Serving the Quantitative Finance Community

 
User avatar
Cuchulainn
Posts: 22924
Joined: July 16th, 2004, 7:38 am

Re: Popular Yield Curve Models

December 5th, 2023, 7:40 pm

My co-author Andrea Germani discusses scenarios for collections of bonds in  "C# for Financial Markets". He compares them to a flat scenario and price/delta for different rate values. Maybe?
 
User avatar
NightCoder
Topic Author
Posts: 11
Joined: June 4th, 2021, 7:08 am

Re: Popular Yield Curve Models

December 5th, 2023, 8:40 pm

Yes, Cuchulainn. I mean exactly that part!
 
User avatar
Cuchulainn
Posts: 22924
Joined: July 16th, 2004, 7:38 am

Re: Popular Yield Curve Models

December 6th, 2023, 12:19 am

Here is a sample from Andrea

// Using .NET LINQ
public static void Scenario()
{
double rate = 0.05; //my starting rate
// 1)Defining scenarios
var Scenario = new[]
{
new {Name = "Flat", RateValue = rate},
new {Name = "+1bp", RateValue = rate+0.0001},
new {Name = "+100bp", RateValue = rate+0.01},
new {Name = "-1bp", RateValue = rate-0.0001},
new {Name = "-100bp", RateValue = rate-0.01},
};
Scenario.Print("Scenarios");
// 2) My bond defined as collection of pair (time, cash flows)
var Bond = new[]
{
new { Time = 1.0 , CashFlow = 2.0 },
new { Time = 2.0 , CashFlow = 2.0 },
new { Time = 3.0 , CashFlow = 102.0 }
};
// 3)Define my discount function: standard continuous compounding
Func<double, double, double> CalcDF = (t, r) => Math.Exp(-r * t);
// Define my bond pricer calculator: it calculates the sum of present values
// of cash flows according to "CalcDf"
Func<double, double> CalcBondPx = r => (from p in Bond
select p.CashFlow * CalcDF(p.Time, r)).Sum();
// 4) Calculate bond prices in different scenarios
Last edited by Cuchulainn on December 6th, 2023, 12:22 am, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 22924
Joined: July 16th, 2004, 7:38 am

Re: Popular Yield Curve Models

December 6th, 2023, 12:21 am

var BondValues = from s in Scenario
select new { Name = s.Name, BondPx = CalcBondPx(s.RateValue) };
BondValues.Print("\nBond Prices in different scenarios");
// 5) Calculate the differences in bond prices in different scenarios, with
// respect to "flat" scenario
var PricesDelta = from s in BondValues
select new
{
Name = s.Name,
Delta = s.BondPx - BondValues.Single
(p => p.Name == "Flat").BondPx
};
PricesDelta.Print("\nDeltas in bond prices with respect 'Flat'
scenario");
The output from this code is:
Scenarios
{ Name = Flat, RateValue = 0.05 },
{ Name = +1bp, RateValue = 0.0501 },
{ Name = +100bp, RateValue = 0.06 },
{ Name = -1bp, RateValue = 0.0499 },
{ Name = -100bp, RateValue = 0.04 },
Bond Prices in different scenarios
{ Name = Flat, BondPx = 91.5043472804292 },
{ Name = +1bp, BondPx = 91.4774614314561 },
{ Name = +100bp, BondPx = 88.8549315045526 },
{ Name = -1bp, BondPx = 91.5312411221132 },
{ Name = -100bp, BondPx = 94.233696116228 },
Deltas in bond prices with respect 'Flat' scenario
{ Name = Flat, Delta = 0 },
{ Name = +1bp, Delta = -0.0268858489730945 },
{ Name = +100bp, Delta = -2.64941577587669 },
{ Name = -1bp, Delta = 0.0268938416839575 },
{ Name = -100bp, Delta = 2.72934883579873 },
It is possible to generalise this design to cases in
 
User avatar
NightCoder
Topic Author
Posts: 11
Joined: June 4th, 2021, 7:08 am

Re: Popular Yield Curve Models

December 6th, 2023, 8:17 am

Okay, thanks.
 
User avatar
Cuchulainn
Posts: 22924
Joined: July 16th, 2004, 7:38 am

Re: Popular Yield Curve Models

December 6th, 2023, 4:35 pm

Maybe have a chat with a trader who does this stuff on a daily basis, if they have time..