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


C# CarbonClient.GetBondPriceFromYieldAsync方法代码示例

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


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

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