当前位置: 首页>>代码示例>>C#>>正文


C# CarbonClient.PriceSwapAsync方法代码示例

本文整理汇总了C#中CarbonClient.PriceSwapAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CarbonClient.PriceSwapAsync方法的具体用法?C# CarbonClient.PriceSwapAsync怎么用?C# CarbonClient.PriceSwapAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CarbonClient的用法示例。


在下文中一共展示了CarbonClient.PriceSwapAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: getCalcs

    protected void getCalcs()
    {
      var conf = CountryConfig.GetCountryConfig(Market);

      if (Values == null)
        Values =
          new ConstructGen<double>(
            ((ColPosition[]) Enum.GetValues(typeof (ColPosition))).Select(x => x.ToString()).ToArray());

      var crv = Singleton<CMTCurveCache>.Instance.Get(
        market_: Market,
        series_: CMTSeriesNumber,
        curve_: conf.OISCurve,
        focus_: Focus.ASW,
        createIfNotThere_: true);

      if (crv == null || crv.Data == null) return;

      // need to find the indexof of the tenor points in the data construct
      int pointIndex = -1;

      for (int i = 0; i < crv.Data.ArrayLength && (pointIndex == -1); ++i)
      {
        var asDbl = double.Parse(crv.Data.ColumnHeadings[i]);

        if (Math.Abs(asDbl - Tenor) < 1e-7)
          pointIndex = i;
      }

      var startDate = new DateTime(2010, 1, 1);


      Values.SetColumnValues((int)ColPosition.CMT_OIS, crv.Data.GetColumnValuesAsDDC(pointIndex).GetValuesBetweenDates(startDate, DateTime.Today).MultiplyBy(-100d));
      Values.SetColumnValues((int)ColPosition.GC, BbgTalk.HistoryRequester.GetHistory(startDate, conf.CollateralTicker, "PX_LAST", false));
      Values.SetColumnValues((int)ColPosition.OIS, BbgTalk.HistoryRequester.GetHistory(startDate, conf.OISTicker, "PX_LAST", false));

      Values.SortKeys();

      using (var cc = new CarbonClient("PRD"))
      {
        var fillCols = new[] { ColPosition.CMT_OIS, ColPosition.GC, ColPosition.OIS };

        for (int i = 0; i < Values.Dates.Count; ++i)
        {
          var date = Values.Dates[i];
          var vals = Values.GetValues(Values.Dates[i]);

          // fill in zeros as unlikely all series will line up
          if (i > 0)
          {
            foreach (var col in fillCols)
            {
              if (vals[(int)col].IsZero())
                vals[(int)col] = Values.GetValues(Values.Dates[i - 1])[(int)col];
            }
          }

          vals[(int)ColPosition.GCminusOIS] = vals[(int)ColPosition.GC] - vals[(int)ColPosition.OIS];


          bool needToMakeCall = true;

          {
            var currentValue = Values.GetValue(date.Date, (int) ColPosition.SwapValue);
            if (!currentValue.IsZero())
              needToMakeCall = false;
          }

          if (needToMakeCall)
          {
            Logger.Info(string.Format("Making calls for {0}.{1}.{2} carry calc on {3}",Market,Tenor,CMTSeriesNumber, date.ToString("dd-MMM-yyyy")),
              typeof(CMTCarry));


            var settleDate = cc.RollDateAsync(date.ToNodaLocalDate(), 2, Symmetry.Carbon.Model.DateUnit.Bd,
              Symmetry.Carbon.Model.BusinessDayConvention.Following, conf.HolidayCalendar).Result;

            var swapDate =
              cc.RollDateAsync(settleDate, Tenor, Symmetry.Carbon.Model.DateUnit.Y,
                Symmetry.Carbon.Model.BusinessDayConvention.Following, conf.HolidayCalendar).Result;

            var swapResult = cc.PriceSwapAsync(
              curveName: conf.OTSwapName,
              startDate: settleDate,
              endDate: swapDate,
              asof: date.Date.AddHours(23),
              pricingSetup: "Symmetry").Result;

            if (swapResult == null) continue;

            foreach (var v in swapResult.Results)
            {
              switch (v.Key)
              {
                case "BreakEven Rate":
                  vals[(int)ColPosition.SwapValue] = v.Value;
                  break;
                case "PV01":
                  vals[(int)ColPosition.SwapDuration] = v.Value;
                  break;
//.........这里部分代码省略.........
开发者ID:heimanhon,项目名称:researchwork,代码行数:101,代码来源:CMTCarry.cs

示例2: GetSpreads

    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;
    }
开发者ID:heimanhon,项目名称:researchwork,代码行数:98,代码来源:BondSpreadRetriever.cs


注:本文中的CarbonClient.PriceSwapAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。