Guys I am trying to understand the quantlib library and the the moment I am struggling badly. Any help will be appreciated.
I have added the following line to my code and now I am getting the following error: Added lines: " Statistics sampleAccumulator; MonteCarloModel<SingleVariate, PseudoRandom> myModel( myPathGenerator, myPathPricer, sampleAccumulator,antitheticVariate); " Error: " myMC.cpp: In function ‘int main()’: myMC.cpp:67: error: no matching function for call to ‘QuantLib::MonteCarloModel<QuantLib::SingleVariate, QuantLib::GenericPseudoRandom<QuantLib::MersenneTwisterUniformRng, QuantLib::InverseCumulativeNormal>, QuantLib::GenericRiskStatistics<QuantLib::GenericGaussianStatistics<QuantLib::GeneralStatistics> > >::MonteCarloModel(boost::shared_ptr<QuantLib::PathGenerator<QuantLib::InverseCumulativeRsg<QuantLib::RandomSequenceGenerator<QuantLib::MersenneTwisterUniformRng>, QuantLib::InverseCumulativeNormal> > >&, boost::shared_ptr<QuantLib::MCEuropeanEngine<QuantLib::GenericPseudoRandom<QuantLib::MersenneTwisterUniformRng, QuantLib::InverseCumulativeNormal>, QuantLib::GenericRiskStatistics<QuantLib::GenericGaussianStatistics<QuantLib::GeneralStatistics> > > >&, QuantLib::Statistics&, bool&)’ /home/Risco/Cxx/Quant/QuantLib/include/ql/methods/montecarlo/montecarlomodel.hpp:70: note: candidates are: QuantLib::MonteCarloModel<MC, RNG, S>::MonteCarloModel(const boost::shared_ptr<typename MC<RNG>::path_generator_type>&, const boost::shared_ptr<typename MC<RNG>::path_pricer_type>&, const S&, bool, const boost::shared_ptr<typename MC<RNG>::path_pricer_type>&, typename MC<RNG>::path_pricer_type::result_type, const boost::shared_ptr<typename MC<RNG>::path_generator_type>&) [with MC = QuantLib::SingleVariate, RNG = QuantLib::GenericPseudoRandom<QuantLib::MersenneTwisterUniformRng, QuantLib::InverseCumulativeNormal>, S = QuantLib::GenericRiskStatistics<QuantLib::GenericGaussianStatistics<QuantLib::GeneralStatistics> >] /home/Risco/Cxx/Quant/QuantLib/include/ql/methods/montecarlo/montecarlomodel.hpp:51: note: QuantLib::MonteCarloModel<QuantLib::SingleVariate, QuantLib::GenericPseudoRandom<QuantLib::MersenneTwisterUniformRng, QuantLib::InverseCumulativeNormal>, QuantLib::GenericRiskStatistics<QuantLib::GenericGaussianStatistics<QuantLib::GeneralStatistics> > >::MonteCarloModel(const QuantLib::MonteCarloModel<QuantLib::SingleVariate, QuantLib::GenericPseudoRandom<QuantLib::MersenneTwisterUniformRng, QuantLib::InverseCumulativeNormal>, QuantLib::GenericRiskStatistics<QuantLib::GenericGaussianStatistics<QuantLib::GeneralStatistics> > >&) " full source code: " #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 fo the BlackScholesMertonProcess and GeneralizedBlackScholesProcess 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<StochasticProcess1D> diffusion( new BlackScholesMertonProcess(stateVariable, dividendYield, riskFreeRate, volatility)); boost::shared_ptr<GeneralizedBlackScholesProcess> Gdiffusion( new GeneralizedBlackScholesProcess(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> ( Gdiffusion, timeSteps, timeStepsPerYear, brownianBridge, antitheticVariate, controlVariate, requiredSamples, requiredTolerance, maxSamples, seed)); Statistics sampleAccumulator; MonteCarloModel<SingleVariate, PseudoRandom> myModel( myPathGenerator, myPathPricer, sampleAccumulator,antitheticVariate); 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; } " " Upgrade to Internet Explorer 8 Optimised for MSN. " Download Now ------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Risco Mutelo schrieb:
> " > Statistics sampleAccumulator; > > MonteCarloModel<SingleVariate, PseudoRandom> > myModel( myPathGenerator, myPathPricer, > sampleAccumulator,antitheticVariate); > " The problem lies in the second parameter myPathPricer which is of type *boost::shared_ptr<MCEuropeanEngine<PseudoRandom,Statistics> >*. This type doesnt match the signature of constructor from MonteCarloModel: MonteCarloModel( const boost::shared_ptr<path_generator_type>& pathGenerator, *const boost::shared_ptr<path_pricer_type>*& pathPricer, const stats_type& sampleAccumulator, bool antitheticVariate, const boost::shared_ptr<path_pricer_type>& cvPathPricer = boost::shared_ptr<path_pricer_type>(), result_type cvOptionValue = result_type(), const boost::shared_ptr<path_generator_type>& cvPathGenerator = boost::shared_ptr<path_generator_type>()) In your case the type *path_pricer_type *equals *QuantLib::PathPricer<QuantLib::SingleVariate<RNG>::path_type>>. *So you need first create an object from type *QuantLib::PathPricer<QuantLib::SingleVariate<RNG>::path_type>> *and store this object in a shared_ptr. The class *QuantLib::PathPricer *is used to model the payoff function from your structure ( for example: call, put, barrier,...). For an example take a look in file mceuropeanengine.hpp class EuropeanPathPricer : public PathPricer<Path> { public: EuropeanPathPricer(Option::Type type, Real strike, DiscountFactor discount); Real operator()(const Path& path) const; private: PlainVanillaPayoff payoff_; DiscountFactor discount_; }; Best reagrds, Kim Here is the complete code: #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> > myeuropeanengine(new MCEuropeanEngine<PseudoRandom, Statistics>(diffusion, timeSteps, timeStepsPerYear, brownianBridge, antitheticVariate, controlVariate, requiredSamples, requiredTolerance, maxSamples, seed)); boost::shared_ptr<MCEuropeanEngine<PseudoRandom,Statistics>::path_pricer_type > myPathPricer(new EuropeanPathPricer(Option::Call,100.0,1.0) ); Statistics sampleAccumulator; MonteCarloModel<SingleVariate, PseudoRandom> myModel( myPathGenerator, myPathPricer, sampleAccumulator,antitheticVariate); 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |