From 5d43e04e889fde6fb964825f2080e19f45b7a17e Mon Sep 17 00:00:00 2001 From: Gavin Brennan Date: Thu, 13 Oct 2022 21:20:48 +0200 Subject: [PATCH] .net 6.0 package support --- src/Qwack.Core/Qwack.Core.csproj | 2 +- src/Qwack.Dates/Qwack.Dates.csproj | 2 +- src/Qwack.Futures/Qwack.Futures.csproj | 2 +- .../Qwack.Math.Interpolation.csproj | 2 +- src/Qwack.Math/BondUtils.cs | 20 +++++++++++++++++++ src/Qwack.Math/Qwack.Math.csproj | 2 +- src/Qwack.Models/Qwack.Models.csproj | 2 +- src/Qwack.Options/Qwack.Options.csproj | 2 +- src/Qwack.Paths/Qwack.Paths.csproj | 2 +- src/Qwack.Providers/Qwack.Providers.csproj | 2 +- src/Qwack.Random/Qwack.Random.csproj | 2 +- .../Qwack.Serialization.csproj | 2 +- src/Qwack.Storage/Qwack.Storage.csproj | 2 +- src/Qwack.Transport/Qwack.Transport.csproj | 2 +- src/Qwack.Utils/Qwack.Utils.csproj | 2 +- version.txt | 2 +- 16 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/Qwack.Core/Qwack.Core.csproj b/src/Qwack.Core/Qwack.Core.csproj index 51193f55..8670efe9 100644 --- a/src/Qwack.Core/Qwack.Core.csproj +++ b/src/Qwack.Core/Qwack.Core.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0;net6.0 Qwack.Core Qwack.Core diff --git a/src/Qwack.Dates/Qwack.Dates.csproj b/src/Qwack.Dates/Qwack.Dates.csproj index 74ad989a..8f40dbfe 100644 --- a/src/Qwack.Dates/Qwack.Dates.csproj +++ b/src/Qwack.Dates/Qwack.Dates.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0;net6.0 Qwack.Dates Qwack.Dates diff --git a/src/Qwack.Futures/Qwack.Futures.csproj b/src/Qwack.Futures/Qwack.Futures.csproj index 5bc36f79..fbbbfd9a 100644 --- a/src/Qwack.Futures/Qwack.Futures.csproj +++ b/src/Qwack.Futures/Qwack.Futures.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0;net6.0 diff --git a/src/Qwack.Math.Interpolation/Qwack.Math.Interpolation.csproj b/src/Qwack.Math.Interpolation/Qwack.Math.Interpolation.csproj index 06bd3fad..a0490751 100644 --- a/src/Qwack.Math.Interpolation/Qwack.Math.Interpolation.csproj +++ b/src/Qwack.Math.Interpolation/Qwack.Math.Interpolation.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0;net6.0 Qwack.Math.Interpolation Qwack.Math.Interpolation diff --git a/src/Qwack.Math/BondUtils.cs b/src/Qwack.Math/BondUtils.cs index 063728a6..e942b302 100644 --- a/src/Qwack.Math/BondUtils.cs +++ b/src/Qwack.Math/BondUtils.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Qwack.Math.Solvers; namespace Qwack.Math { @@ -9,6 +10,25 @@ public static class BondUtils public static double YieldToMaturity(double couponRate, double faceValue, double cleanPrice, double t) => (couponRate + (faceValue - cleanPrice) / t) / ((faceValue + cleanPrice) / 2.0); + public static double YieldToMaturity(double couponRate, double faceValue, double periodsPerYear, double tMaturity, double tNext, double cleanPrice) + { + var source = BondFlows(couponRate / faceValue, faceValue, periodsPerYear, tMaturity, tNext); + var tPerP = 1 / periodsPerYear; + return Brent.BrentsMethodSolve(delegate (double ytm) + { + var num = 0.0; + foreach (var item in source) + { + var y = (item.Key) / tPerP; + num += item.Value / System.Math.Pow(1.0 + ytm / periodsPerYear, y); + } + return num - cleanPrice; + }, -0.1, 1.0, 1E-06); + } + + public static double YieldToWorst(double couponRate, double[] redemptionPrices, double cleanPrice, double[] tRedeem, double periodsPerYear, double tNext) + => tRedeem.Select((t, ix) => YieldToMaturity(couponRate, redemptionPrices[ix], periodsPerYear, t, tNext, cleanPrice)).Min(); + public static double YieldToWorst(double couponRate, double faceValue, double cleanPrice, double tMaturity, double tCall, double callPrice) => System.Math.Min( YieldToMaturity(couponRate, faceValue, cleanPrice, tMaturity), diff --git a/src/Qwack.Math/Qwack.Math.csproj b/src/Qwack.Math/Qwack.Math.csproj index 099a0ce8..646d987b 100644 --- a/src/Qwack.Math/Qwack.Math.csproj +++ b/src/Qwack.Math/Qwack.Math.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0;net6.0 true Qwack.Math Qwack.Math diff --git a/src/Qwack.Models/Qwack.Models.csproj b/src/Qwack.Models/Qwack.Models.csproj index 81e0198a..14ccbb3e 100644 --- a/src/Qwack.Models/Qwack.Models.csproj +++ b/src/Qwack.Models/Qwack.Models.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0;net6.0 Qwack.Models Qwack.Models diff --git a/src/Qwack.Options/Qwack.Options.csproj b/src/Qwack.Options/Qwack.Options.csproj index 66d43b23..868e9119 100644 --- a/src/Qwack.Options/Qwack.Options.csproj +++ b/src/Qwack.Options/Qwack.Options.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0;net6.0 true Qwack.Options Qwack.Options diff --git a/src/Qwack.Paths/Qwack.Paths.csproj b/src/Qwack.Paths/Qwack.Paths.csproj index d2366d5d..c5a8fd49 100644 --- a/src/Qwack.Paths/Qwack.Paths.csproj +++ b/src/Qwack.Paths/Qwack.Paths.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0;net6.0 true Qwack.Paths Qwack.Paths diff --git a/src/Qwack.Providers/Qwack.Providers.csproj b/src/Qwack.Providers/Qwack.Providers.csproj index 19af8b58..d4e52a80 100644 --- a/src/Qwack.Providers/Qwack.Providers.csproj +++ b/src/Qwack.Providers/Qwack.Providers.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0;net6.0 Qwack.Providers Qwack.Providers diff --git a/src/Qwack.Random/Qwack.Random.csproj b/src/Qwack.Random/Qwack.Random.csproj index 7006f021..37bd0ecb 100644 --- a/src/Qwack.Random/Qwack.Random.csproj +++ b/src/Qwack.Random/Qwack.Random.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0;net6.0 true Qwack.Random Qwack.Random diff --git a/src/Qwack.Serialization/Qwack.Serialization.csproj b/src/Qwack.Serialization/Qwack.Serialization.csproj index c132e27d..91b5975c 100644 --- a/src/Qwack.Serialization/Qwack.Serialization.csproj +++ b/src/Qwack.Serialization/Qwack.Serialization.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0;net6.0 diff --git a/src/Qwack.Storage/Qwack.Storage.csproj b/src/Qwack.Storage/Qwack.Storage.csproj index 14aad234..8f78c32b 100644 --- a/src/Qwack.Storage/Qwack.Storage.csproj +++ b/src/Qwack.Storage/Qwack.Storage.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0;net6.0 diff --git a/src/Qwack.Transport/Qwack.Transport.csproj b/src/Qwack.Transport/Qwack.Transport.csproj index 62cc4e01..3d7cf642 100644 --- a/src/Qwack.Transport/Qwack.Transport.csproj +++ b/src/Qwack.Transport/Qwack.Transport.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0;net6.0 diff --git a/src/Qwack.Utils/Qwack.Utils.csproj b/src/Qwack.Utils/Qwack.Utils.csproj index 958bf5ad..8b495d60 100644 --- a/src/Qwack.Utils/Qwack.Utils.csproj +++ b/src/Qwack.Utils/Qwack.Utils.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0;net6.0 true Qwack.Utils Qwack.Utils diff --git a/version.txt b/version.txt index d5cc44d1..b09a54cb 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.7.2 \ No newline at end of file +0.7.3 \ No newline at end of file