// a1/a2 form a spread:

claim a1 {
    type european_call,
    maturity 60,
    strike 100,
    payoff linear
}

claim a2 {
    type european_call,
    maturity 60,
    strike 110,
    payoff linear
}

// A knock-out put:

claim a3 {
    type european_put,
    maturity 60,
    strike 95,
    down_and_out 85,
    payoff linear
}

// An American put:

claim a4 {
    type american_put,
    maturity 50,
    strike 100,
    payoff linear
}

portfolio p1 {
    a1 long,
    a2 short,
    a3 long,
    a4 short
}

// (Domestic) Interest rate:

drift r {
    implied 60 0.055
}

// Dividend/foreign interest rate:

drift q {
    implied 60 0.025
}

// Minimum vol is 10%.
// Prior vol is 15%.
// Maximum vol is 20%.

vol v {
    implied 60 0.1 .. 0.15 .. 0.2
}

factor s {
}

model m1 {
    type bs,
    days_per_year 365,
    discount r,
    carry q,
    vol v,
    factor s 100
}

// Explicit finite differencing, trimming
// after 3.5 standard deviations, 10 time
// steps per day:

lattice l1 {
    shape tree 3.5,
    method explicit,
    model m1,
    portfolio p1,
    time_step 0.1
}

scenario w1 {
    type worst_case,
    seller
}

evaluate {
    portfolio p1,
    model m1,
    lattice l1,
    scenario w1,
    accuracy exact
}

// Result: 1.63631

// Now evaluate the same portfolio under a
// shock scenario - prior vol is 15%.

scenario w2 {
    type shock,
    seller,
    duration 3,
    periodicity 1,
    repetitions 1
}

evaluate {
    portfolio p1,
    model m1,
    lattice l1,
    scenario w2,
    accuracy exact
}

// Result: 1.03289
