public static object ComputeCVA( [ExcelArgument(Description = "Hazzard curve")] string HazzardCurveName, [ExcelArgument(Description = "Origin date")] DateTime OriginDate, [ExcelArgument(Description = "Discount curve")] string DiscountCurve, [ExcelArgument(Description = "EPE profile, cube or array")] object EPEProfile, [ExcelArgument(Description = "Loss-given-default, e.g. 0.4")] double LGD) { return(ExcelHelper.Execute(_logger, () => { var hz = ContainerStores.GetObjectCache <HazzardCurve>().GetObjectOrThrow(HazzardCurveName, $"Hazzard curve {HazzardCurveName} not found"); var disc = ContainerStores.GetObjectCache <IIrCurve>().GetObjectOrThrow(DiscountCurve, $"Discount curve {DiscountCurve} not found"); if (EPEProfile is object[,] arr) { if (arr.GetLength(1) != 2) { throw new Exception("Expected Nx2 array for EPE"); } var epeDates = new DateTime[arr.GetLength(0)]; var epeValues = new double[arr.GetLength(0)]; for (var i = 0; i < arr.GetLength(0); i++) { epeDates[i] = (DateTime)arr[i, 0]; epeValues[i] = (double)arr[i, 1]; } return XVACalculator.CVA(OriginDate, epeDates, epeValues, hz.Value, disc.Value, LGD); } else if (EPEProfile is string epeCubeName) { var cube = ContainerStores.GetObjectCache <ICube>().GetObjectOrThrow(epeCubeName, $"Cube {epeCubeName} not found"); return XVACalculator.CVA(OriginDate, cube.Value, hz.Value, disc.Value, LGD); } throw new Exception("EPE profile must be cube reference or Nx2 array"); })); }
public double CVA() => XVACalculator.CVA(Model.BuildDate, EPE(), Settings.CreditSettings.CreditCurve, Settings.CreditSettings.FundingCurve, Settings.CreditSettings.LGD);