//---------------------------------------------------------------------------------------- public static double[] GetRepoRates(BondAnalytics.Country eCountry, List<DateTime> dates ) //---------------------------------------------------------------------------------------- { List<double> reporates = new List<double>(); foreach (var dte in dates) { double repo = double.NaN; switch (eCountry) { case BondAnalytics.Country.US: GenericPrice prc = GetHistoryPrice(Constants.NomGcMidRate, dte, "NOM", "NOM"); repo = prc == null ? double.NaN : prc.GcMidRate / 100.0; break; case BondAnalytics.Country.DE: var o = GetCbnTimeSeriesDataCell("GC_GERMANY_SUB_10YR", "eod-icaprepo", dte, "wtdRate", new object[] { "term~S-N" }); if (o is double) { repo = (double) o / 100.0; } else repo = double.NaN; break; /* case BondAnalytics.Country.UK: break;*/ default: throw new ArgumentException("Invalid input country " + eCountry.ToString()); } reporates.Add(repo); } return reporates.ToArray(); }
public static double Calculate(CalcMeasure Measure, DateTime settle, double price, Bond bondStatic, BondAnalytics.Country eCountry, DateTime asOfDate, List<DateTime> hols) { // byran lim config coded in symmetry.net. we use this until we have a centralised place for the curve static // different country has different setting of using forcast and discount curve bool bForecastCurve; switch (eCountry) { case BondAnalytics.Country.DE: bForecastCurve = false; break; default: bForecastCurve = true; break; } var fcstCfg = new SpreadTimeSeriesConfigs(eCountry.ToString(), bForecastCurve); int trial = 0; DiscountCurve forCurve = null; DiscountCurve disCurve = null; if (discountCurveCache.ContainsKey(fcstCfg.SymForecastCurveName)) { var forTup = discountCurveCache[fcstCfg.SymForecastCurveName].FirstOrDefault(i => i.Item1 == asOfDate); if (forTup != null) forCurve = forTup.Item2; } if (discountCurveCache.ContainsKey(fcstCfg.SymDiscountCurveName)) { var disTup = discountCurveCache[fcstCfg.SymDiscountCurveName].FirstOrDefault(i => i.Item1 == asOfDate); if (disTup != null) disCurve = disTup.Item2; } if (forCurve == null || disCurve == null) { while (trial < 3) { try { forCurve = SymmetryDataModel.GetDiscountCurve(fcstCfg.SymForecastCurveName, asOfDate); disCurve = SymmetryDataModel.GetDiscountCurve(fcstCfg.SymDiscountCurveName, asOfDate); trial = 5; break; } catch (Exception) { trial++; continue; } } if (forCurve != null && disCurve != null) { var forTup = new Tuple<DateTime, DiscountCurve>(asOfDate, forCurve); var disTup = new Tuple<DateTime, DiscountCurve>(asOfDate, disCurve); if (discountCurveCache.ContainsKey(fcstCfg.SymForecastCurveName)) discountCurveCache[fcstCfg.SymForecastCurveName].Add(forTup); else discountCurveCache[fcstCfg.SymForecastCurveName] = new[] {forTup}.ToList(); if (discountCurveCache.ContainsKey(fcstCfg.SymDiscountCurveName)) discountCurveCache[fcstCfg.SymDiscountCurveName].Add(disTup); else discountCurveCache[fcstCfg.SymDiscountCurveName] = new[] { disTup }.ToList(); } } if (forCurve == null || disCurve == null) return double.NaN; DateTime effectiveDate = bondStatic.EffectiveDate ?? DateTime.MinValue; DateTime maturity = bondStatic.Maturity ?? DateTime.MinValue; DateTime firstCpnDate = bondStatic.FirstCouponDate ?? DateTime.MinValue; double coupon = bondStatic.Coupon; long bondCpnFreq = fcstCfg.bndCouponFreq; bool bOIS = !fcstCfg.bForecastCurve; BondAnalytics.DayCountType dct = fcstCfg.dct; long swapFixedFreq = fcstCfg.swpfixfreq; long swapFloatFreq = fcstCfg.swpfloatfreq; return CalcMeasure(Measure, price, eCountry, settle, disCurve, forCurve, effectiveDate, maturity, firstCpnDate, coupon, bondCpnFreq, bOIS, dct, swapFixedFreq, swapFloatFreq, hols); }