public static ConstructGen<double> GetSmoothCurvesColumnsAreCurvePoints(DateTime valueDate_, uint curveCount_, BondMarket market_, BondField field_, SI.Data.BondCurves curve_, string close_ = "MLP", string source_ = "MLP") { DateTime date = valueDate_; var points = new List<decimal>(); for (decimal d = 1M; d < 30M; d = d + 0.25M) points.Add(d); var con = new ConstructGen<double>(points.Select(x => x.ToString()).ToArray()); for (int i = 0; i < curveCount_; ++i) { var curve = GetSmoothCurve(date, market_, field_, curve_, close_, source_); if (curve == null) continue; foreach (var node in curve.GetNodes()) { int index = points.IndexOf(node); if (index == -1) continue; var point = curve.GetValue(node); if(point.HasValue) con.SetValue(date, index, point.Value); } date = MyCalendar.PrevWeekDay(date); } con.SortKeys(); return con; }
public OTREditorMenuItem_RefreshMarketTenorFromBloomberg(BondMarket market_, int tenor_) { Market = market_; Tenor = tenor_; Text = string.Format("Refresh {0} {1}Y point from Bloomberg", market_, tenor_); }
public static DatedDataCollectionGen<double> GetHistoricalSpreads(BondMarket market1_, BondMarket market2_, Focus focus_, int curvePoint_) { var s1 = GetHistoricalCMT(market1_, focus_, curvePoint_); var s2 = GetHistoricalCMT(market2_, focus_, curvePoint_); return (s1 == null || s2 == null) ? null : s1.Minus(s2); }
public static ConstructGen<double> GetSmoothCurvesColumnsAreValueDates(DateTime valueDate_, uint curveCount_, BondMarket market_, BondField field_, SI.Data.BondCurves curve_, string close_ = "MLP", string source_ = "MLP") { var tempDict = new SortedDictionary<DateTime, RateCurve>(); var date = valueDate_; for (int i = 0; i < curveCount_; ++i) { var curve = GetSmoothCurve(date, market_, field_, curve_, close_, source_); if (curve == null) continue; tempDict.Add(date, curve); date = MyCalendar.PrevWeekDay(date); } var keys = tempDict.Keys.ToArray(); var con = new ConstructGen<double>(keys.Select(x => x.ToString("dd MMM")).ToArray()); for (int i = 0; i < keys.Length; ++i) { var curve = tempDict[keys[i]]; foreach (var node in curve.GetNodes()) { var time = valueDate_.AddDays(Convert.ToDouble(node)*365.25).Date; con.SetValue(time, i, curve.GetValue(node).Value*100d); } } return con; }
public static ConstructGen<double> GetHistoricalSpreads(BondMarket market1_, BondMarket market2_, Focus focus_) { var s1 = GetHistoricalCMT(market1_, focus_); var s2 = GetHistoricalCMT(market2_, focus_); return (s1 == null || s2 == null) ? null : s1.Minus(s2); }
public static HistoricalCMT GetInstance(Data.BondCurves curve_, BondMarket market_, Focus focus_, bool createIfNotThere_=true) { var key = getKey(curve_, market_, focus_); if(m_cache.ContainsKey(key)==false) lock(m_cache) if(m_cache.ContainsKey(key)==false) { var record = SI.DB.MongoDB.GetCollection<HistoricalCMT>(MongoDBDetails.ServerReference, MongoDBDetails.DB, MongoDBDetails.CMTCollection) .Find(Builders<HistoricalCMT>.Filter.Where(h => h.Market == market_ && h.Curve == curve_ && h.Focus == focus_)) .FirstOrDefaultAsync().Result; if (record == null && createIfNotThere_) { record = new HistoricalCMT { Market = market_, Curve = curve_, Focus = focus_, CMTs = new ConstructGen<double>(CMTLine.AllPoints.Select(x => string.Format("{0}Y", x)).ToArray()), FitParameters = new ConstructGen<double>(new[] {1, 2, 3, 4, 5, 6}.Select(x => x.ToString()).ToArray()), }; } m_cache[key] = record; } return m_cache[key]; }
public OTRCountryGroupNode(string text_, BondMarket[] markets_, StructureGrouping grouping_, int structureIndex_=-1) { Markets = markets_; Text = text_; Grouping = grouping_; StructureIndex = structureIndex_; }
public IntraCountryFlyMenuItem(string[] folderPath_, string text_, BondMarket market_, FlyWeightingMethod method_, int historyWinLength_) : base(folderPath_,text_) { Market = market_; WeightingMethod = method_; HistoryWindowLength = historyWinLength_; }
private void OnBondMarketChanged(BondMarket market_) { var h = BondMarketChanged; if (h != null) h(this, new BondMarketChangedEventArgs(market_)); }
public static ConstructGen<double> GetHistoricalCMT(BondMarket market_, Focus focus_) { HistoricalCMT.RegisterMongo(); var m = HistoricalCMT.GetInstance(BondAnalysisLineHelper.GetDefaultCurveForMarket(market_), market_, focus_, false); return m == null ? null : m.CMTs; }
public CreateCountryBondFlysForMaturityGaps(string[] folderPath_, string text_, BondMarket market_, uint unitGap_, MaturityGapUnit unitType_, BondFlyWeightMode mode_) : base(folderPath_,text_) { Market = market_; UnitGap = unitGap_; MyMode = mode_; UnitType = unitType_; }
public CrossMarketFlyMenuItem(string[] folderPath_, string text_, int tenor_, int historyLength_, BondMarket[] markets_, FlyWeightingMethod method_) : base(folderPath_, text_) { Tenor = tenor_; Markets = markets_; WeightingMethod = method_; HistoryLength = historyLength_; }
public static void RefreshFromMongo(BondMarket market_, int tenor_, int seriesNumber_) { var record = SI.DB.MongoDB.GetCollection<CMTCarry>(Mongo.MongoDBDetails.SVR_REF, Mongo.MongoDBDetails.DB, Mongo.MongoDBDetails.CArry_Collection) .Find(Builders<CMTCarry>.Filter.Where(h => h.Market == market_ && h.Tenor == tenor_&& h.CMTSeriesNumber== seriesNumber_)) .FirstOrDefaultAsync().Result; if (record != null) _cache[getKey(market_, tenor_, seriesNumber_)] = record; }
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 static SI.Data.BondCurves GetDefaultCurveForMarket(BondMarket market_) { switch (market_) { case BondMarket.US: return Data.BondCurves.USD3mLibor; case BondMarket.GB: return Data.BondCurves.GBP6mLibor; default: return Data.BondCurves.EUR6mEuribor; } }
public void Create(BondMarket market_) { Market = market_; m_maturity = CarbonHistoricRetriever.GetDateForward(DateTime.Today, 5, Symmetry.Carbon.Model.DateUnit.Y); dtpFwdDate.DateTime = m_maturity; dtpFwdDate.ValueChanged += (x, y) => { m_maturity = dtpFwdDate.DateTime; if (m_dummy != null) getDummy().Maturity = m_maturity; }; }
public static CMTLine GetCMTSpreadLiveDiff(BondMarket market1_, BondMarket market2_, Focus focus_) { var key = getSpreadLineKey(market1_, market2_, focus_); if (_spreadLineCache.ContainsKey(key)) return _spreadLineCache[key]; var diff = new CMTLineDiff( CountryBondSource.GetInstance(market1_).GetSmoothCurveGroupForFocus(focus_).LiveCMT, CountryBondSource.GetInstance(market2_).GetSmoothCurveGroupForFocus(focus_).LiveCMT); _spreadLineCache[key] = diff; return diff; }
public static void Collate(BondMarket market_=BondMarket.US) { var allTenors = SI.ExtensionMethods.CreateArray(1, 30, x => x + 1); var con = new ConstructGen<double>(allTenors.Select(x => string.Format("cmt_{0}", x)).ToArray()); for (int i = 0; i < allTenors.Length; ++i) { var cr = Get(market_, allTenors[i]); if (cr == null) continue; con.SetColumnValues(i, cr.Values.GetColumnValuesAsDDC((int) CMTCarry.ColPosition.Carry)); } con.WriteToCSV(string.Format(@"e:\temp\CMTCarry_{0}.csv", market_)); }
public DateTime CurrentLiveTime(BondMarket market) { switch (market) { case BondMarket.US: return DateTime.UtcNow.AddHours(-5); break; case BondMarket.EU: // todo! need to implement for EU break; default: throw new ArgumentOutOfRangeException("market", market, null); } return DateTime.MinValue; }
private static RateCurve GetSmoothCurve(DateTime valueDate_, BondMarket market_, BondField field_, SI.Data.BondCurves curve_, string close_ = "MLP", string source_ = "MLP") { var moniker = RateCurve.CreateBondSeriesCurveMoniker( valueDate: valueDate_, curveType: GetDBCurveTypeNameFromField(field_), country: convertMarketCode(market_), series: 1, close: close_, source: source_, curveName: EnumDescriptionAttribute.GetDescription(curve_) ); var curve = SObjectManager.Instance().LoadSObject<RateCurve>(moniker); return curve; }
public void Create(BondMarket initialMarket1_, BondMarket initialMarket2_, Focus focus_) { m_args = new Args() { Market1 = initialMarket1_, Market2 = initialMarket2_, Focus = focus_ }; lblCountry1.Bind(m_args, "Market1", new Validators.EnumDescValidator(m_args.Market1)); lblCountry2.Bind(m_args, "Market2", new Validators.EnumDescValidator(m_args.Market2)); lblField.Bind(m_args, "Focus", new Validators.EnumDescValidator(m_args.Focus)); rebuildBinding(); m_args.PropertyChanged += (a, b) => rebuildBinding(); }
public void Create(BondMarket initialMarket_, Focus initialFocus_, CurveSetPeriod initialPeriod_) { m_args.Market = initialMarket_; m_args.Focus = initialFocus_; m_args.Period = initialPeriod_; m_args.PropertyChanged += (a, b) => { reloadCurve(); }; reloadCurve(); lblCountry.Bind(m_args, "Market", new Validators.EnumDescValidator(m_args.Market)); lblField.Bind(m_args, "Focus", new Validators.EnumDescValidator(m_args.Focus)); lblPeriod.Bind(m_args, "Period", new Validators.EnumDescValidator(m_args.Period)); }
protected CountryBondSource(Data.BondCurves curve_, BondMarket market_, DateTime asOfDate_) { Curve = curve_; Market = market_; m_asOfDate = asOfDate_; m_bondMarketCodes = AttributeHelper.GetSingleAttribute<MarketCodeAttribute>(Market).MarketCodes; CouponPaymentFreq = AttributeHelper.GetSingleAttribute<CouponPaymentFreqAttribute>(Market).Freq; rebuildList(); m_recalcNumber = CentralEvents.GetNextIteration(); if (asOfDate_ >= DateTime.Today) { GetSmoothCurveGroupForFocus(Focus.Yield).ToString(); GetSmoothCurveGroupForFocus(Focus.ASW).ToString(); GetSmoothCurveGroupForFocus(Focus.CAS).ToString(); } }
public static CMTCarry Get(BondMarket market_, int tenor_, int seriesNumber_ = 1, bool createIfNotThere_=false) { var key = getKey(market_, tenor_, seriesNumber_); if (_cache.ContainsKey(key)) return _cache[key]; CMTCarry.RegisterMongo(); RefreshFromMongo(market_, tenor_, seriesNumber_); if (_cache.ContainsKey(key)) return _cache[key]; if (createIfNotThere_) return _cache[key] = new CMTCarry() {CMTSeriesNumber = seriesNumber_, Market = market_, Tenor = tenor_}; return null; }
private static string convertMarketCode(BondMarket market_) { switch (market_) { case BondMarket.DE: return "DE"; case BondMarket.ES: return "ES"; case BondMarket.FR: return "FR"; case BondMarket.IT: return "IT"; case BondMarket.NL: return "NL"; case BondMarket.GB: return "GB"; default : throw new Exception("market needs to be implemented"); } }
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 static IEnumerable<KeyValuePair<string, double>> GetHistoricValues( BondMarket market_, MongoBond bond_, double price_, DateTime asOf_, CarbonClient client_, string pricingSetup_="Sym_LIBOR" ) { try { var baseBondId = getBaseBondID(market_, bond_.Maturity); var result = client_.PriceBondAsync( baseBondId: (long)baseBondId, issueDate: DateConversions.ToNodaLocalDate(bond_.IssueDate), maturityDate: DateConversions.ToNodaLocalDate(bond_.Maturity), coupon: bond_.Coupon / 100d, asof: asOf_, pricingSetup: pricingSetup_, quantity: 1000000d, stubDate: DateConversions.ToNodaLocalDate(bond_.FirstCouponDate), price: price_).Result; if (result.Results.Any(x => double.IsNaN(x.Value))) { Logger.Error( string.Format("At least one Null value returned from carbon Date={0}, Market={1}", asOf_.ToString("dd-MMM-yyyy"), market_), typeof(CarbonHistoricRetriever)); } return result.Results; } catch (Exception ex_) { Logger.Error("Error pricing bond", typeof(CarbonHistoricRetriever), ex_); return null; } }
/// <summary> /// /// </summary> /// <param name="issueDate_"></param> /// <param name="maturityDate_"></param> /// <param name="cleanPriceInPercent_">in the form 1.01 not 101</param> /// <param name="couponInPercent_">in the form 2 rather than 0.02 </param> /// <param name="freq_"></param> /// <param name="settleDate_"></param> /// <param name="forwardDate_"></param> /// <param name="repoRateInPercent_">give 0.25 to imply a decimal of 0.0025</param> /// <param name="marketCode_"></param> /// <returns></returns> public static double GetForwardPrice ( DateTime effectiveDate_, DateTime maturityDate_, DateTime firstCouponDate_, double cleanPriceInPercent_, double couponInPercent_, CouponPaymentFrequency freq_, DateTime settleDate_, DateTime forwardDate_, double repoRateInPercent_, BondMarket market_ ) { return Symmetry.Analytics.BondAnalytics.CalcBondFwd( country: GetSymCountry(market_), settleDate: settleDate_, cleanPrice: cleanPriceInPercent_/100d, maturityDate: maturityDate_, coupon: couponInPercent_/100d, freq: freq_ == CouponPaymentFrequency.SemiAnnual ? 6 : 12, fwdDate: forwardDate_, repoRate: repoRateInPercent_/100d, startDate: effectiveDate_, firstCpnDate: firstCouponDate_)[0]*100d; //return Symmetry.Analytics.BondAnalytics.CalcBondFwd( // Country: market_.ToString(), // AsOfSettleDate: settleDate_, // CleanPrice: cleanPriceInPercent_/100d, // IssueDate: issueDate_, // MaturityDate: maturityDate_, // Coupon: couponInPercent_/100d, // Freq: freq_ == CouponPaymentFrequency.SemiAnnual ? 6 : 12, // FwdDate: forwardDate_, // repoRate: repoRateInPercent_/100d // )*100d; }
internal static List<BondStructureOTRCreator> GetItems(BondMarket[] markets_, StructureGrouping grouping_, int index_) { var list = new List<BondStructureOTRCreator>(); if (grouping_.Has(StructureGrouping.Outrights)) list.AddRange(GetOutrights(markets_,index_)); if (grouping_.Has(StructureGrouping.Curves)) list.AddRange(GetCurves(markets_, index_)); if (grouping_.Has(StructureGrouping.Butterflies)) list.AddRange(GetButterflies(markets_, index_)); if (grouping_.Has(StructureGrouping.XMarketSpreads)) list.AddRange(GetXMktSpreads(markets_, index_)); if (grouping_.Has(StructureGrouping.XMarketBoxes)) list.AddRange(GetXMktBoxes(markets_, index_)); return list; }