public static void Rethrow(string errorMessage, ThrowBehavior behavior, Exception ex) { SLog.log.Error(errorMessage, ex); if (behavior == ThrowBehavior.Throw) { throw ex; } }
public async Task <string> FetchAsync(InOutOptions options = InOutOptions.None) { if (ThrowBehavior.HasFlag(ThrowOption.ThrowOnFetch)) { throw new IOException($"Mock exception has been thrown at {this.GetType().Name}"); } await Task.Delay(Duration); return(await File.ReadAllTextAsync("../fetch.json")); }
public async Task PersistAsync(string data, InOutOptions options) { if (ThrowBehavior.HasFlag(ThrowOption.ThrowOnPersist)) { throw new IOException($"Mock exception has been thrown at {this.GetType().Name}"); } await Task.Delay(Duration); return; }
public static string GetConfigString(string configKey, ThrowBehavior behavior = ThrowBehavior.Throw) { try { return System.Configuration.ConfigurationManager.AppSettings[configKey]; } catch(Exception ex) { Exceptions.Rethrow("Error retrieving config value " + configKey, behavior, ex); } return null; }
public static void SendMessage(MailMessage msg_, ThrowBehavior behavior_ = ThrowBehavior.DontThrow) { try { GetClient().Send(msg_); } catch (Exception ex_) { Exceptions.Rethrow("Error sending email", behavior_, ex_); } }
public static FI GetFIBySymmetryCode(string symmetryCode, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw) { try { return dc.FIs.SingleOrDefault(fi => fi.SymmetryCode.Equals(symmetryCode, StringComparison.InvariantCultureIgnoreCase)); } catch (Exception ex) { Exceptions.Rethrow("GetFIBySymmetryCode", behavior, ex); } return null; }
public static bool GetConfigBool(string configKey, ThrowBehavior behavior = ThrowBehavior.Throw) { try { return (GetConfigInt(configKey, behavior) == 1); } catch (Exception ex) { Exceptions.Rethrow("Error retrieving config value " + configKey, behavior, ex); } return false; }
public static DateTime[] GetCalendar(string otCode_, CarbonClient client_, ThrowBehavior behavior_=ThrowBehavior.DontThrow) { try { return client_.GetCalendarAsync(otCode_).Result.Dates.Select(x => x.ToDateTime()).ToArray(); } catch (Exception ex_) { Exceptions.Rethrow(string.Format("Error getting calendar {0}", otCode_), behavior_, ex_); } return null; }
public static FI GetFI(int fiid, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw) { try { return dc.FIs.SingleOrDefault(f => f.FIID == fiid); } catch (Exception ex) { Exceptions.Rethrow("GetFI", behavior, ex); } return null; }
public static string[] GetFIIdentifiers(string symmetryCode, IdentifierType identifierType, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw) { try { return dc.FIIdentifiers.Where(x => x.FI.SymmetryCode.Equals(symmetryCode, StringComparison.InvariantCultureIgnoreCase) && x.IdentifierType == identifierType) .Select(x => x.Identifier).ToArray(); } catch (Exception ex_) { Exceptions.Rethrow("GetFIIdentiers", behavior, ex_); } return null; }
public static MarketSnap GetMarketSnap(string marketSnapCode, DateTime snapDate, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw) { try { return dc.MarketSnaps.SingleOrDefault(s => s.MarketSnapSchedule.MarketSnapCode.Equals(marketSnapCode, StringComparison.InvariantCultureIgnoreCase) && s.ValueDate == snapDate); } catch (Exception ex) { Exceptions.Rethrow("GetMarketSnap", behavior, ex); } return null; }
public static Moniker FromString(string moniker, ThrowBehavior behavior = ThrowBehavior.Throw) { try { if (!string.IsNullOrWhiteSpace(moniker) && moniker.Contains(sSeparator)) { string[] tokens = moniker.Trim().ToLower().Split(sSeparator); if (tokens.Length != 5) { if (behavior == ThrowBehavior.DontThrow) { return null; } throw new Exception("Unable to parse moniker " + moniker); } var newMoniker = new Moniker { Type = tokens[0].Trim(), Name = tokens[1].Trim(), Source = tokens[2].Trim(), Close = tokens[3].Trim(), Date = null }; if (!string.IsNullOrWhiteSpace(tokens[4])) { if (tokens[4] == sLatest) { newMoniker.Date = null; } else { DateTime valueDate; if (!DateTime.TryParseExact(tokens[4], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out valueDate)) { if (behavior == ThrowBehavior.DontThrow) { return null; } throw new Exception("Unable to parse date in moniker " + moniker); } newMoniker.Date = valueDate; } return newMoniker; } } } catch(Exception ex) { Exceptions.Rethrow("Error parsing moniker " + moniker, behavior, ex); } return null; }
public static string GetFIIdentifier(string symmetryCode, IdentifierType identifierType, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw) { try { var fiID = dc.FIIdentifiers.SingleOrDefault(i => i.FI.SymmetryCode.Equals(symmetryCode, StringComparison.InvariantCultureIgnoreCase) && i.IdentifierType == identifierType); return fiID==null ? null : fiID.Identifier; } catch (Exception ex) { Exceptions.Rethrow("GetFIIdentifier", behavior, ex); } return null; }
public static FI GetFutureByMaturity(string bloombergChain, DateTime maturity, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw) { try { var fi = dc.FIs.FirstOrDefault(i => ( i.InstrumentType == InstrumentType.IRFuture || i.InstrumentType == InstrumentType.BondFuture ) && i.Maturity.HasValue && i.Maturity.Value == maturity && i.SymmetryCode.StartsWith(bloombergChain)); return fi; } catch (Exception ex) { Exceptions.Rethrow("GetFutureByMaturity", behavior, ex); } return null; }
public static BondSpreadResult GetSpreads(OTBond bondType_, SwapCurveType curveType_, NodaTime.LocalDate maturity_, NodaTime.LocalDate issueDate_, NodaTime.LocalDate firstCouponDate_, QuoteValueType priceType_, double priceValue_, double coupon_, DateTime asOf_, CarbonClient client_, ThrowBehavior behavior_ = ThrowBehavior.DontThrow) { return GetSpreads( bondType_, maturity_, issueDate_, firstCouponDate_, priceType_, priceValue_, coupon_, CurveMappings.GetMapping(curveType_), asOf_, client_, behavior_); }
public static MarketSnap GetLatestMarketSnapWithValues(string marketSnapCode, DateTime latestDate, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw) { try { var snap = dc.MarketSnaps.Where(s => s.MarketSnapSchedule.MarketSnapCode.Equals(marketSnapCode, StringComparison.InvariantCultureIgnoreCase)) .Where(v => v.ValueDate <= latestDate) .OrderByDescending(v => v.ValueDate).FirstOrDefault(v=>v.Quotes.Count>0); return snap; } catch (Exception ex) { Exceptions.Rethrow("GetLatestMarketSnap", behavior, ex); } return null; }
public static BondSpreadResult GetSpreads(Symmetry.Data.FIBond bond_, QuoteValueType priceType_, double priceValue_, SwapCurveType curveType_, DateTime asOf_, CarbonClient client_, ThrowBehavior behavior_ = ThrowBehavior.DontThrow) { return GetSpreads( bondType_: OTBondHelper.GetBond(bond_), maturity_:bond_.FI.Maturity.Value.ToNodaLocalDate(), issueDate_:bond_.IssueDate.Value.ToNodaLocalDate(), firstCouponDate_: bond_.Coupon==0 ? bond_.IssueDate.Value.ToNodaLocalDate() : bond_.FirstCouponDate.Value.ToNodaLocalDate(), priceType_:priceType_, priceValue_:priceValue_, coupon_: Convert.ToDouble(bond_.Coupon)/100d, pricingSetup_: CurveMappings.GetMapping(curveType_), asOf_: asOf_, client_: client_, behavior_: behavior_); }
public static FI GetFIByIdentifier(string identifier, IdentifierType identifierType, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw) { try { var identifierEntry = dc.FIIdentifiers.SingleOrDefault(i => i.IdentifierType == identifierType && i.Identifier.Equals(identifier, StringComparison.InvariantCultureIgnoreCase)); if (identifierEntry != null) { return identifierEntry.FI; } } catch (Exception ex) { Exceptions.Rethrow("GetFIByIdentifier", behavior, ex); } return null; }
public static int GetConfigInt(string configKey, ThrowBehavior behavior = ThrowBehavior.Throw) { try { var s = GetConfigString(configKey, behavior); if(!string.IsNullOrWhiteSpace(s)) { return Int32.Parse(s); } } catch (Exception ex) { Exceptions.Rethrow("Error retrieving config value " + configKey, behavior, ex); } return 0; }
private static DateTime Roll(DateTime date_, int units_, DateUnit unit_, BusinessDayConvention convention_, string otCalendar_, CarbonClient client_, ThrowBehavior behavior_=ThrowBehavior.DontThrow) { try { string key = getKey(date_, units_, unit_, convention_, otCalendar_); if (_cache.ContainsKey(key)) return _cache[key]; var result = client_.RollDateAsync(date_.ToNodaLocalDate(), units_, unit_, convention_, otCalendar_).Result.ToDateTime(); _cache[key] = result; return result; } catch (Exception ex_) { Exceptions.Rethrow("Error rolling date", behavior_, ex_); } return DateTime.MinValue; }
public static MarketSnap GetOrCreateMarketSnap(string marketSnapCode, DateTime snapDate, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw) { try { var schedule = dc.MarketSnapSchedules.Single(s => s.MarketSnapCode.Equals(marketSnapCode)); var snap = dc.MarketSnaps.SingleOrDefault(s => s.MarketSnapSchedule.MarketSnapCode.Equals(marketSnapCode, StringComparison.InvariantCultureIgnoreCase) && s.ValueDate == snapDate); if (snap == null) { snap = new MarketSnap { ValueDate = snapDate, MarketSnapSchedule = schedule }; dc.MarketSnaps.Add(snap); } return snap; } catch (Exception ex) { Exceptions.Rethrow("GetOrCreateMarketSnap", behavior, ex); } return null; }
public static DateTime RollYears(DateTime date_, int numyears_, string otCalendar_, CarbonClient client_, ThrowBehavior behavior_ = ThrowBehavior.DontThrow) { return Roll(date_, numyears_, DateUnit.Y, BusinessDayConvention.ModFollowing, otCalendar_, client_, behavior_); }
public static DateTime[] GetCalendarFromSymCode(string symCalendarCode_,CarbonClient client_, ThrowBehavior behavior_=ThrowBehavior.DontThrow) { var otCode = CalendarMappings.GetOTfromSym(symCalendarCode_); return GetCalendar(otCode, client_, behavior_); }
/// <summary> /// Calculate the bondspreads for the given bond over the given swap curve /// </summary> /// <param name="bond_"></param> /// <param name="priceType_">either yield or price</param> /// <param name="priceValue_">if price, then pass 100.3 rather than 1.003</param> /// <param name="curveType_">the swap curve</param> /// <param name="country_">JB's country definitions</param> /// <param name="asOf_">the date of the price. will determine the date of the curves that are used</param> /// <param name="client_">carbon client to get holidays</param> /// <param name="quoteSource_">mlp/sym</param> /// <param name="snapCode_">mlp/nyk/ldn</param> /// <param name="behavior_">whether you want exceptions to be swallowed or not</param> /// <returns></returns> public static async Task<BondSpreadResult> GetSpreads( Symmetry.Data.FIBond bond_, QuoteValueType priceType_, double priceValue_, SwapCurveType curveType_, BondAnalytics.Country country_, DateTime asOf_, CarbonClient client_, string quoteSource_, string snapCode_, ThrowBehavior behavior_ = ThrowBehavior.DontThrow) { try { var mapping = CurveMappings.GetMapping(curveType_); var settleDate = await client_.RollDateAsync( date: asOf_.Date.ToNodaLocalDate(), count: country_.SettleDateDays(), unit: DateUnit.Bd, convention: BusinessDayConvention.Following, calendar: country_.OTHolidayCode()); var holidays = CalendarRetriever.GetCalendar(country_.OTHolidayCode(), client_).ToList(); var startDate = bond_.EffectiveDate.Value; var firstCpnDate = bond_.Coupon==0 ? bond_.IssueDate.Value : bond_.FirstCouponDate.Value; var maturity = bond_.FI.Maturity; var coupon = Convert.ToDouble(bond_.Coupon); // 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(mapping.DiscountCurve), Type = "discountcurve", Date = asOf_.Date }); if (discCurve == null) { SLog.log.ErrorFormat("Could not load {0} discount curve from database for {1}", mapping.DiscountCurve, asOf_.Date); return null; } var fcstCurve = SObjectManager.Instance().LoadSObject<DiscountCurve>(new Moniker() { Close = snapCode_, Source = quoteSource_, Name = KnownCurveHelpers.GetKnownCurveCode(mapping.ForecastCurve), Type = "discountcurve", Date = asOf_.Date }); if (fcstCurve == null) { SLog.log.ErrorFormat("Could not load {0} discount curve from database for {1}", mapping.ForecastCurve, asOf_.Date); return null; } double price=0, yield=0; switch (priceType_) { case QuoteValueType.Price: price = priceValue_; yield = BondAnalytics.SolveYield( country: country_, settleDate: settleDate.ToDateTime(), cleanPrice: price, startDate: startDate, firstCpnDate: firstCpnDate, maturityDate: maturity.Value, coupon: coupon, freq: country_.BondFreq())[0]; break; case QuoteValueType.Yield: yield = priceValue_; price = BondAnalytics.PriceFromYield( country: country_, settleDate: settleDate.ToDateTime(), yield: priceValue_, startDate: startDate, firstCpnDate: firstCpnDate, maturityDate: maturity.Value, coupon: coupon, freq: country_.BondFreq())[0]; break; } var mms = BondAnalytics.CalcMMS( startDate: settleDate.ToDateTime(), maturityDate: maturity.Value, dctType: mapping.DayCountType, fixedFreq: (long) mapping.FixedFreq, floatFreq: (long) mapping.FloatFreq, discCurveDates: discCurve.AsDoubleArray().SliceColumn(0).Select(DateTime.FromOADate).ToArray(), discDfs: discCurve.AsDoubleArray().SliceColumn(1), fcstCurveDates: fcstCurve.AsDoubleArray().SliceColumn(0).Select(DateTime.FromOADate).ToArray(), fcstDfs: fcstCurve.AsDoubleArray().SliceColumn(1), holidays: holidays, stubExpiries: null, stubTenors: null, stubValues: null, fixingTenors: null, fixings: null, firstCpnDate: firstCpnDate ); var truespread = BondAnalytics.SolveZSpread( country: country_, settleDate: settleDate.ToDateTime(), cleanPrice: price, startDate: startDate, firstCpnDate: firstCpnDate, maturityDate: maturity.Value, coupon: coupon, freq: country_.BondFreq(), curveDates: fcstCurve.AsDoubleArray().SliceColumn(0).Select(DateTime.FromOADate).ToArray(), dfs: fcstCurve.AsDoubleArray().SliceColumn(1), holidays: holidays); return new BondSpreadResult { Price = price, Spreads = new BondSpread { Yield=yield, MMS=mms, TrueSpread=truespread * -1d, Spread = mms-yield, } }; } catch (Exception ex_) { Exceptions.Rethrow("Error calculating bondspread", behavior_, ex_); return null; } }
public static Dictionary<IdentifierType, string> GetAllIdentifiers(FI fi, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw) { try { return dc.FIIdentifiers.Where(i => i.FIID == fi.FIID).ToList().GroupBy(i => i.IdentifierType, i => i) .ToDictionary(i => i.Key, i => i.First().Identifier); // return first id if many found } catch (Exception ex) { Exceptions.Rethrow("GetAllIdentifiers", behavior, ex); } return null; }
public static bool SaveQuote(MarketSnap snap, int sourceID, int fiid, QuoteValueType valueType, decimal value, DateTime? lastUpdated, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw, bool overwrite = true) { bool saved = false; //FIChangeTracking.DisableChangeTracking(ref dc); try { var existingQuote = dc.Quotes.SingleOrDefault(q => q.MarketSnapID == snap.MarketSnapID && q.QuoteSourceID == sourceID && q.FIID == fiid); if (existingQuote == null) { existingQuote = new Quote { LastUpdated = lastUpdated ?? DateHelpers.GetNow(), FIID = fiid, QuoteSourceID = sourceID, MarketSnap = snap, MarketSnapID = snap.MarketSnapID }; dc.Quotes.Add(existingQuote); dc.SaveChanges(); } var existingQuoteValue = dc.QuoteValues.SingleOrDefault(q => q.QuoteID == existingQuote.QuoteID && q.QuoteValueType == valueType); if (existingQuoteValue != null && overwrite) { if (existingQuoteValue.Value != value) { existingQuoteValue.Value = value; existingQuote.LastUpdated = lastUpdated ?? DateHelpers.GetNow(); //FIChangeTracking.SetModified(existingQuoteValue, dc); saved = true; } } else { dc.QuoteValues.Add(new QuoteValue { QuoteValueType = valueType, Value = value, QuoteID = existingQuote.QuoteID }); saved = true; } dc.SaveChanges(); } catch (Exception ex) { Exceptions.Rethrow("SaveQuote", behavior, ex); } finally { //FIChangeTracking.EnableChangeTracking(ref dc); } return saved; }
public static decimal? GetQuoteValue(int marketSnapID, int sourceID, int fiid, QuoteValueType valueType, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw) { try { return GetQuoteValues(marketSnapID, sourceID, fiid, dc, behavior).GetValue(valueType); } catch (Exception ex) { Exceptions.Rethrow("GetQuoteValue", behavior, ex); } return null; }
public static QuoteValues GetQuoteValues(int marketSnapID, int sourceID, int fiid, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw) { try { var existingQuote = dc.Quotes.SingleOrDefault(q => q.MarketSnapID == marketSnapID && q.QuoteSourceID == sourceID && q.FIID == fiid); if(existingQuote != null) { return new QuoteValues(existingQuote.QuoteValues.ToList()); } } catch (Exception ex) { Exceptions.Rethrow("GetQuoteValues", behavior, ex); } return new QuoteValues(); }
internal static BondSpreadResult GetSpreads( OTBond bondType_, NodaTime.LocalDate maturity_, NodaTime.LocalDate issueDate_, NodaTime.LocalDate firstCouponDate_, QuoteValueType priceType_, double priceValue_, double coupon_, CurveMappings.Mapping pricingSetup_, DateTime asOf_, CarbonClient client_, ThrowBehavior behavior_=ThrowBehavior.DontThrow ) { var ret = new BondSpreadResult(); ret.Spreads = new BondSpread(); try { SLog.log.DebugFormat( "Calling PriceBondAsync with params: baseBondID={0} issueDate={1} maturity={2} coupon={3} asOf={4} pricingSetup={5} stubDate={6} priceValue={7}, priceType_={8}", ((long) bondType_).ToString(), issueDate_, maturity_, coupon_, asOf_, pricingSetup_.OT_BondPricingSetup, firstCouponDate_, priceValue_, priceType_); switch (priceType_) { case QuoteValueType.Price: { ret.Price = priceValue_; var result = client_.PriceBondAsync( baseBondId: (long)bondType_, issueDate: issueDate_, maturityDate: maturity_, coupon: coupon_, asof: asOf_, pricingSetup: pricingSetup_.OT_BondPricingSetup, quantity: 100000d, stubDate: firstCouponDate_, price: ret.Price.Value).Result; ret.Spreads.Spread = -result.Results[ServiceConstants.KEY_ASW_YY]; ret.Spreads.TrueSpread = -result.Results[ServiceConstants.KEY_ZSpread]; ret.Spreads.Yield = result.Results[ServiceConstants.KEY_Yield]; } break; case QuoteValueType.Yield: { var result = client_.GetBondPriceFromYieldAsync( baseBondId: (long)bondType_, issueDate: issueDate_, maturityDate: maturity_, coupon: coupon_, asof: asOf_, pricingSetup: pricingSetup_.OT_BondPricingSetup, quantity: 100000d, yield: priceValue_, stubDate: firstCouponDate_).Result; ret.Price = result.Results[ServiceConstants.KEY_Price]; ret.Spreads.Spread = -result.Results[ServiceConstants.KEY_ASW_YY]; ret.Spreads.TrueSpread = -result.Results[ServiceConstants.KEY_ZSpread]; ret.Spreads.Yield = priceValue_; } break; default: SLog.log.ErrorFormat("Cannot call Carbon to get spreads with priceType {0}", priceType_); break; } SLog.log.DebugFormat( "Calling PriceSwapAsync with params: curveName={0} startDate={1} endDate={2} asOf={3} pricingSetup={4}", pricingSetup_.OT_Swap, issueDate_, maturity_, asOf_, pricingSetup_.OT_BondPricingSetup); var mmsResult = client_.PriceSwapAsync( curveName: pricingSetup_.OT_Swap, startDate: asOf_.ToNodaLocalDate(), endDate: maturity_, asof: asOf_, pricingSetup: pricingSetup_.OT_BondPricingSetup).Result; ret.Spreads.MMS = mmsResult.Results[ServiceConstants.KEY_MMS]; SLog.log.DebugFormat("Result: y={0} m={1} s={2} t={3}", ret.Spreads.Yield, ret.Spreads.MMS, ret.Spreads.Spread, ret.Spreads.TrueSpread); postProcess(bondType_, ret.Spreads, pricingSetup_); } catch (Exception ex_) { Exceptions.Rethrow("GetCurves", behavior_, ex_); } return ret; }
public static QuoteSource GetQuoteSource(string quoteSourceCode, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw) { try { return dc.QuoteSources.SingleOrDefault(s => s.QuoteSourceCode.Equals(quoteSourceCode, StringComparison.InvariantCultureIgnoreCase)); } catch (Exception ex) { Exceptions.Rethrow("GetQuoteSource", behavior, ex); } return null; }
public static QuoteSource GetOrCreateQuoteSource(string quoteSourceCode, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw) { try { var existingSource = GetQuoteSource(quoteSourceCode, dc, ThrowBehavior.DontThrow); if(existingSource == null) { var newSource = new QuoteSource { QuoteSourceCode = quoteSourceCode, DisplayName = quoteSourceCode, QuoteSourceType = 0 }; dc.QuoteSources.Add(newSource); dc.SaveChanges(); return newSource; } else { return existingSource; } } catch (Exception ex) { Exceptions.Rethrow("GetOrCreateQuoteSource", behavior, ex); } return null; }
public static FI GetOrCreateMLPBond(MLPBondInstrument instrument, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw) { if(string.IsNullOrWhiteSpace(instrument.ISIN)) { return null; } FIChangeTracking.DisableChangeTracking(ref dc); FI fi = null; try { // create instrument fi = FIHelpers.GetFIBySymmetryCode(instrument.ISIN, dc, behavior); if (fi == null) { fi = new FI { InstrumentType = InstrumentType.Bond, Currency = null, DisplayName = instrument.MlpTicker, Maturity = DateTime.FromOADate(instrument.Maturity), SymmetryCode = instrument.ISIN }; dc.FIs.Add(fi); } else { var newCcy = GetBondCurrencyForBbTicker(instrument.BbTicker); if (!string.IsNullOrEmpty(newCcy) && fi.Currency != newCcy) { fi.Currency = newCcy; FIChangeTracking.SetModified(fi, dc); } } dc.SaveChanges(); // set identifiers SetOrUpdateIdentifier(fi, IdentifierType.ISIN, instrument.ISIN, dc); SetOrUpdateIdentifier(fi, IdentifierType.CUSIP, instrument.CUSIP, dc); SetOrUpdateIdentifier(fi, IdentifierType.MLPCode, instrument.MlpTicker, dc); SetOrUpdateIdentifier(fi, IdentifierType.RIC, instrument.RIC, dc); SetOrUpdateIdentifier(fi, IdentifierType.Bloomberg, instrument.ISIN + " Govt", dc); dc.SaveChanges(); // create bond var fiBond = dc.FIBonds.SingleOrDefault(b => b.FIID == fi.FIID); if (fiBond == null) { fiBond = new FIBond { FIID = fi.FIID, Market = instrument.GetMarket(), Coupon = instrument.Coupon.HasValue ? instrument.Coupon.Value : 0, EffectiveDate = DateTime.FromOADate(instrument.EffectiveDate), FirstCouponDate = DateTime.FromOADate(instrument.FirstCouponDate), IssueDate = DateTime.FromOADate(instrument.IssueDate), Series = instrument.Series, Term = instrument.Term }; dc.FIBonds.Add(fiBond); } else { var coupon = instrument.Coupon.HasValue ? instrument.Coupon.Value : 0; var effectiveDate = DateTime.FromOADate(instrument.EffectiveDate); var firstCouponDate = DateTime.FromOADate(instrument.FirstCouponDate); var issueDate = DateTime.FromOADate(instrument.IssueDate); if (fiBond.Market != instrument.GetMarket() || fiBond.Coupon != coupon || fiBond.EffectiveDate != effectiveDate || fiBond.FirstCouponDate != firstCouponDate || fiBond.IssueDate != issueDate || fiBond.Series != instrument.Series || fiBond.Term != instrument.Term) { fiBond.Market = instrument.GetMarket(); fiBond.Coupon = coupon; fiBond.EffectiveDate = effectiveDate; fiBond.FirstCouponDate = firstCouponDate; fiBond.IssueDate = issueDate; fiBond.Series = instrument.Series; fiBond.Term = instrument.Term; FIChangeTracking.SetModified(fiBond, dc); } } dc.SaveChanges(); } catch (Exception ex) { Exceptions.Rethrow("GetOrCreateMLPBond", behavior, ex); } finally { FIChangeTracking.EnableChangeTracking(ref dc); } return fi; }