public void TestTimeMatrixDouble() { //Test1 var bag1 = new object[, ] { { null, null, null, null }, { "", "myparam ", "hello", "toto" }, { null, "1y", "1.0", 5.0 }, { null, "02/22/1978", "2.0", "4.0" }, { null, "10y", "3.0", 1.0 } }; TimeMatrixDatas timeDatas = bag1.ProcessTimeMatrixDatas("MyParam"); var helloDatas = timeDatas.GetColFromLabel("hello"); var totoDatas = timeDatas.GetColFromLabel("toto"); UnitTestUtils.EqualDoubleArray(helloDatas, new[] { 1.0, 2.0, 3.0 }, DoubleUtils.MachineEpsilon); UnitTestUtils.EqualDoubleArray(totoDatas, new[] { 5.0, 4.0, 1.0 }, DoubleUtils.MachineEpsilon); }
private static AssetMarket[] ProcessAssetMkt(object[,] bag, DateTime refDate, DiscountCurve[] discountCurves) { var eqtyTime = TimeMeasure.Act365(refDate); var assetRawDatas = bag.ProcessLabelledMatrix("Asset", o => o.ToString(), o => o.ToString(), o => o); TimeMatrixDatas repoRawDatas = bag.ProcessTimeMatrixDatas("Repo"); var repoPillars = repoRawDatas.RowLabels .Select(dOrDur => dOrDur.ToDate(refDate)).ToArray(); var assetMkts = new List <AssetMarket>(); for (int i = 0; i < assetRawDatas.RowLabels.Length; i++) { var assetName = assetRawDatas.RowLabels[i]; var rawCurrency = assetRawDatas.GetColFromLabel("Currency")[i].ToString(); object rawSpot = assetRawDatas.GetColFromLabel("Spot")[i]; var currency = Currency.Parse(rawCurrency); var assetId = new AssetId(assetName, currency); double spot; if (!NumberConverter.TryConvertDouble(rawSpot, out spot)) { throw new ArgumentException(String.Format("AssetMarketFactory, invalid {0} spot : {1}", assetName, rawSpot)); } double[] repoRates = repoRawDatas.GetColFromLabel(assetName); var repoZcs = repoRates.Select((r, idx) => Math.Exp(-eqtyTime[repoPillars[idx]] * r)).ToArray(); var repoCurve = DiscountCurve.LinearRateInterpol(FinancingId.AssetCollat(assetId), repoPillars, repoZcs, eqtyTime); var divQuotes = ProcessDiv(bag, refDate, assetName); var volMatrix = AssetVolMatrix(bag, eqtyTime, assetName); var riskFreeDiscount = discountCurves.Single(curve => curve.Financing.Equals(FinancingId.RiskFree(currency))); var mkt = new AssetMarket(assetId, refDate, eqtyTime, spot, riskFreeDiscount, repoCurve, divQuotes, volMatrix); assetMkts.Add(mkt); } return(assetMkts.ToArray()); }
private static DiscountCurve[] RateCurveFromRawDatas(TimeMatrixDatas curveRawDatas, DateTime refDate) { var rateTimeInterpol = RateTimeMeasure(refDate); DateTime[] datePillars = curveRawDatas.RowLabels .Select(dOrDur => dOrDur.ToDate(refDate)).ToArray(); var curves = new List <DiscountCurve>(); foreach (var curveLabel in curveRawDatas.ColLabels) { FinancingId financingId; if (!FinancingId.TryParse(curveLabel, out financingId)) { throw new ArgumentException(String.Format("RateMarketFactory, invalid Discount Curve Id : {0}", curveLabel)); } double[] zcs = curveRawDatas.GetColFromLabel(curveLabel); var discountCurve = DiscountCurve.LinearRateInterpol(financingId, datePillars, zcs, rateTimeInterpol); curves.Add(discountCurve); } return(curves.ToArray()); }