public OISSpreadRepoGenerator(double onRate, string market, DateTime settle, DiscountCurve oisCurve) : base(onRate, market, settle) { this.oisCurve = oisCurve; country = (BondAnalytics.Country)Enum.Parse(typeof(BondAnalytics.Country), market); var startdate = CarbonModel.RollDate(settle, 1, DateUnit.Bd, BusinessDayConvention.Following, Calendar.Calendar.OTHolidayCode(country)); DateTime[] discDfDates = oisCurve.AsTuples().Select(x => x.Item1).ToArray(); double[] discDfs = oisCurve.AsTuples().Select(x => x.Item2).ToArray(); repoShift = onRate - BondAnalytics.CalcMMS(startdate, startdate, BondAnalytics.DayCountType.I30360, 12, 12, discDfDates, discDfs, discDfDates, discDfs, null, null, null, null, null, null, DateTime.MinValue, 0) * 10000; }
public static double CalcMeasure(CalcMeasure Measure, double price, BondAnalytics.Country eCountry, //DateTime asof, DateTime settle, DiscountCurve discCurve, DiscountCurve fcstCurve, DateTime effectiveDate, DateTime maturity, DateTime firstCpnDate, double coupon, long bondCpnFreq, bool bOIS, BondAnalytics.DayCountType dct, long swapFixedFreq, long swapFloatFreq, List<DateTime> hols) //---------------------------------------------------------------------------------------- { double output = double.NaN; switch (Measure) { case Analytics.CalcMeasure.Price: { output = price; break; } case Analytics.CalcMeasure.Yield: { output = 10000.0*BondAnalytics.SolveYield(eCountry, settle, price, effectiveDate, firstCpnDate, maturity, coupon, bondCpnFreq)[0]; break; } case Analytics.CalcMeasure.TrueSpread: { DateTime[] dfDates = (bOIS ? discCurve.AsTuples().Select(x => x.Item1).ToArray() : fcstCurve.AsTuples().Select(x => x.Item1).ToArray()); double[] dfs = (bOIS ? discCurve.AsTuples().Select(x => x.Item2).ToArray() : fcstCurve.AsTuples().Select(x => x.Item2).ToArray()); // Check. Sometimes (holidays) the first date on the curve can be repeated, which will cause an exception in the pricer. if (dfDates[0] == dfDates[1]) { dfDates = dfDates.GetSubArray(1, dfDates.GetLength(0)).ToArray(); dfs = dfs.GetSubArray(1, dfs.GetLength(0)).ToArray(); } output = -10000.0*BondAnalytics.SolveZSpread(eCountry, settle, price, effectiveDate, firstCpnDate, maturity, coupon, bondCpnFreq, dfDates, dfs, hols); break; } case Analytics.CalcMeasure.MMS: { DateTime[] discDfDates = discCurve.AsTuples().Select(x => x.Item1).ToArray(); DateTime[] fcstDfDates = (bOIS ? discCurve.AsTuples().Select(x => x.Item1).ToArray() : fcstCurve.AsTuples().Select(x => x.Item1).ToArray()); double[] discDfs = discCurve.AsTuples().Select(x => x.Item2).ToArray(); double[] fcstDfs = (bOIS ? discCurve.AsTuples().Select(x => x.Item2).ToArray() : fcstCurve.AsTuples().Select(x => x.Item2).ToArray()); double mms = BondAnalytics.CalcMMS(settle, maturity, dct, swapFixedFreq, swapFloatFreq, discDfDates, discDfs, fcstDfDates, fcstDfs, hols, null, null, null, null, null, firstCpnDate, (bOIS ? 5 : 0)); output = 10000.0*mms; break; } case Analytics.CalcMeasure.Spread: { DateTime[] discDfDates = discCurve.AsTuples().Select(x => x.Item1).ToArray(); DateTime[] fcstDfDates = (bOIS ? discCurve.AsTuples().Select(x => x.Item1).ToArray() : fcstCurve.AsTuples().Select(x => x.Item1).ToArray()); double[] discDfs = discCurve.AsTuples().Select(x => x.Item2).ToArray(); double[] fcstDfs = (bOIS ? discCurve.AsTuples().Select(x => x.Item2).ToArray() : fcstCurve.AsTuples().Select(x => x.Item2).ToArray()); double mms = BondAnalytics.CalcMMS(settle, maturity, dct, swapFixedFreq, swapFloatFreq, discDfDates, discDfs, fcstDfDates, fcstDfs, hols, null, null, null, null, null, firstCpnDate, (bOIS ? 5 : 0)); double yield = BondAnalytics.SolveYield(eCountry, settle, price, effectiveDate, firstCpnDate, maturity, coupon, bondCpnFreq)[0]; output = 10000.0*(mms - yield); break; } } return output; }
//---------------------------------------------------------------------------------------- public static double calcMeasure( string Measure, double price, BondAnalytics.Country eCountry, DateTime asof, DateTime settle, DiscountCurve discCurve, DiscountCurve fcstCurve, BondStatic bondStatic, SpreadTimeSeriesConfigs configs, List<DateTime> hols) //---------------------------------------------------------------------------------------- { DateTime effectiveDate = DateTime.FromOADate( bondStatic.EffectiveDate); DateTime maturity = DateTime.FromOADate( bondStatic.Maturity); DateTime firstCpnDate = DateTime.FromOADate(bondStatic.FirstCoupon); double coupon = bondStatic.Coupon; long bondCpnFreq = configs.bndCouponFreq; bool bOIS = !configs.bForecastCurve; BondAnalytics.DayCountType dct = configs.dct; long fixedFreq = configs.swpfixfreq; long floatFreq = configs.swpfloatfreq; double output = double.NaN; switch (Measure) { case "Price": { output= price; break; } case "Yield": { output= 10000.0 * BondAnalytics.SolveYield(eCountry, settle, price, effectiveDate, firstCpnDate, maturity, coupon, bondCpnFreq)[0]; break; } case "TrueSpread": { DateTime[] dfDates = (bOIS ? discCurve.AsTuples().Select(x => x.Item1).ToArray() : fcstCurve.AsTuples().Select(x => x.Item1).ToArray()); double[] dfs = (bOIS ? discCurve.AsTuples().Select(x => x.Item2).ToArray() : fcstCurve.AsTuples().Select(x => x.Item2).ToArray()); // Check. Sometimes (holidays) the first date on the curve can be repeated, which will cause an exception in the pricer. if (dfDates[0] == dfDates[1]) { dfDates = dfDates.GetSubArray(1, dfDates.GetLength(0)).ToArray(); dfs = dfs.GetSubArray(1, dfs.GetLength(0)).ToArray(); } output= -10000.0 * BondAnalytics.SolveZSpread(eCountry, settle, price, effectiveDate, firstCpnDate, maturity, coupon, bondCpnFreq, dfDates, dfs,hols ); break; } case "MMS": { DateTime[] discDfDates = discCurve.AsTuples().Select(x => x.Item1).ToArray(); DateTime[] fcstDfDates = (bOIS ? discCurve.AsTuples().Select(x => x.Item1).ToArray() : fcstCurve.AsTuples().Select(x => x.Item1).ToArray()); double[] discDfs = discCurve.AsTuples().Select(x => x.Item2).ToArray(); double[] fcstDfs =(bOIS ? discCurve.AsTuples().Select(x => x.Item2).ToArray() : fcstCurve.AsTuples().Select(x => x.Item2).ToArray()); double mms = BondAnalytics.CalcMMS(settle, maturity, dct, fixedFreq, floatFreq, discDfDates, discDfs, fcstDfDates, fcstDfs, hols, null, null, null, null, null, firstCpnDate, (bOIS ? 5 : 0)); output= 10000.0 * mms; break; } case "Spread": { DateTime[] discDfDates = discCurve.AsTuples().Select(x => x.Item1).ToArray(); DateTime[] fcstDfDates = (bOIS ? discCurve.AsTuples().Select(x => x.Item1).ToArray() : fcstCurve.AsTuples().Select(x => x.Item1).ToArray()); double[] discDfs = discCurve.AsTuples().Select(x => x.Item2).ToArray(); double[] fcstDfs = (bOIS ? discCurve.AsTuples().Select(x => x.Item2).ToArray() : fcstCurve.AsTuples().Select(x => x.Item2).ToArray()); double mms = BondAnalytics.CalcMMS(settle, maturity, dct, fixedFreq, floatFreq, discDfDates, discDfs, fcstDfDates, fcstDfs, hols, null, null, null, null, null, firstCpnDate, (bOIS ? 5 : 0)); double yield = BondAnalytics.SolveYield(eCountry,settle ,price, effectiveDate, firstCpnDate, maturity, coupon, bondCpnFreq)[0]; output= 10000.0 * (mms - yield); break; } } return output; }