예제 #1
0
    public static List<CTDLine<Bond>> Go(CashBondRolling cashBondRollOption_=CashBondRolling.Monthly, bool doSerialize_=true)
    {
      string diskPath = string.Format(@"{0}\Bonds_Roll{1}", DiskCacheHelper.PATH_CTD, cashBondRollOption_);

      if (DiskCacheHelper.OnlyReadFromCache)
      {
        return Singleton<DiscCache>.Instance.ReadFromGivenFilePath<List<CTDLine<Bond>>>(diskPath, true);
      }

      var startDate = new DateTime(2012, 01, 01);

      var bondsList = new List<CTDLine<Bond>>();

      var bonds2 = Singleton<Bonds>.Instance.Where(x => x.SymmetryCode.StartsWith("US9128") && x.Term.HasValue && x.Term.Value == 2 && x.IsFloater==false && x.IsInflationLinked==false);
      var bonds3 = Singleton<Bonds>.Instance.Where(x => x.SymmetryCode.StartsWith("US9128") && x.Term.HasValue && x.Term.Value == 3 && x.IsFloater == false && x.IsInflationLinked == false);
      var bonds5 = Singleton<Bonds>.Instance.Where(x => x.SymmetryCode.StartsWith("US9128") && x.Term.HasValue && x.Term.Value == 5 && x.IsFloater == false && x.IsInflationLinked == false);
      var bonds7 = Singleton<Bonds>.Instance.Where(x => x.SymmetryCode.StartsWith("US9128") && x.Term.HasValue && x.Term.Value == 7 && x.IsFloater == false && x.IsInflationLinked == false);
      var bonds10 = Singleton<Bonds>.Instance.Where(x => x.SymmetryCode.StartsWith("US9128") && x.Term.HasValue && x.Term.Value == 10 && x.IsFloater == false && x.IsInflationLinked == false);
      var bonds30 = Singleton<Bonds>.Instance.Where(x => x.SymmetryCode.StartsWith("US9128") && x.Term.HasValue && x.Term.Value == 30 && x.IsFloater == false && x.IsInflationLinked == false);

      while (startDate < DateTime.Today)
      {
        Logger.InfoFormat(typeof(Generator), "processing ct/ctd on startdate {0}", startDate);
        var item = new CTDLine<Bond>(startDate);

        //var prevDate = startDate.AddMonths(-1);
        //var pervprevDate = startDate.AddMonths(-2);
        //var refundingM = startDate.AddMonths(-3);
        //var prevrefundingM = startDate.AddMonths(-6);

        {
          var cashBondOption = cashBondRollOption_ == CashBondRolling.Monthly
            ? item.CashBondMonth
            : item.RefundingMonth;

          var cashBondPriorOption = cashBondRollOption_ == CashBondRolling.Monthly
            ? item.CashBondPriorMonth
            : item.PrevRefundingMonth;

          var cashBondPriorPriorOption = cashBondRollOption_ == CashBondRolling.Monthly
            ? item.CashBondPriorPriorMonth
            : item.PrevPrevRefundingMonth;


          {
            // override for Oct 2015 - special case of an auction reissue
            item.CT2 = findBond(bonds2, cashBondOption, 2, startDate, 0);
            item.PrevCT2 = findBond(bonds2, cashBondPriorOption, 2, startDate, 1);
            item.PrevPrevCT2 = findBond(bonds2, cashBondPriorPriorOption, 2, startDate, 2);
            item.OOOCT2 = findBond(bonds2, cashBondPriorPriorOption, 2, startDate, 3);
            item.OOOOCT2 = findBond(bonds2, cashBondPriorPriorOption, 2, startDate, 4);

            if (item.CT2 == null) item.CT2 = findBond(bonds5, cashBondOption, 2, startDate, 0);
            if (item.PrevCT2 == null) item.PrevCT2 = findBond(bonds5, cashBondPriorOption, 2, startDate, 1);
            if (item.PrevPrevCT2 == null) item.PrevPrevCT2 = findBond(bonds5, cashBondPriorPriorOption, 2, startDate, 2);
          }

          {
              item.CT3 = findBond(bonds3, cashBondOption, 3, startDate, 0);
              item.PrevCT3 = findBond(bonds3, cashBondPriorOption, 3, startDate, 1);
              item.PrevPrevCT3 = findBond(bonds3, cashBondPriorPriorOption, 3, startDate, 2);
              item.OOOCT3 = findBond(bonds3, cashBondPriorPriorOption, 3, startDate, 3);
              item.OOOOCT3 = findBond(bonds3, cashBondPriorPriorOption, 3, startDate, 4);

              if (item.CT3 == null) item.CT3 = findBond(bonds5, cashBondOption, 3, startDate, 0);
              if (item.PrevCT3 == null) item.PrevCT3 = findBond(bonds5, cashBondPriorOption, 3, startDate, 1);
              if (item.PrevPrevCT3 == null) item.PrevPrevCT3 = findBond(bonds5, cashBondPriorPriorOption, 3, startDate, 2);
          }

          {
              item.CT5 = findBond(bonds5, cashBondOption, 5, startDate, 0);
              item.PrevCT5 = findBond(bonds5, cashBondPriorOption, 5, startDate, 1);
              item.PrevPrevCT5 = findBond(bonds5, cashBondPriorPriorOption, 5, startDate, 2);
              item.OOOCT5 = findBond(bonds5, cashBondPriorPriorOption, 5, startDate, 3);
              item.OOOOCT5 = findBond(bonds5, cashBondPriorPriorOption, 5, startDate, 4);

              if (item.CT5 == null) item.CT5 = findBond(bonds7, cashBondOption, 5, startDate, 0);
              if (item.PrevCT5 == null) item.PrevCT5 = findBond(bonds7, cashBondPriorOption, 5, startDate, 1);
              if (item.PrevPrevCT5 == null) item.PrevPrevCT5 = findBond(bonds7, cashBondPriorPriorOption, 5, startDate, 2);
          }

          item.CT7 = findBond(bonds7, cashBondOption, 7, startDate, 0);
          item.PrevCT7 = findBond(bonds7, cashBondPriorOption, 7, startDate, 1);
          item.PrevPrevCT7 = findBond(bonds7, cashBondPriorPriorOption, 7, startDate, 2);
          item.OOOCT7 = findBond(bonds7, cashBondPriorPriorOption, 7, startDate, 3);
          item.OOOOCT7 = findBond(bonds7, cashBondPriorPriorOption, 7, startDate, 4);
        }

        item.CT10 = findBond(bonds10, item.RefundingMonth, 10, startDate, 0);
        item.PrevCT10 = findBond(bonds10, item.PrevRefundingMonth, 10, startDate, 1);
        item.PrevPrevCT10 = findBond(bonds10, item.PrevPrevRefundingMonth, 10, startDate, 2);
        item.OOOCT10 = findBond(bonds10, item.PrevPrevRefundingMonth, 10, startDate, 3);
        item.OOOOCT10 = findBond(bonds10, item.PrevPrevRefundingMonth, 10, startDate, 4);

        item.CT30 = findBond(bonds30, item.RefundingMonth, 30, startDate, 0);
        item.PrevCT30 = findBond(bonds30, item.PrevRefundingMonth, 30, startDate, 1);
        item.PrevPrevCT30 = findBond(bonds30, item.PrevPrevRefundingMonth, 30, startDate, 2);
        item.OOOCT30 = findBond(bonds30, item.PrevPrevRefundingMonth, 30, startDate, 3);
        item.OOOOCT30 = findBond(bonds30, item.PrevPrevRefundingMonth, 30, startDate, 4);

        item.TU = FutureBondLookup.GetBondForFuture("TU", item.Contract);
        item.PrevTU = FutureBondLookup.GetBondForFuture("TU", item.PrevContract);
        item.PrevPrevTU = FutureBondLookup.GetBondForFuture("TU", item.PrevPrevContract);

        item.FV = FutureBondLookup.GetBondForFuture("FV", item.Contract);
        item.PrevFV = FutureBondLookup.GetBondForFuture("FV", item.PrevContract);
        item.PrevPrevFV = FutureBondLookup.GetBondForFuture("FV", item.PrevPrevContract);

        item.TY = FutureBondLookup.GetBondForFuture("TY", item.Contract);
        item.PrevTY = FutureBondLookup.GetBondForFuture("TY", item.PrevContract);
        item.PrevPrevTY = FutureBondLookup.GetBondForFuture("TY", item.PrevPrevContract);

        item.US = FutureBondLookup.GetBondForFuture("US", item.Contract);
        item.PrevUS = FutureBondLookup.GetBondForFuture("US", item.PrevContract);
        item.PrevPrevUS = FutureBondLookup.GetBondForFuture("US", item.PrevPrevContract);

        item.WN = FutureBondLookup.GetBondForFuture("WN", item.Contract);
        item.PrevWN = FutureBondLookup.GetBondForFuture("WN", item.PrevContract);
        item.PrevPrevWN = FutureBondLookup.GetBondForFuture("WN", item.PrevPrevContract);

        bondsList.Add(item);
        startDate = MyCalendar.NextWeekDay(startDate);
      }

      if(doSerialize_)
        Singleton<DiscCache>.Instance.WriteToGivenFilePath(diskPath, bondsList);

      return bondsList;
    }
예제 #2
0
    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;
    }