public CMTTestSheet(DateTime startDate, DateTime endDate, string market, KnownCurve curve1, KnownCurve curve2) { mStartDate = startDate; mEndDate = endDate; mMarket = market; mCurve1 = curve1; mCurve2 = curve2; BuildMonikers(); }
protected Moniker CreateCurveMoniker(string close, string source, KnownCurve knownCurve, Type type) { return new Moniker { Close = close, Date = ValueDate, Name = KnownCurveHelpers.GetKnownCurveCode(knownCurve), Source = source, Type = type.Name }; }
public static void BuildUSDSmooth(string quoteSource, DateTime valueDate, KnownCurve curve_ = KnownCurve.NotSet) { try { new CalculationAgent(valueDate, quoteSource).BuildUSDSmoothSeries(curve_); } catch (Exception ex) { SLog.log.Error("Error calculating smooth curves for date " + valueDate.ToString(), ex); } }
public static string InferSnapCodeFromKnownCurve(KnownCurve curve_) { switch (curve_) { case KnownCurve.USD3mLibor: case KnownCurve.USD3mLiborOISD: case KnownCurve.USDFedFunds: return "NYK"; default: return "LDN"; } }
protected Tuple<Moniker, string> CreateMonikerTuple(int series, decimal point, KnownCurve curve, string curveType) { return new Tuple<Moniker, string>(BondSpread.CreateBondSpreadMoniker(mStartDate, "mlp", "mlp", mMarket, series, KnownCurveHelpers.GetKnownCurveCode(curve), point), curveType); }
protected DiscountCurve CallCurveCalculator(ICalculator calculator, KnownCurve knownCurve, string marketSnapCode_, string quotesourceCode_, CarbonClient carbonClient_) { DateTime startTime = DateTime.Now; SLog.log.InfoFormat("Calculation of {0} for {1} starting...", knownCurve.GetDescription(), ValueDate); // generate the table of constituents { var cp = String.Compare("mlp", quotesourceCode_, StringComparison.OrdinalIgnoreCase) == 0 ? calculator.BuildConstituentsTable() : null; if (cp != null) { var moniker = GenericTable.GenerateSwapCurveConstituentsMoniker(ValueDate, marketSnapCode_.ToLower(), quotesourceCode_.ToLower(), KnownCurveHelpers.GetKnownCurveCode(knownCurve)); SObjectManager.Instance().SaveSObject(moniker, cp); } } if (mConstituentsOnly) return null; // this is the old way, which will invoke fincad... //var curves = calculator.Calculate(); var curves = Symmetry.Interop.Carbon.OT.CurveRetriever .GetCurvesAsDictionary(knownCurve, ValueDate, carbonClient_, ThrowBehavior.DontThrow); foreach (var kvp in curves) { if (kvp.Value != null) { Type type = null; switch (kvp.Key) { case "DiscountCurve": type = typeof(DiscountCurve); break; case "RateCurve": type = typeof(RateCurve); break; case "Parameters": type = typeof(SwapCurveParameters); break; } if (type != null) { var moniker = CreateCurveMoniker(marketSnapCode_.ToLower(), quotesourceCode_.ToLower(), knownCurve, type); SObjectManager.Instance().SaveSObject(moniker, kvp.Value); } else if (kvp.Key == "Constituents") { // don't want to overwrite if mlp (will have been written above if (String.Compare("mlp", quotesourceCode_, StringComparison.OrdinalIgnoreCase) == 0) continue; var moniker = GenericTable.GenerateSwapCurveConstituentsMoniker(ValueDate, marketSnapCode_.ToLower(), quotesourceCode_.ToLower(), KnownCurveHelpers.GetKnownCurveCode(knownCurve)); SObjectManager.Instance().SaveSObject(moniker, kvp.Value); } } } SLog.log.InfoFormat("Calculation of {0} finished in {1} ms...", knownCurve.GetDescription(), (DateTime.Now - startTime).TotalMilliseconds); if (curves.ContainsKey("DiscountCurve")) { return (DiscountCurve)curves["DiscountCurve"]; } return null; }
public void BuildUSDSmoothSeries(KnownCurve curve_ = KnownCurve.NotSet) { foreach (var sourceSet in SP.GetUSD(mQuoteSource)) { var sw = Stopwatch.StartNew(); SLog.log.InfoFormat("Smooth Bond Curve calculation starting for USD.{0} {1}...", sourceSet.QS, ValueDate); if (curve_ == KnownCurve.NotSet || curve_ == KnownCurve.USD3mLibor) { InternalBuildSmoothBondSeries(KnownCurve.USD3mLibor, new SmoothBondCurveCalculationParams { SpotDelay = 2, SettleDelay = 1, HolidayCenter = "USA_FI", Close = sourceSet.MS, Source = sourceSet.QS, CurveStart = 1, CurveStep = 0.25M, YieldLambdas = new Dictionary<int, double> { { 2, 0 }, { 3, 1 }, { 5, 1 }, { 7, 1 }, { 10, 1 }, { 30, 0 } }, SpreadLambdas = new Dictionary<int, double> { { 2, 0 }, { 3, 1 }, { 5, 1 }, { 7, 1 }, { 10, 1 }, { 30, 0 } }, TrueSpreadLambdas = new Dictionary<int, double> { { 2, 0 }, { 3, 1 }, { 5, 1 }, { 7, 1 }, { 10, 1 }, { 30, 0 } }, CurveName = KnownCurveHelpers.GetKnownCurveCode(KnownCurve.USD3mLibor), Markets = new string[] { "UST" }, Currency = "USD", Maturities = new int[] { 2, 3, 5, 7, 10, 30 }, SwapCurveType = SwapCurveType.USD3mLibor, Country = "UST", AnalyticsCountry=BondAnalytics.Country.US, ShouldIncludeBondInTargetMaturityDelegate = (bond_, targetMaturity) => targetMaturity == 30 && bond_.Term.HasValue && bond_.Term.Value > 15 }); } if (curve_ == KnownCurve.NotSet || curve_ == KnownCurve.USDFedFunds) { InternalBuildSmoothBondSeries(KnownCurve.USDFedFunds, new SmoothBondCurveCalculationParams { SpotDelay = 2, SettleDelay = 1, HolidayCenter = "USA_FI", Close = sourceSet.MS, Source = sourceSet.QS, CurveStart = 1, CurveStep = 0.25M, YieldLambdas = new Dictionary<int, double> { { 2, 0 }, { 3, 1 }, { 5, 1 }, { 7, 1 }, { 10, 1 }, { 30, 0 } }, SpreadLambdas = new Dictionary<int, double> { { 2, 0 }, { 3, 1 }, { 5, 1 }, { 7, 1 }, { 10, 1 }, { 30, 0 } }, TrueSpreadLambdas = new Dictionary<int, double> { { 2, 0 }, { 3, 1 }, { 5, 1 }, { 7, 1 }, { 10, 1 }, { 30, 0 } }, CurveName = KnownCurveHelpers.GetKnownCurveCode(KnownCurve.USDFedFunds), Markets = new string[] { "UST" }, Currency = "USD", Maturities = new int[] { 2, 3, 5, 7, 10, 30 }, SwapCurveType = SwapCurveType.USDOIS, Country = "UST", AnalyticsCountry=BondAnalytics.Country.US, ShouldIncludeBondInTargetMaturityDelegate = (bond_, targetMaturity) => targetMaturity == 30 && bond_.Term.HasValue && bond_.Term.Value > 15 }); } //if (curve_ == KnownCurve.NotSet || curve_ == KnownCurve.USD3mLiborOISD) //{ // InternalBuildSmoothBondSeries(KnownCurve.USD3mLiborOISD, new SmoothBondCurveCalculationParams // { // SpotDelay = 2, // SettleDelay = 1, // HolidayCenter = "USA_FI", // Close = sourceSet.MS, // Source = sourceSet.QS, // CurveStart = 1, // CurveStep = 0.25M, // YieldLambdas = new Dictionary<int, double> { { 2, 0 }, { 3, 1 }, { 5, 1 }, { 7, 1 }, { 10, 1 }, { 30, 0 } }, // SpreadLambdas = new Dictionary<int, double> { { 2, 0 }, { 3, 1 }, { 5, 1 }, { 7, 1 }, { 10, 1 }, { 30, 0 } }, // TrueSpreadLambdas = new Dictionary<int, double> { { 2, 0 }, { 3, 1 }, { 5, 1 }, { 7, 1 }, { 10, 1 }, { 30, 0 } }, // CurveName = KnownCurveHelpers.GetKnownCurveCode(KnownCurve.USD3mLiborOISD), // Markets = new string[] { "UST" }, // Currency = "USD", // Maturities = new int[] { 2, 3, 5, 7, 10, 30 }, // SwapCurveType = SwapCurveType.USD3mLibor, // Country = "UST", // ShouldIncludeBondInTargetMaturityDelegate = (bond_, targetMaturity) => targetMaturity == 30 && bond_.Term.HasValue && bond_.Term.Value > 15 // }); //} SLog.log.InfoFormat("Smooth Bond Curve calculation finished in {0} ms...", sw.ElapsedMilliseconds); } }
protected void InternalBuildSmoothBondSeries(KnownCurve knownCurve, SmoothBondCurveCalculationParams parameters, bool buildCMT = true) { if (mConstituentsOnly) { return; } var curve = SObjectManager.Instance().LoadSObject<DiscountCurve>(new Moniker { Close = parameters.Close, Source = parameters.Source, Type = "DiscountCurve", Date = ValueDate, Name = KnownCurveHelpers.GetKnownCurveCode(knownCurve) }); if (curve == null) { SLog.log.ErrorFormat("Unable to load curve {0} for smooth series construction.", knownCurve.ToString()); return; } // delete the old data else might have residual stuff saved that confuses things { SLog.log.Debug("Deleting any previous data from the database..."); foreach (var ending in new[] { string.Empty, "%" }) SObjectManager.Instance().DeleteCachedObject( monikerDate_: ValueDate, monikerSource_: parameters.Source, likeMonikerName_: string.Format("{0}%{1}{2}", parameters.Country, parameters.CurveName, ending)); } SLog.log.DebugFormat("Building {0} smooth curve over {1} on {2}", parameters.Country, parameters.CurveName, ValueDate); IEnumerable<KeyValuePair<string, AnySObject>> allObjects = new Dictionary<string, AnySObject>(); Dictionary<string, Dictionary<int, RateCurve>> cmtGlobal = new Dictionary<string, Dictionary<int, RateCurve>>(); foreach (var maturity in parameters.Maturities) { try { var smoothCurves = new SmoothBondCurveCalculator(ValueDate, new SmoothBondCurveParameters { SpotDelay = parameters.SpotDelay, SettleDelay = parameters.SettleDelay, HolidayCenter = parameters.HolidayCenter, Close = parameters.Close, Source = parameters.Source, CurveStart = parameters.CurveStart, CurveStep = parameters.CurveStep, YieldLambda = parameters.YieldLambdas[maturity], SpreadLambda = parameters.SpreadLambdas[maturity], TrueSpreadLambda = parameters.TrueSpreadLambdas[maturity], CurveName = parameters.CurveName, Markets = parameters.Markets, Currency = parameters.Currency, Country = parameters.Country, AnalyticsCountry = parameters.AnalyticsCountry, Maturity = maturity, SwapCurveType = parameters.SwapCurveType, TermDrift = parameters.BondTermDrift, ShouldIncludeDelegate = parameters.ShouldIncludeBondInTargetMaturityDelegate, }, curve).Calculate(); if (smoothCurves.ContainsKey("Yield")) { var yieldMoniker = RateCurve.CreateSmoothCurveMoniker(ValueDate, "yield", parameters.Country, maturity, parameters.Close, parameters.Source, parameters.CurveName); SObjectManager.Instance().SaveSObject(yieldMoniker, smoothCurves["Yield"]); } if (smoothCurves.ContainsKey("Spread")) { var spreadMoniker = RateCurve.CreateSmoothCurveMoniker(ValueDate, "spread", parameters.Country, maturity, parameters.Close, parameters.Source, parameters.CurveName); SObjectManager.Instance().SaveSObject(spreadMoniker, smoothCurves["Spread"]); } if (smoothCurves.ContainsKey("MMS")) { var mmsMoniker = RateCurve.CreateSmoothCurveMoniker(ValueDate, "mms", parameters.Country, maturity, parameters.Close, parameters.Source, parameters.CurveName); SObjectManager.Instance().SaveSObject(mmsMoniker, smoothCurves["MMS"]); } if (smoothCurves.ContainsKey("TrueSpread")) { var trueSpreadMoniker = RateCurve.CreateSmoothCurveMoniker(ValueDate, "truespread", parameters.Country, maturity, parameters.Close, parameters.Source, parameters.CurveName); SObjectManager.Instance().SaveSObject(trueSpreadMoniker, smoothCurves["TrueSpread"]); } foreach (var kvp in smoothCurves) { if (Moniker.IsMoniker(kvp.Key)) { SObjectManager.Instance().SaveSObject(Moniker.FromString(kvp.Key), kvp.Value); } } if (buildCMT) { var bsObjects = new CMTBondSpreadCalculator(ValueDate, new CMTBondSpreadParameters { Close = parameters.Close, CurveName = parameters.CurveName, Country = parameters.Country, Maturity = maturity, Source = parameters.Source, Maturities = parameters.Maturities }, smoothCurves, ref cmtGlobal).Calculate(); foreach (var bso in bsObjects) { SObjectManager.Instance().SaveSObject(Moniker.FromString(bso.Key), bso.Value); } allObjects = allObjects.Union(bsObjects.AsEnumerable()); } } catch (Exception ex) { SLog.log.Error("Error calculating smooth series", ex); } } if (buildCMT) { try { foreach (var curveType in cmtGlobal.Keys) foreach (var series in cmtGlobal[curveType].Keys) { var moniker = RateCurve.CreateBondSeriesCurveMoniker(ValueDate, curveType, parameters.Country, series, parameters.Close, parameters.Source, parameters.CurveName); SObjectManager.Instance().SaveSObject(moniker, cmtGlobal[curveType][series]); } } catch (Exception ex) { SLog.log.Error("Error saving cmt rate curves", ex); } } }
public static SwapPricingConfig GetConfig(KnownCurve curve_) { switch (curve_) { case KnownCurve.EUR6mEuribor: case KnownCurve.EUR6mEuriborOISD: return new SwapPricingConfig() { DiscCurve=KnownCurve.EUREonia, FcstCurve=KnownCurve.EUR6mEuribor, CalcFunction = BondAnalytics.CalcMMS_Euribor }; case KnownCurve.EUREonia: return new SwapPricingConfig() { DiscCurve=KnownCurve.EUREonia, FcstCurve=KnownCurve.EUREonia, CalcFunction = BondAnalytics.CalcMMS_Eonia, }; case KnownCurve.USD3mLibor: case KnownCurve.USD3mLiborOISD: return new SwapPricingConfig() { DiscCurve = KnownCurve.USDFedFunds, FcstCurve = KnownCurve.USD3mLibor, CalcFunction = BondAnalytics.CalcMMS_USLibor }; case KnownCurve.USDFedFunds: return new SwapPricingConfig() { DiscCurve = KnownCurve.USDFedFunds, FcstCurve = KnownCurve.USDFedFunds, CalcFunction = BondAnalytics.CalcMMS_USFedFunds }; case KnownCurve.GBP6mLibor: case KnownCurve.GBP6mLiborOISD: return new SwapPricingConfig() { DiscCurve = KnownCurve.GBPSonia, FcstCurve = KnownCurve.GBP6mLibor, CalcFunction = BondAnalytics.CalcMMS_GBLibor }; case KnownCurve.GBPSonia: return new SwapPricingConfig() { DiscCurve = KnownCurve.GBPSonia, FcstCurve = KnownCurve.GBPSonia, CalcFunction = BondAnalytics.CalcMMS_GBSonia }; case KnownCurve.JPY6mLibor: return new SwapPricingConfig() { DiscCurve=KnownCurve.JPYTona, FcstCurve=KnownCurve.JPY6mLibor, CalcFunction=BondAnalytics.CalcMMS_JPLibor }; case KnownCurve.JPYTona: return new SwapPricingConfig() { DiscCurve=KnownCurve.JPYTona, FcstCurve=KnownCurve.JPYTona, CalcFunction=BondAnalytics.CalcMMS_JPOIS }; default: return null; } }
public static GenericPrice Calculate(KnownCurve curve_, DateTime valueDate_, DateTime swapStart_, DateTime swapEnd_, string quoteSource_="mlp", string snapCode_="mlp" ) { // have we set up a config for this curve yet? var config = SwapPricingConfig.GetConfig(curve_); if (config == null) { SLog.log.ErrorFormat("Coult not find SwapPrincingConfig config for {0}", curve_); return null; } // get the persisted discount curves for the fixed and floating legs var discCurve = SObjectManager.Instance().LoadSObject<DiscountCurve>(new Moniker() { Close=snapCode_, Source=quoteSource_, Name=KnownCurveHelpers.GetKnownCurveCode(config.DiscCurve), Type="discountcurve", Date=valueDate_ }); if (discCurve == null) { SLog.log.ErrorFormat("Could not load {0} discount curve from database for {1}", config.DiscCurve, valueDate_); } var fcstCurve = SObjectManager.Instance().LoadSObject<DiscountCurve>(new Moniker() { Close = snapCode_, Source = quoteSource_, Name = KnownCurveHelpers.GetKnownCurveCode(config.FcstCurve), Type = "discountcurve", Date = valueDate_ }); if (fcstCurve == null) { SLog.log.ErrorFormat("Could not load {0} discount curve from database for {1}", config.FcstCurve, valueDate_); } if (discCurve == null || fcstCurve == null) { return null; } var mms = config.CalcFunction( swapStart_, swapEnd_, discCurve.AsDoubleArray().SliceColumn(0).Select(DateTime.FromOADate).ToArray(), discCurve.AsDoubleArray().SliceColumn(1), fcstCurve.AsDoubleArray().SliceColumn(0).Select(DateTime.FromOADate).ToArray(), fcstCurve.AsDoubleArray().SliceColumn(1)); if (double.IsNaN(mms)) { SLog.log.ErrorFormat("Could not calcualate mms for {0} vd:{1}; start:{2}, end:{3}", curve_, valueDate_.ToString("dd-MMM-yyyy"), swapStart_.ToString("dd-MMM-yyyy"), swapEnd_.ToString("dd-MMM-yyyy")); } return new GenericPrice() { Price = mms }; }
public static string GetKnownCurveCode(KnownCurve curve) { return curve.GetDescription(); }