system {

    base "15 Jan 2000"

}



// Four US Treasury bonds. The

// coupons are absolute amounts.



claim a1 {

    type ust_bond,

    maturity "15 Jan 2005",

    settlement identity,

    principal 100,

    coupon 4.5,

    price 98

}



claim a2 {

    type ust_bond,

    maturity "15 Jan 2007",

    settlement identity,

    principal 100,

    coupon 4.5,

    price 100

}



claim a3 {

    type ust_bond,

    maturity "15 Jan 2010",

    settlement identity,

    principal 100,

    coupon 5,

    price 100

}



claim a4 {

    type ust_bond,

    maturity "15 Jan 2030",

    settlement identity,

    principal 100,

    coupon 5.5,

    price 105

}



// Although we need to define a portfolio,

// the quantities won't matter for bootstrapping

// or calibration.



portfolio p1 {

    a1 long,

    a2 long,

    a3 long,

    a4 long

}



// Compute a piecewise constant forward

// rate curve via simple bootstrapping.



bootstrap b1 {

    portfolio p1,

    save "bootstrap02.txt"

}



factor r {

}



// Use the bootstrapped step function as

// mean for the Vasicek model. The short

// rate at the base date is 5% ("initial").



model m1 {

    type vasicek,

    days_per_year 365,

    factor r sigma 0.01 theta 1.0 alpha 1.0,

    initial 0.05,

    mean b1

}



// The base date is taken from the

// system object. Time steps are

// spaced monthly.



path_space t1 {

    day_count dc_act_365,

    scale year 12,

    model m1,

    portfolio p1,

    size 50000,

    save "pathspace02.txt"

}



optimizer o1 {

    type entropy,

    low -100,

    high 100

}



// Save the resulting forward rates and yields

// so that other programs can read them for

// simple bond math.



curve c1 {

    type forward,

    path_space t1,

    save "forward02.txt"

}



curve c2 {

    type yield,

    path_space t1,

    save "yield02.txt"

}



// Put both curves and the bootstrapping

// result into an image.



image g1 {

    title "Calibration result",

    portfolio p1,

    size 1024 512,

    curve c1 red lines,

    curve c2 green lines,

    bootstrap b1 blue steps,

    save "calibration02.png"

}



// Calibrate the pathspace t1 and save

// the result in "pathspace02.txt".



evaluate {

    portfolio p1,

    model m1,

    path_space t1,

    optimizer o1,

    image g1

}

