Ejemplo n.º 1
0
 public void Dispose()
 {
   innerDispose();
   m_bond = null;
   m_context = null;
   m_measures = null;
 }
Ejemplo n.º 2
0
 protected BondMeasureCalcBase(Bond bond_, AsOfAndSpotSettle dateContext_, DateTime settleDate_, BondMeasures updateThis_)
 {
   m_measures = updateThis_;
   m_bond = bond_;
   m_context = dateContext_;
   SettleDate = settleDate_;
 }
    public BondMeasureCalcPriceYield(Bond bond_, AsOfAndSpotSettle context_, DateTime settleDate_, BondMeasures measures_)
      : base (bond_, context_, settleDate_, measures_)
    {
      m_measuresDisp = measures_.Subscribe(handleUpdate);

      {
        var px = measures_.GetValue(BondMeasure.Price);
        if (px.HasValue)
          handleUpdate(Tuple.Create(BondMeasure.Price, px.Value));
      }
    }
    public BondMeasureCalcFwdPriceYield(Bond bond_, AsOfAndSpotSettle dateContext_,  DateTime settlDate_, BondMeasures spotMeasures_, BondMeasures measures_)
      : base(bond_, dateContext_, settlDate_,measures_)
    {

      m_spotMeasureDisp = spotMeasures_.Subscribe(handleSpotMeasureUpdated);

      {
        var px = spotMeasures_.GetValue(BondMeasure.Price);
        if (px.HasValue)
          handleSpotMeasureUpdated(Tuple.Create(BondMeasure.Price, px.Value));
      }

    }
Ejemplo n.º 5
0
    public static double CalcYield(Bond bond_, DateTime settleDate_, double px_)
    {
      var result = BondAnalytics.SolveYield(
        country: bond_.OwningMarket.Market.Country(),
        settleDate: settleDate_,
        cleanPrice: px_,
        startDate: bond_.EffectiveDate,
        firstCpnDate: bond_.FirstCouponDate,
        maturityDate: bond_.Maturity,
        coupon: bond_.Coupon,
        freq: bond_.OwningMarket.Market.CpnFreq());

      return result[0];
    }
Ejemplo n.º 6
0
 public static double CalcZSpread(Bond bond_, DateTime settleDate_, Tuple<DateTime[], double[]> crv, double px_)
 {
   return BondAnalytics.SolveZSpread(
     country: bond_.OwningMarket.Market.Country(),
     settleDate: settleDate_,
     cleanPrice: px_,
     startDate: bond_.EffectiveDate,
     firstCpnDate: bond_.FirstCouponDate,
     maturityDate: bond_.Maturity,
     coupon: bond_.Coupon,
     freq: bond_.OwningMarket.Market.CpnFreq(),
     curveDates: crv.Item1,
     dfs: crv.Item2,
     holidays: null);
 }
    private BondMeasureCalcSpreadsOverCurve(
      Bond bond_, 
      SwapCurve swapcurve_, 
      AsOfAndSpotSettle dateContext_, 
      DateTime settleDate_,
      BondMeasures updateThis_, 
      BondMeasures listenToThis_
      ) : base(bond_,dateContext_,settleDate_,updateThis_)
    {
      SwapCurve = swapcurve_;

      m_listenToThisDisp = listenToThis_.Subscribe(listenToUpdated);
      m_myMeasuresDisp = updateThis_.Subscribe(myMeasuresUpdated);

    }
Ejemplo n.º 8
0
    public static double CalcFwdPrice(Bond bond_, DateTime settleDate_, DateTime fwdDate_, double spotPrice_, double repoRate = 0d)
    {
      var result = BondAnalytics.CalcBondFwd(
        country: bond_.OwningMarket.Market.Country(),
        settleDate: settleDate_,
        cleanPrice: spotPrice_,
        firstCpnDate: bond_.FirstCouponDate,
        maturityDate: bond_.Maturity,
        coupon: bond_.Coupon,
        freq: bond_.OwningMarket.Market.CpnFreq(),
        fwdDate: fwdDate_,
        repoRate: repoRate,
        startDate: bond_.EffectiveDate);

      return result[0];
    }
Ejemplo n.º 9
0
    public static double CalcMMS(Bond bond_, SwapCurve swapCurve_, DateTime settleDate_, Tuple<DateTime[], double[]> fcs, Tuple<DateTime[], double[]> dis)
    {
      var conv = swapCurve_.GetConventions();

      return BondAnalytics.CalcMMS(
        startDate: settleDate_,
        maturityDate: bond_.Maturity,
        dctType: conv.DayCount,
        fixedFreq: conv.FixedFreq,
        floatFreq: conv.FloatFreq,
        discCurveDates: dis.Item1,
        discDfs: dis.Item2,
        fcstCurveDates: fcs.Item1,
        fcstDfs: fcs.Item2,
        holidays: null,
        stubExpiries: null,
        stubTenors: null,
        stubValues: null,
        fixingTenors: null,
        fixings: null,
        firstCpnDate: bond_.FirstCouponDate,
        blendIndex: 0);
    }
Ejemplo n.º 10
0
    private async Task populate(CarbonClient cc_)
    {
      await populateDates(cc_);
      // at the moment, carbon can't give me the list of cmt bonds for 'today' so need to get as of yesterday

      var bonds =
        await
          cc_.GetTimeSeriesAsync(Market.CarbonName(), "cmt-bonds", Yesterday.AsOf);

      //var blah =
      //  await cc_.GetTimeSeriesAsync("US7YT=TWEB", "Snap", null, null, new TimeSeriesOptions {IdentifierType = "RIC"});

      if (!bonds.Any())
      {
        Logger.Error(
          string.Format("Did not get any response from carbon asking for cmt-bonds for market {0}", Market.CarbonName()),
          typeof (BondMarket));
        return;
      }

      MessagePackObject mpo;

      if (bonds[0].Series[0].TryGetValue("cmtBonds", out mpo) == false || !mpo.IsList)
        return;


      var bondDict = new Dictionary<string, Bond>();

      foreach (var v in mpo.AsList())
      {
        var dict = v.AsDictionary();

        var bond = new Bond
        {
          OwningMarket = this,
        };

        foreach (var key in dict.Keys)
        {
          switch (key.AsString())
          {
            case "isin":
              bond.Isin = dict[key].AsString();
              break;
            case "term":
              bond.Term = dict[key].AsDouble();
              break;
            case "aswyylambda":
              bond.ASWyyLambda = dict[key].AsDouble();
              break;
            case "yieldlamda":
              bond.YieldLambda = dict[key].AsDouble();
              break;
            case "zspreadlambda":
              bond.ZSpreadLambda = dict[key].AsDouble();
              break;
          }
        }

        if (!string.IsNullOrEmpty(bond.Isin))
        {
          bondDict[bond.Isin] = bond;
        }
      }

      m_bonds = bondDict;

      // need to get some more static data about the bonds

      var dateSetups = new[]
      {
        new Tuple<string, Action<Bond, DateTime>>("maturityDt", (bs, date) => bs.Maturity = date),
        new Tuple<string, Action<Bond, DateTime>>("issueDt", (bs, date) => bs.IssueDate= date),
        new Tuple<string, Action<Bond, DateTime>>("firstCpnDt", (bs, date) => bs.FirstCouponDate= date),
        new Tuple<string, Action<Bond, DateTime>>("effectiveDt", (bs, date) => bs.EffectiveDate= date),
      };

      var dblSetups = new[]
      {
        new Tuple<string, Action<Bond, double>>("cpnRate", (bs, dbl) => bs.Coupon = dbl),
      };

      var statics = await cc_.GetStaticDataAsync(m_bonds.Keys, "static-bond");

      foreach (var s in statics)
      {
        var isin = s.Identifier;

        Bond bs;
        if (m_bonds.TryGetValue(isin, out bs) == false)
          continue;

        DateTime dt;

        foreach (var setup in dateSetups)
        {
          var strVal = s.Properties.GetString(setup.Item1);
          if (DateTime.TryParseExact(strVal, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
            setup.Item2(bs, dt);
        }

        foreach (var setup in dblSetups)
        {
          var dblVal = s.Properties.GetDouble(setup.Item1);
          if (dblVal.HasValue)
            setup.Item2(bs, dblVal.Value);
        }
      }

      var histPrices =
        await cc_.GetTimeSeriesAsync(m_bonds.Keys, Market.CarbonCloseSnapCollection(), DateTime.Today.AddMonths(-2));

      foreach (var v in histPrices.Where(x=>x.Series!=null))
      {
        var isin = v.Identifier;

        Bond bs;
        if (m_bonds.TryGetValue(isin, out bs) == false)
          continue;

        var px = new SortedDictionary<DateTime, double>();

        foreach (var obj in v.Series.Where(x=>x.ContainsKey("close") && x.ContainsKey("date")))
        {
          var strVal = obj.GetString("date");
          DateTime dt;
          double? dblVal;

          if (DateTime.TryParseExact(strVal, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)
            && (dblVal = obj.GetDouble("close")).HasValue)
            px[dt] = dblVal.Value;
        }

        if (px.Count > 0)
          bs.HistoricPrices = new DatedDataCollectionGen<double>(px.Keys.ToArray(), px.Values.ToArray());


        Logger.Debug(v.Series.ToString(), typeof (BondMarket));
      }


      m_priceSub = cc_.SubscribeToMarketData(m_bonds.Keys.ToList(),handlePriceCallback);
    }
Ejemplo n.º 11
0
    public static double CalcZSpread(Bond bond_, DateTime settleDate_, IRCurveImpl forecastCurve_, double px_)
    {
      var crv = forecastCurve_.GetValues();

      return CalcZSpread(bond_, settleDate_, crv, px_);
    }
Ejemplo n.º 12
0
 public static double CalcMMS(Bond bond_, SwapCurve swapCurve_, DateTime settleDate_, IRCurveImpl forecastCurve_, IRCurveImpl discountCurve_)
 {
   return CalcMMS(bond_, swapCurve_, settleDate_, forecastCurve_.GetValues(), discountCurve_.GetValues());
 }
    public static async Task<BondMeasureCalcSpreadsOverCurve> Create(
            Bond bond_,
      SwapCurve swapcurve_,
      AsOfAndSpotSettle dateContext_,
      DateTime settleDate_,
      BondMeasures updateThis_,
      BondMeasures listenToThis_,
      CarbonClient cc_
)
    {
      var impl = new BondMeasureCalcSpreadsOverCurve(bond_, swapcurve_, dateContext_, settleDate_, updateThis_,
        listenToThis_);

      await impl.initiate(cc_,listenToThis_);

      return impl;
    }