Skip to content

Commit

Permalink
Bond utils
Browse files Browse the repository at this point in the history
  • Loading branch information
gavbrennan committed Oct 10, 2022
1 parent bfc1118 commit 634bead
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/Qwack.Math/BondUtils.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Qwack.Math
{
Expand All @@ -19,11 +18,23 @@ public static double YieldToWorst(double couponRate, double faceValue, double cl
public static double YieldToWorst(double couponRate, double[] redemptionPrices, double cleanPrice, double[] tRedeem)
=> tRedeem.Select((t, ix) => YieldToMaturity(couponRate, redemptionPrices[ix], cleanPrice, t)).Min();

public static (double ytw, double t) YieldToWorstWithWorkout(double couponRate, double[] redemptionPrices, double cleanPrice, double[] tRedeem)
=> tRedeem.Select((t, ix) => (YieldToMaturity(couponRate, redemptionPrices[ix], cleanPrice, t), t))
.OrderBy(x => x.Item1)
.Take(1)
.Select(x => (x.Item1, x.t))
.FirstOrDefault();

// public static double YtmInBase(double couponRate, double faceValue, double periodsPerYear, double tMaturity, double tNext, Func<double,double> fxRates, double dirtyPriceInLocal)
public static double YieldToWorstInBase(double couponRate, double[] redemptionPrices, double periodsPerYear, double tNext, double cleanPrice, double[] tRedeem, Func<double, double> fxRates)
=> tRedeem.Select((t, ix) => YtmInBase(couponRate, redemptionPrices[ix], periodsPerYear, t, tNext, fxRates, cleanPrice)).Min();

public static (double ytw, double t) YieldToWorstInBaseWithWorkout(double couponRate, double[] redemptionPrices, double periodsPerYear, double tNext, double cleanPrice, double[] tRedeem, Func<double, double> fxRates)
=> tRedeem.Select((t, ix) => (YtmInBase(couponRate, redemptionPrices[ix], periodsPerYear, t, tNext, fxRates, cleanPrice), t))
.OrderBy(x => x.Item1)
.Take(1)
.Select(x => (x.Item1, x.t))
.FirstOrDefault();

public static double PriceFromYtm(double couponRate, double faceValue, double ytm, double t)
=> (couponRate * 2 + faceValue * (2 / t - ytm)) / (ytm + 2 / t);

Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.0
0.7.1

0 comments on commit 634bead

Please sign in to comment.