Exemplo n.º 1
0
 public SolveYtm(Cashflow[] cashflows,
                 IDayCount dayCount,
                 Frequency frequency,
                 Date startDate,
                 Date valueDate,
                 double fullPrice,
                 TradingMarket tradeingMarket,
                 bool irregularPayment,
                 IBondYieldPricer bondYieldPricer = null)
 {
     _cashflows        = cashflows;
     _dayCount         = dayCount;
     _frequency        = frequency;
     _startDate        = startDate;
     _valueDate        = valueDate;
     _fullPrice        = fullPrice;
     _tradeingMarket   = tradeingMarket;
     _irregularPayment = irregularPayment;
     _bondYieldPricer  = bondYieldPricer ?? new BondYieldPricer();
 }
Exemplo n.º 2
0
        public static double GetModifiedDuration(Cashflow[] cashflows,
                                                 IDayCount dayCount,
                                                 Frequency frequency,
                                                 Date startDate,
                                                 Date valueDate,
                                                 double yield,
                                                 TradingMarket tradeingMarket,
                                                 bool irregularPayment            = false,
                                                 IBondYieldPricer bondYieldPricer = null)
        {
            const double dy = 1e-4;

            if (bondYieldPricer == null)
            {
                bondYieldPricer = new BondYieldPricer();
            }
            var priceUp   = bondYieldPricer.FullPriceFromYield(cashflows, dayCount, frequency, startDate, valueDate, yield - dy, tradeingMarket, irregularPayment);
            var priceDown = bondYieldPricer.FullPriceFromYield(cashflows, dayCount, frequency, startDate, valueDate, yield + dy, tradeingMarket, irregularPayment);

            return((priceUp - priceDown) / dy / (priceDown + priceUp));
        }
Exemplo n.º 3
0
 public BondEngineCn(IBondYieldPricer bondYieldPricer = null)
 {
     _bondYieldPricer = bondYieldPricer ?? new BondYieldPricer();
     _bondEngine      = new BondEngine(_bondYieldPricer);
 }
Exemplo n.º 4
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="bondYieldPricer">债券收益率计算器</param>
 public BondEngine(IBondYieldPricer bondYieldPricer = null)
 {
     _bondYieldPricer = bondYieldPricer ?? new BondYieldPricerCn();
 }