FloatingRateBond cashflow retrieval and printing

229 views Asked by At

I am using the FloatingRateBond class to create a floating rate bond object, which I have already priced correctly. However, now I need to retrieve the cashflows and the dirty price to decompose the yield. I have been trying the following without any success:

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

Output:

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

thanks

2

There are 2 answers

2
Lucas Triana On

I have. however I get the same thing. My collegue solved it by not using an iterator but just a simple for loop and then pointing to the ->amount()

I don't understand however how is this different given that quantlib is built upon STL and boost.

like so:

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;


            }
        }

If it did (*it)->amount(); it would yield an error.

0
MisterC On

Your question is not really clear. You're trying to iterate Leg, which should be defined as

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

So if it = cf.begin(), than *it is of type boost::shared_ptr<CashFlow>, which would explain the type N5boost10shared_ptrIN8QuantLib8CashFlowEEE and the address 0x14365170.

Have you tried to de-referece one more time, to get CashFlow? Was that your problem?