« Return to Thread: Manto carlo: MCEuropeanEngine

Re: Manto carlo: MCEuropeanEngine

by Kim Kuen Tang :: Rate this Message:

Reply to Author | View in Thread

Hi Risco,

Risco Mutelo schrieb:

> hi Kim,
>
> I included the two template parameters as
> boost::shared_ptr<PathPricer<Path> > myPathPricer(
>                 new MCEuropeanEngine<PseudoRandom, Statistics>
> myMCEuropeanEngine(
>                 const diffusion, timeSteps, timeStepsPerYear,
> brownianBridge,
>                antitheticVariate, controlVariate, requiredSamples,
> requiredTolerance, maxSamples, seed));
>
> but now i get a different error:
> "
> myMC.cpp: In function ‘int main()’:
> myMC.cpp:70: error: no matching function for call to
> ‘QuantLib::MCEuropeanEngine<QuantLib::GenericPseudoRandom<QuantLib::MersenneTwisterUniformRng,
> QuantLib::InverseCumulativeNormal>,
> QuantLib::GenericRiskStatistics<QuantLib::GenericGaussianStatistics<QuantLib::GeneralStatistics>
> > >::MCEuropeanEngine()’
> /home/Risco/Cxx/Quant/QuantLib/include/ql/pricingengines/vanilla/mceuropeanengine.hpp:122:
> note: candidates are: QuantLib::MCEuropeanEngine<RNG,
> S>::MCEuropeanEngine(const
> boost::shared_ptr<QuantLib::GeneralizedBlackScholesProcess>&,
> QuantLib::Size, QuantLib::Size, bool, bool, bool, QuantLib::Size,
> QuantLib::Real, QuantLib::Size, QuantLib::BigNatural) [with RNG =
> QuantLib::GenericPseudoRandom<QuantLib::MersenneTwisterUniformRng,
> QuantLib::InverseCumulativeNormal>, S =
> QuantLib::GenericRiskStatistics<QuantLib::GenericGaussianStatistics<QuantLib::GeneralStatistics>
> >]
> /home/Risco/Cxx/Quant/QuantLib/include/ql/pricingengines/vanilla/mceuropeanengine.hpp:43:
> note:                
> QuantLib::MCEuropeanEngine<QuantLib::GenericPseudoRandom<QuantLib::MersenneTwisterUniformRng,
> QuantLib::InverseCumulativeNormal>,
> QuantLib::GenericRiskStatistics<QuantLib::GenericGaussianStatistics<QuantLib::GeneralStatistics>
> > >::MCEuropeanEngine(const
> QuantLib::MCEuropeanEngine<QuantLib::GenericPseudoRandom<QuantLib::MersenneTwisterUniformRng,
> QuantLib::InverseCumulativeNormal>,
> QuantLib::GenericRiskStatistics<QuantLib::GenericGaussianStatistics<QuantLib::GeneralStatistics>
> > >&)
>
> "
> which does not make sense to me bcos it seems to suggest that am
> trying to instantiate MCEuropeanEngine() with a default constructor,
> which is not what I am doing.
the correct call of the constructor is the following:

boost::shared_ptr<MCEuropeanEngine<PseudoRandom,Statistics> >
myPathPricer(new MCEuropeanEngine<PseudoRandom, Statistics>(diffusion,
timeSteps, timeStepsPerYear,
             brownianBridge, antitheticVariate, controlVariate,
             requiredSamples, requiredTolerance, maxSamples, seed));

But this wont compile too, since diffusion do not have the correct type.
Change the type from diffusion into  
boost::shared_ptr<GeneralizedBlackScholesProcess>, then the code will
compile.

Best regards,
Kim
> I will be grateful for any feedback.
>
> Cheers
>
>
#include <ql/quantlib.hpp>
#include <boost/timer.hpp>
#include <iostream>
#include <iomanip>

using namespace QuantLib;

int main()
{

    try{
        Calendar calendar = TARGET();
        Date today = Date::todaysDate();
        DayCounter dayCount = Actual365Fixed();
        Rate r_ = 0.05;
        Real s0_ = 0.10;
        Volatility sigma_ = 0.20;
        Size nTimeSteps = 1;
        Time maturity_ = 1.0/12.0;

        Size timeSteps = 1;
        Size timeStepsPerYear = 1000;
        bool antitheticVariate = false;
        bool controlVariate = false;
        Size requiredSamples = 1000;
        Real requiredTolerance = 0.001;
        Size maxSamples = 1000;
        BigNatural seed = 42;

    // calculate Input parameters from the BlackScholesMertonProcess
        Handle<Quote> stateVariable(
                              boost::shared_ptr<Quote>(new
SimpleQuote(s0_)));
        Handle<YieldTermStructure> riskFreeRate(
                              boost::shared_ptr<YieldTermStructure>(
                                          new FlatForward(today, r_,
dayCount)));
        Handle<YieldTermStructure> dividendYield(
                              boost::shared_ptr<YieldTermStructure>(
                                          new FlatForward(today, 0.0,
dayCount)));
        Handle<BlackVolTermStructure> volatility(
                              boost::shared_ptr<BlackVolTermStructure>(
                                   new BlackConstantVol(today, calendar,
sigma_, dayCount)));
    boost::shared_ptr<GeneralizedBlackScholesProcess> diffusion(
                       new BlackScholesMertonProcess(stateVariable,
dividendYield,
                                                     riskFreeRate,
volatility));

        PseudoRandom::rsg_type rsg =
            PseudoRandom::make_sequence_generator(nTimeSteps, 0);

        bool brownianBridge = false;

        typedef SingleVariate<PseudoRandom>::path_generator_type
generator_type;
        boost::shared_ptr<generator_type> myPathGenerator(new
            generator_type(diffusion, maturity_, nTimeSteps,
                           rsg, brownianBridge));

    boost::shared_ptr<MCEuropeanEngine<PseudoRandom,Statistics> >
myPathPricer(new MCEuropeanEngine<PseudoRandom,        
Statistics>(diffusion, timeSteps, timeStepsPerYear,
             brownianBridge, antitheticVariate, controlVariate,
             requiredSamples, requiredTolerance, maxSamples, seed));
    return EXIT_SUCCESS;
    }
    catch(std::exception& e)
    {
        std::cout<<e.what()<<"\n";
        return EXIT_FAILURE;
    }
    catch(...)
    {
        std::cout<<"unknown error \n";
        return EXIT_FAILURE;
    }

return 0;
}

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
QuantLib-users mailing list
QuantLib-users@...
https://lists.sourceforge.net/lists/listinfo/quantlib-users

 « Return to Thread: Manto carlo: MCEuropeanEngine