|
From: animesh s. <ani...@gm...> - 2010-08-31 12:17:57
|
I located the error in the code. I think this is probably due to design.
Generally people would like to price options using different processes.
For example Himalayan Option is priced using BlackScholes process in the
example. When I change it to another process like Merton76Process (which
also is Stochastic1D - as per the guidelines), I should be able to price
it. The error is when it delegates to casting to generalized Black
Scholes process, the following code in file mchimalayaengine.hpp.
template <class RNG, class S>
inline
boost::shared_ptr<typename MCHimalayaEngine<RNG,S>::path_pricer_type>
MCHimalayaEngine<RNG,S>::pathPricer() const {
* boost::shared_ptr<GeneralizedBlackScholesProcess> process =*
* boost::dynamic_pointer_cast<GeneralizedBlackScholesProcess>(*
*
processes_->process(0));*
QL_REQUIRE(process, "Black-Scholes process required");
return boost::shared_ptr<
typename
MCHimalayaEngine<RNG,S>::path_pricer_type>(
new HimalayaMultiPathPricer(arguments_.payoff,
process->riskFreeRate()->discount(
arguments_.exercise->lastDate())));
}
The cast is throwing the error. If I change it to *"STATIC CAST", the
error is gone!
boost::shared_ptr<GeneralizedBlackScholesProcess> process =*
* boost::static_pointer_cast<GeneralizedBlackScholesProcess>(*
*
processes_->process(0));*
The developer's might have better suggestions. Any views on this?? Is
this a design problem?
Thanks in advance.
On 8/31/10 1:57 AM, animesh saxena wrote:
> Below is the sample code for Himalayan Option valuation. It works for
> BlackScholes process but if I change it to slightly fancier
> Merton76Process (Jumps), it throws out an ugly SIG ABORT exception.
> Can anyone help me in figuring out the mistake. "Just copy paste the
> code below to test it out".
> Thanks in advance!
>
> Date today = Settings::instance().evaluationDate();
>
> DayCounter dc = Actual360();
> std::vector<Date> fixingDates;
> for (Size i=0; i<5; ++i)
> fixingDates.push_back(today+i*90);
>
> Real strike = 100.0;
> HimalayaOption option(fixingDates, strike);
>
> Handle<YieldTermStructure> riskFreeRate(flatRate(today, 0.05, dc));
>
> std::vector<boost::shared_ptr<StochasticProcess1D> > processes(4);
>
> boost::shared_ptr<SimpleQuote> spot(new SimpleQuote(100));
> boost::shared_ptr<SimpleQuote> qRate(new SimpleQuote(0.01));
> boost::shared_ptr<YieldTermStructure> qTS = flatRate(today, qRate,
> dc);
> boost::shared_ptr<SimpleQuote> rRate(new SimpleQuote(0.05));
> boost::shared_ptr<YieldTermStructure> rTS = flatRate(today, rRate,
> dc);
> boost::shared_ptr<SimpleQuote> vol(new SimpleQuote(0.20));
> boost::shared_ptr<BlackVolTermStructure> volTS = flatVol(today,
> vol, dc);
>
>
> boost::shared_ptr<SimpleQuote> jumpIntensity(new SimpleQuote(1));
> boost::shared_ptr<SimpleQuote> meanLogJump(new SimpleQuote(0.2));
> boost::shared_ptr<SimpleQuote> jumpVol(new SimpleQuote(0.2));
>
> processes[0]= boost::shared_ptr<StochasticProcess1D>(new
> Merton76Process(Handle<Quote>(spot),Handle<YieldTermStructure>(qTS),Handle<YieldTermStructure>(rTS),Handle<BlackVolTermStructure>(volTS),Handle<Quote>(jumpIntensity),Handle<Quote>(meanLogJump),Handle<Quote>(jumpVol)));
>
> processes[1]= boost::shared_ptr<StochasticProcess1D>(new
> Merton76Process(Handle<Quote>(spot),Handle<YieldTermStructure>(qTS),Handle<YieldTermStructure>(rTS),Handle<BlackVolTermStructure>(volTS),Handle<Quote>(jumpIntensity),Handle<Quote>(meanLogJump),Handle<Quote>(jumpVol)));
>
> processes[2]= boost::shared_ptr<StochasticProcess1D>(new
> Merton76Process(Handle<Quote>(spot),Handle<YieldTermStructure>(qTS),Handle<YieldTermStructure>(rTS),Handle<BlackVolTermStructure>(volTS),Handle<Quote>(jumpIntensity),Handle<Quote>(meanLogJump),Handle<Quote>(jumpVol)));
>
> processes[3]= boost::shared_ptr<StochasticProcess1D>(new
> Merton76Process(Handle<Quote>(spot),Handle<YieldTermStructure>(qTS),Handle<YieldTermStructure>(rTS),Handle<BlackVolTermStructure>(volTS),Handle<Quote>(jumpIntensity),Handle<Quote>(meanLogJump),Handle<Quote>(jumpVol)));
>
>
>
>
> Matrix correlation(4,4);
> correlation[0][1] = 0.29;
> correlation[0][2] = 0.29;
> correlation[0][3] = 0.39;
> correlation[1][0] = 0.49;
> correlation[1][2] = 0.59;
> correlation[1][3] = 0.69;
>
> correlation[2][2] = 0.19;
> correlation[2][3] = 0.29;
>
> correlation[3][0] = correlation[0][3];
> correlation[3][1] = correlation[1][3];
> correlation[3][2] = correlation[2][3];
> correlation[2][0] = correlation[0][2];
> correlation[2][1] = correlation[1][2];
> correlation[1][1] = 1.00;
>
> correlation[0][0] = 1.00;
> correlation[3][3] = 1.00;
>
>
> BigNatural seed = 42;
> int i_samples;
> i_samples = 4999;
> Size fixedSamples;
> boost::shared_ptr<StochasticProcessArray> process(new
> StochasticProcessArray(processes, correlation));
> Real value;
>
> option.setPricingEngine(MakeMCHimalayaEngine<PseudoRandom>(process).withSamples(fixedSamples).withSeed(seed));
> value = option.NPV();
>
>
>
--
Regards,
Animesh Saxena
(http://quantanalysis.wordpress.com)
Ph: (+91)9920098221
|