コード例 #1
0
    private static void import(SymmetryEntities dc_, AuctionInfo info_)
    {
      var cusipIdentifier = findCusipIdentifier(dc_, info_);

      if (cusipIdentifier == null) return;

      // take the opportunity to update the coupon if it's different

      if (cusipIdentifier.FI != null 
        && cusipIdentifier.FI.FIBond != null 
        && info_.Coupon.HasValue
        && Math.Abs(Convert.ToDouble(cusipIdentifier.FI.FIBond.Coupon) - info_.Coupon.Value) > 1e-3)
      {
        SLog.log.InfoFormat("Changing coupon of {0} from {1} to {2}", cusipIdentifier.Identifier,
          cusipIdentifier.FI.FIBond.Coupon, info_.Coupon);

        cusipIdentifier.FI.FIBond.Coupon = Convert.ToDecimal(info_.Coupon.Value);
        FIChangeTracking.SetModified(cusipIdentifier.FI.FIBond, dc_);
        dc_.SaveChanges();
      }


      bool found = false;

      foreach (var auction in dc_.FIBondAuctions.Where(x => x.FIID == cusipIdentifier.FIID))
      {

        if (auction.AuctionDate == info_.AuctionDate.Value)
        {
          //SLog.log.DebugFormat("Auction already set up for {0} on {1}", info_.Cusip, info_.AuctionDate.Value);

          if (!auction.EffectiveDate.HasValue)
          {
            SLog.log.InfoFormat("Updating auction effective date to {0}", info_.IssueDate.Value);
            auction.EffectiveDate = info_.IssueDate.Value;
            FIChangeTracking.SetModified(auction, dc_);
          }
          found = true;
          break;
        }
      }

      if (found)
      {
        dc_.SaveChanges();
        return;
      }

      SLog.log.InfoFormat("Setting up auction for {0} on {1}", info_.Cusip, info_.AuctionDate.Value);


      var newAuction = new FIBondAuction()
      {
        FIID = cusipIdentifier.FIID,
        FIBond = dc_.FIBonds.FirstOrDefault(x => x.FIID == cusipIdentifier.FIID),
        AuctionDate = info_.AuctionDate.Value,
        EffectiveDate = info_.IssueDate.Value,
        Term = info_.Term.Value
      };

      dc_.FIBondAuctions.Add(newAuction);
      dc_.SaveChanges();
    }
コード例 #2
0
        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;
        }
コード例 #3
0
        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;
        }
コード例 #4
0
 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;
 }
コード例 #5
0
ファイル: FIHelpers.cs プロジェクト: heimanhon/researchwork
        public static FI GetOrCreateFiViaIdentifier(string identifier, InstrumentType insttype, string currency, DateTime maturity, SymmetryEntities dc, ThrowBehavior behavior = ThrowBehavior.Throw)
        {
            if (string.IsNullOrWhiteSpace(identifier))
            {
                return null;
            }
            FIChangeTracking.DisableChangeTracking(ref dc);
            FI fi = null;
            try
            {
                // create instrument
                fi = GetFIBySymmetryCode(identifier, dc, behavior);
                if (fi == null)
                {
                    fi = new FI
                    {
                        InstrumentType = insttype,
                        Currency = currency,
                        DisplayName = identifier,
                        Maturity = maturity,
                        SymmetryCode = identifier
                    };
                    dc.FIs.Add(fi);
                }

                dc.SaveChanges();
            }
            catch (Exception ex)
            {
                Exceptions.Rethrow("GetOrCreateFiViaIdentifier", behavior, ex);
            }
            finally
            {
                FIChangeTracking.EnableChangeTracking(ref dc);
            }
            return fi;
        }