FloatingRateBond现金流检索和打印

时间:2015-06-10 15:23:43

标签: c++ floating rate coupon quantlib

我正在使用FloatingRateBond类创建浮动利率债券对象,我已经正确定价。但是,现在我需要检索现金流和脏价以分解收益率。我一直在尝试以下方面没有任何成功:

Leg cf=floatingRateBond.cashflows();
     Leg::iterator it;
     for(it=cf.begin();it!=cf.end();++it)
        cout<<"Type: "<<typeid(*it).name()<< "    value:" << *it<<endl;

输出:

Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14362a50
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14362c40
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14362e70
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x143630a0
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x143632d0
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14363500
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14363730
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14363960
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14363b90
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14363dc0
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14363ff0
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14364220
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14364450
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14364680
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x143648b0
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14364ae0
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14364d10
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14364f40
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14365170
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x143653a0
Type: N5boost10shared_ptrIN8QuantLib8CashFlowEEE    value:0x14362660

感谢

2 个答案:

答案 0 :(得分:2)

你的问题不是很清楚。您正在尝试迭代Leg,应将其定义为

typedef std::vector< boost::shared_ptr<CashFlow> > Leg; source

因此,如果it = cf.begin()*it的类型为boost::shared_ptr<CashFlow>,则会解释类型N5boost10shared_ptrIN8QuantLib8CashFlowEEE和地址0x14365170

您是否曾尝试过再次参考,以获得CashFlow?那是你的问题吗?

答案 1 :(得分:0)

我有。但是我得到同样的东西。我的同事通过不使用迭代器解决了它,只是一个简单的for循环,然后指向 - &gt; amount()

我不明白,鉴于Quantlib建立在STL和boost之上,这有什么不同。

像这样:

Leg cf=floatingRateBond.cashflows();
     for (Size j=0; j<cf.size()-1; j++) {
            if (!cf[j]->hasOccurred(settlementDate, false)) {
                Date myDate =  cf[j]->date();
                Real Amount = cf[j]->amount();
                cout << "Date is " << myDate << "  |  Amount is " << Amount << endl;


            }
        }

如果确实如此(* it) - &gt; amount();它会产生错误。