Cox Ingersoll Ross

Overview


Fixed Income analysis is a complex subject. The davinci library contains a number of differenct tool for analyzing cash flows from fixed income instruments. This corner goes through some simple examples.

{% dr = (\eta - \gamma r) dt + \sqrt{\alpha r}dW %}

Zero Coupon Bond Price


The CIR model admits a affine term structure solution to the price of a zero coupon bond.
{% p(t, T) = exp[A(t, T) - B(t, T)r] %}
where
{% \frac{\alpha}{2} A = a \psi_2 log(a-B) + \psi_2 b log((B+b)/b) - a\psi_2 log a %}
{% B(t, T) = \frac{2(e^{\psi_1 (T-t)} -1)}{(\gamma + \psi_1)(e ^{\psi_1(T-t)} -1) + 2\psi_1} %}
{% \psi_1 = \sqrt{\gamma^2 + 2 \alpha} %}
{% \psi_2 = \frac{\eta}{a+b} %}
{% b = \frac{\gamma + \sqrt{\gamma^2 + 2\alpha}}{\alpha} %}
{% a = \frac{-\gamma + \sqrt{\gamma^2 + 2\alpha}}{\alpha} %}
{% see wilmott 16.6.2 %}

Monte Carlo Simulations


The mathematical form of the CIR model given above prevents interest rates from going zero. However, when simulating the model, a finite time increment must be chosen, and the probability of the model going negative is not zero.

copy


let ito = await import('/lib/statistics/simulations/v1.0.0/ito.js');
// SITE
// /home/apis/api.html?url=/lib/statistics/simulations/v1.0.0/site/ito.js

let eta = 0.1;
let gamma = 0.1;
let beta = 0.1;
let alpha = 0.1

let dt = function(points){
    return eta - gamma*points[points.length-1]
}

let vol = function(points){
    return Math.sqrt(points[points.length-1]*alpha);
}

let data = [];
for(let i=0;i<5;i++){ let sims=ito.generate(300, dt, vol, 0.1)
					  sims=sims.map(p =>{
        return {
            value:p,
            sim:(i+1).toString()
        }
    });
    data = [...data,...sims]
}

$val.set('data',data);