public void ComputeLiveBondSpread(List<ChartComponent> components, BondCurves curve, BondAnalytics.Country country, string guid) { try { Logger.Info("Computing Live Bond Spread.....", typeof(LiveBondSpreadModel)); // live var liveCurve = GetLiveCurve(EnumDescriptionAttribute.GetDescription(curve)).GetValues(); var finalResultList = new List<double>(); foreach (var chartComponent in components) { // look up the current live ctd bond isin var isin = _liveDataModel.GetCusipFromStructure(chartComponent.Component); if (string.IsNullOrEmpty(isin)) return; var bondPrice = (_liveDataModel.GetRealTimeBondData(isin).Bid + _liveDataModel.GetRealTimeBondData(isin).Ask) / 2; var settleDate = CarbonModel.RollDate(DateTime.Today, 1, DateUnit.Bd, BusinessDayConvention.Following, "USNY"); var maturity = _bond[chartComponent.Component, CTDValueGeneration.Current].Maturity ?? DateTime.MinValue; var coupon = _bond[chartComponent.Component, CTDValueGeneration.Current].Coupon; var bondSpread = BondAnalytics.SolveZSpread(country, settleDate, bondPrice, DateTime.MinValue, DateTime.MinValue, maturity, coupon, 6, liveCurve.Item1, liveCurve.Item2, new List<DateTime>()); // for smoothing, we also need the current obond isin. // if obond is different from current live ctd bond, we also compute the live bond spread for the obond ctd. if (bondSpread == -1.0) bondSpread = double.NaN; var finalResult = -1 * bondSpread * chartComponent.Multiplier * 10000d; finalResultList.Add(finalResult); } var result = finalResultList.Sum(); bsResultSubject.OnNext(new BondSpreadResult() { Guid = guid, Components = components, Country = country, Curve = curve, BondSpread = result, // also set the obond spread here //oBondSpread = }); } catch(Exception e) { Logger.Error("Exception while computing bond spread", typeof(LiveBondSpreadModel), e); } }
public void SubscribeAndCompute(List<ChartComponent> components, BondCurves curve, BondAnalytics.Country country, string guid) { var curveName = EnumDescriptionAttribute.GetDescription(curve).ToUpper(); var newComponentList = new List<ChartComponent>(); foreach (var chartComponent in components) { newComponentList.Add(chartComponent.Clone()); } workitems[guid] = new LiveBondSpreadWorkItem { Guid = guid, Components = newComponentList, Curve = curve, Country = country, ComputeAction = (com, ccy, c, g) => ComputeLiveBondSpread(com, ccy, c, g), }; // get curve update stream var disp = CarbonSubscriber.Instance().LiveCurveObservable() .Where(c => c.CarbonCurveName == curveName) .Sample(TimeSpan.FromMilliseconds(500)) //.SubscribeOn(Scheduler.ThreadPool) .ObserveOn(Scheduler.CurrentThread) .Subscribe(_ => workitems[guid].Compute()); disps.Add(disp); }
protected void setComponent(Display.ChartComponent component_, CTDValuePair pair_, double multiplier_, BondCurves curve_=BondCurves.USD3mLibor) { component_.Enabled = true; component_.Curve = curve_; component_.Component = pair_; component_.Multiplier = multiplier_; }
protected RollCalculatorBase(BondMarket market_, BondCurves curve_, double rollFromTenor_, double rollToTenor_, int series_=1) { Market = market_; Curve = curve_; RollFromTenor = rollFromTenor_; RollToTenor = rollToTenor_; SeriesNumber = series_; CMTCurve.RegisterMongo(); }
public DatedDataCollectionGen<double> GetPoint(BondMarket market_, int series_, Focus focus_, BondCurves curve_, decimal curvePoint_) { var pointIndex = AllPoints.ToList().IndexOf(curvePoint_); if (pointIndex == -1) return null; var curve = Get(market_, series_, focus_, curve_, false); if (curve == null) return null; return curve.Data.GetColumnValuesAsDDC(pointIndex); }
public CMTCurve Get(BondMarket market_, int series_, Focus focus_, BondCurves curve_, bool createIfNotThere_ = false) { // messy! but necessary // yield has no need for a curve, so I only save to Mongo for the 'default' curve for the market // so if yield is requested, then override the requested curve with the default otherwise no data will be found var curve = (focus_ == Focus.Yield) ? BondAnalysisLineHelper.GetDefaultCurveForMarket(market_) : curve_; var item = m_list.FirstOrDefault(x => x.Market == market_ && x.Series == series_ && x.Focus==focus_ && x.Curve==curve); if (item != null) return item; // try to get from mongo item = SI.DB.MongoDB.GetCollection<CMTCurve>(MongoDBDetails.SVR_REF, MongoDBDetails.DB, MongoDBDetails.Curve_Collection) .Find(Builders<CMTCurve>.Filter.Where(x=> x.Series == series_ && x.Market == market_ && x.Focus == focus_ && x.Curve == curve)).FirstOrDefaultAsync().Result; if (item != null) { m_list.Add(item); return item; } if (createIfNotThere_) { item = new CMTCurve { Market = market_, Series = series_, Focus = focus_, Curve=curve, Data = new ConstructGen<double>(AllPoints.Select(x => x.ToString()).ToArray()) }; m_list.Add(item); } return item; }
public USRoll(BondCurves curve_, double rollFromTenor_, double rollToTenor_, int series_ = 1) : base(BondSpreadAnalysis.Enums.BondMarket.US, curve_, rollFromTenor_, rollToTenor_, series_) { }
public string SubscribeAndCompute(List<ChartComponent> components, BondCurves curve, BondAnalytics.Country country) { var guid = Guid.NewGuid().ToString(); livebsmodel.SubscribeAndCompute(components, curve, country, guid); return guid; }
private static BondSpreads getSpreads(Bond b_, DateTime date_, BondCurves curve_) { if (b_ == null) return null; var spreads = b_.GetSpreadsVsCurve(curve_); if(spreads==null) return null; var sp = spreads.ValueOnExactDate(date_); if (sp == null) { Logger.Error(string.Format("No bond spread found for {0}{1} on date {2}", b_.SymmetryCode, b_.DisplayName, date_.ToString("dd-MMM-yyyy")), typeof(Generator)); return null; } return sp; }
public static List<CTDLine<BondSpreads>> GetSpreads(List<CTDLine<Bond>> bonds_, BondCurves curve_, CashBondRolling cashBondRollOption_ = CashBondRolling.Monthly, bool doSerialize_=true) { string diskPath = string.Format(@"{0}\BondSpreads_Roll{1}_{2}", DiskCacheHelper.PATH_CTD, cashBondRollOption_, curve_); if (DiskCacheHelper.OnlyReadFromCache) { return Singleton<DiscCache>.Instance.ReadFromGivenFilePath<List<CTDLine<BondSpreads>>>(diskPath, true); } var retList=new List<CTDLine<BondSpreads>>(); CTDValue[] allVals = (CTDValue[])Enum.GetValues(typeof(CTDValue)); foreach(var line in bonds_) { var retLine=new CTDLine<BondSpreads>(line.MarkDate); foreach(var val in allVals) { Logger.InfoFormat(typeof(Generator), "Computing bond spreads for {0} on date: {1}", val, line.MarkDate); var sp = getSpreads(line[val], line.MarkDate, curve_); retLine[val] = sp; } retList.Add(retLine); } if(doSerialize_) Singleton<DiscCache>.Instance.WriteToGivenFilePath(diskPath, retList); return retList; }