Implementing Static Spread

Overview


Also known as the zero volatility spread, is the spread that when added over the entire rate curve (typically the risk free or Treasury curve), would yield the bond price when its cash flows are discounted by the new curve.

Discounting with a Curve


The following code demonstrates a simple example of discounting a set of cash flows with a given rate curve. The rate curve given returns the same rate for each time period.


let cashflows = [{time:1, value:10},{time:2, value:10},{time:3, value:110}];

let price = 95;
let ratecurve = function(date){
  return 0.1
}

let discountValue = function(){
  let value = 0;
  cashflows.forEach(p=>{
    let rate = ratecurve(p.time);
    value += Math.exp(-1*rate*p.time) * p.value;
  });
  return value;
}
					


Adding the Spread


Next, create a function that will take a spread as input, and then calculate the value of the cash flows when discounted with the given rate (from teh rate curve) plus the inputted spread.

The diff function takes a spread and returns the value of the discounted cash flows (at the rate plus the spread) and the price of the instrument.


let spreadValue = function(spread){
  let value = 0;
  cashflows.forEach(p=>{
    let rate = ratecurve(p.time) + spread;
    value += Math.exp(-1*rate*p.time) * p.value;
  });
  return value;
}

let diff = function(spread){
  return spreadValue(spread) - price;
}
					


Lastly, seek to find a root of the diff function, that is, find a value of the spread that makes the value of the diff function equal to zero. (see root finding)


let cashflows = [{time:1, value:10},{time:2, value:10},{time:3, value:110}];
let sp = await import('/lib/finance/fixed-income/spread/v1.0.0/spread.mjs');
let price = 95;
let ratecurve = function(date){
  return 0.1
}

let test = sp.staticSpread(price,cashflows);
					
Try it!


Contents