Hi
I try to make two things in the same time (which is, obviously, impossible since I'm a man...) *make a cashflow model *use Quantlib I would like to put every cashflow I have in my asset portfolio, during a specific period of time, in a std::list<> with the following code std::list<boost::shared_ptr<CashFlow> > Portfolio::listCashFlow(Date d, Period period){ std::list<boost::shared_ptr<CashFlow> > listCF; for (const_iterator i=components_.begin(); i!=components_.end(); ++i) { if (boost::shared_ptr<Bond> iTemp = boost::dynamic_pointer_cast<Bond> (i->first.first)){ //iTemp is now a bond => I can use the cashflow() method Leg cf = iTemp->cashflows(); for (int j = 0; j<cf.size(); j++){ if (d <= (cf[j])->date() && (cf[j])->date() <= d+period) listCF.push_back(cf[j]); } } else if (boost::shared_ptr<Swap> iTemp =boost::dynamic_pointer_cast<Swap> (i->first.first)){ //iTemp is now a swap => I can use the leg(size) method Leg cf1 = iTemp->leg(0); for (int j = 0; j<cf1.size(); j++){ if (d <= (cf1[j])->date() && (cf1[j])->date() <= d+period) listCF.push_back(cf1[j]); } Leg cf2 = iTemp->leg(1); for (int j = 0; j<cf2.size(); j++){ if (d <= (cf2[j])->date() && (cf2[j])->date() <= d+period) listCF.push_back(cf2[j]); } } else if (boost::shared_ptr<VanillaOption> iTemp =boost::dynamic_pointer_cast<VanillaOption> (i->first.first)){ //iTemp is now a VanillaOption => i can use ...??? Date exerciseDate = iTemp->exercise()->lastDate(); if (d <= exerciseDate && exerciseDate <= d+period){ boost::shared_ptr<Payoff> p = iTemp->payoff(); ///////////HERE IS THE PROBLEM//////////////////////// Real underlyingPrice = ???????????; ////////////////////////////////////////////////////// Real amount = p->operator()(underlyingPrice); boost::shared_ptr<CashFlow> cf = boost::shared_ptr<CashFlow>( new SimpleCashFlow( amount, exerciseDate)); listCF.push_back(cf); } } } return listCF; } the data member components_ is defined by typedef std::pair< std::pair<boost::shared_ptr<QuantLib::Instrument>, boost::shared_ptr<QuantLib::Instrument> >, QuantLib::Real> component; typedef std::list<component>::iterator iterator; typedef std::list<component>::const_iterator const_iterator; the pair QL::Instrument, QL::instrument is used for (marketValue, bookValue) Does a magic fonction exist at Instrument level which will give me all the cashflows of a specific instrument? For the moment, I have to use polymorphic dynamic_cast to check if the instrument provides cashflows and after i have to get those CF... It is not a nice solution :-/ The second problem I have is in the "vanillaOption" part. How to get my plainVanillaPayoff cashFlow? Because for a Call (for example), my payoff cashflow is max(0, Underlying-strike) at maturity, but I don't have information about underlying at maturity.... Did I miss smthg? Tks Regards David |
On Tue, 2009-03-03 at 03:07 -0800, dhoorens wrote:
> I would like to put every cashflow I have in my asset portfolio, during a > specific period of time, in a std::list<>. > Does a magic fonction exist at Instrument level which will give me all the > cashflows of a specific instrument? > For the moment, I have to use polymorphic dynamic_cast to check if the > instrument provides cashflows and after i have to get those CF... > It is not a nice solution :-/ No, it's not nice. But unfortunately there's no such method at this time. > The second problem I have is in the "vanillaOption" part. > How to get my plainVanillaPayoff cashFlow? > Because for a Call (for example), my payoff cashflow is max(0, > Underlying-strike) at maturity, but I don't have information about > underlying at maturity.... ...and it's hard to extract it, too. For one thing, it's not in the option itself, since the option doesn't contain directly the process for the underlying (on which its forward value depends.) You should extract the engine from the instrument, cast it to the correct type, and extract the stochastic process from it.---assuming that all the inspectors exist. Then the expected underlying value at maturity has to be calculated. It I may make a suggestion, I'd store the required data in your portfolio together with your instruments. As far as I see, your component_ member already contains other data besides the shared_ptr<Instrument>. When you create the instruments (at which point you know already what each instrument is, and you have its input data at hand) you might consider getting hold of its cashflows or its underlying process and add them to the items in component_. Luigi -- standards, n.: The principles we use to reject other people's code. ------------------------------------------------------------------------------ Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are powering Web 2.0 with engaging, cross-platform capabilities. Quickly and easily build your RIAs with Flex Builder, the Eclipse(TM)based development software that enables intelligent coding and step-through debugging. Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |