-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
020d194
commit 3fe212e
Showing
8 changed files
with
190 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
clients/Qwack.Excel.Next/Curves/InflationCurveFunctions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using ExcelDna.Integration; | ||
using Qwack.Core.Curves; | ||
using Qwack.Excel.Services; | ||
using Qwack.Excel.Utils; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Qwack.Transport.BasicTypes; | ||
using Qwack.Core.Basic; | ||
using Qwack.Dates; | ||
using Qwack.Core.Models; | ||
using Qwack.Models.Calibrators; | ||
using Qwack.Core.Instruments.Funding; | ||
using Qwack.Models; | ||
|
||
namespace Qwack.Excel.Curves | ||
{ | ||
|
||
public class InflationCurveFunctions | ||
{ | ||
private static readonly ILogger _logger = ContainerStores.GlobalContainer.GetService<ILoggerFactory>()?.CreateLogger<InflationCurveFunctions>(); | ||
|
||
[ExcelFunction(Description = "Creates a CPI curve from CPI forecasts", Category = CategoryNames.Curves, Name = CategoryNames.Curves + "_" + nameof(CreateCPICurveFromForecasts), IsThreadSafe = false)] | ||
public static object CreateCPICurveFromForecasts( | ||
[ExcelArgument(Description = "Object name")] string ObjectName, | ||
[ExcelArgument(Description = "Curve name")] object CurveName, | ||
[ExcelArgument(Description = "Build date")] DateTime BuildDate, | ||
[ExcelArgument(Description = "Array of pillar dates")] double[] Pillars, | ||
[ExcelArgument(Description = "Array of CPI forecasts")] double[] CPIForecasts, | ||
[ExcelArgument(Description = "Type of interpolation")] object InterpolationType, | ||
[ExcelArgument(Description = "Inflation Index")] string InfIndex, | ||
[ExcelArgument(Description = "Fixing Dictionary")] string FixingDict, | ||
[ExcelArgument(Description = "Collateral Spec - default LIBOR.3M")] object CollateralSpec) | ||
{ | ||
return ExcelHelper.Execute(_logger, () => | ||
{ | ||
var curveName = CurveName.OptionalExcel(ObjectName); | ||
var curveTypeStr = InterpolationType.OptionalExcel("Linear"); | ||
var colSpecStr = CollateralSpec.OptionalExcel("LIBOR.3M"); | ||
if (!Enum.TryParse(curveTypeStr, out Interpolator1DType iType)) | ||
{ | ||
return $"Could not parse interpolator type - {curveTypeStr}"; | ||
} | ||
if (!ContainerStores.GetObjectCache<InflationIndex>().TryGetObject(InfIndex, out var rIndex)) | ||
{ | ||
_logger?.LogInformation("Rate index {index} not found in cache", InfIndex); | ||
return $"Rate index {InfIndex} not found in cache"; | ||
} | ||
var fixings = new Dictionary<DateTime, double>(); | ||
if(ContainerStores.GetObjectCache<IFixingDictionary>().TryGetObject(FixingDict, out var fixDict)) | ||
{ | ||
foreach(var kv in fixDict.Value) | ||
fixings.Add(kv.Key, kv.Value); | ||
} | ||
var pDates = Pillars.ToDateTimeArray(); | ||
var cObj = new CPICurve(BuildDate, pDates, CPIForecasts, rIndex.Value, fixings) | ||
{ | ||
Name = curveName, | ||
}; | ||
var cache = ContainerStores.GetObjectCache<IIrCurve>(); | ||
cache.PutObject(ObjectName, new SessionItem<IIrCurve> { Name = ObjectName, Value = cObj }); | ||
return ObjectName + '¬' + cache.GetObject(ObjectName).Version; | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.