Hi,
I am trying to understand the monte carlo in QuantLib. However, I am getting errors when i try to call the MCEuropeanEngine. The error is as follows: myMC.cpp: In function ‘int main()’: myMC.cpp:55: error: expected type-specifier before ‘MCEuropeanEngine’ myMC.cpp:55: error: expected `)' before ‘MCEuropeanEngine’ /home/Risco/Cxx/Quant/BoostLib/include/boost-1_38/boost/shared_ptr.hpp: In constructor ‘boost::shared_ptr< <template-parameter-1-1> >::shared_ptr(Y*) [with Y = int, T = QuantLib::PathPricer<QuantLib::Path, double>]’: myMC.cpp:57: instantiated from here /home/Risco/Cxx/Quant/BoostLib/include/boost-1_38/boost/shared_ptr.hpp:183: error: cannot convert ‘int*’ to ‘QuantLib::PathPricer<QuantLib::Path, double>*’ in initialization The error is from this line of the code boost::shared_ptr<PathPricer<Path> > myPathPricer(new MCEuropeanEngine(diffusion, timeSteps, timeStepsPerYear, brownianBridge, antitheticVariate, controlVariate, requiredSamples, requiredTolerance, maxSamples, seed)); I have also attached the full code below as its very short. I can not understand why it says it expected a type specifier before MCEuropeanEngine if its a class template within QuantLib: #include <ql/quantlib.hpp> #include <boost/timer.hpp> #include <iostream> #include <iomanip> using namespace QuantLib; int main() { 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<StochasticProcess1D> 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<PathPricer<Path> > myPathPricer(new MCEuropeanEngine(diffusion, timeSteps, timeStepsPerYear, brownianBridge, antitheticVariate, controlVariate, requiredSamples, requiredTolerance, maxSamples, seed)); return 0; } Thanx in advance. " Upgrade to Internet Explorer 8 Optimised for MSN. " Download Now ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hi Risco,
the two template parameters are for example MCEuropeanEngine<PseudoRandom,Statistics>. Best regards, Kim Risco Mutelo schrieb: > Hi, > > I am trying to understand the monte carlo in QuantLib. However, I am > getting errors when i try to call the MCEuropeanEngine. > > The error is as follows: > > myMC.cpp: In function ‘int main()’: > myMC.cpp:55: error: expected type-specifier before ‘MCEuropeanEngine’ > myMC.cpp:55: error: expected `)' before ‘MCEuropeanEngine’ > /home/Risco/Cxx/Quant/BoostLib/include/boost-1_38/boost/shared_ptr.hpp: > In constructor ‘boost::shared_ptr< <template-parameter-1-1> > >::shared_ptr(Y*) [with Y = int, T = > QuantLib::PathPricer<QuantLib::Path, double>]’: > myMC.cpp:57: instantiated from here > /home/Risco/Cxx/Quant/BoostLib/include/boost-1_38/boost/shared_ptr.hpp:183: > error: cannot convert ‘int*’ to ‘QuantLib::PathPricer<QuantLib::Path, > double>*’ in initialization > > The error is from this line of the code > > boost::shared_ptr<PathPricer<Path> > myPathPricer(new > MCEuropeanEngine(diffusion, timeSteps, timeStepsPerYear, > brownianBridge, antitheticVariate, controlVariate, > requiredSamples, requiredTolerance, maxSamples, seed)); > > I have also attached the full code below as its very short. I can not > understand why it says it expected a type specifier before > MCEuropeanEngine if its a class template within QuantLib: > > #include <ql/quantlib.hpp> > #include <boost/timer.hpp> > #include <iostream> > #include <iomanip> > > using namespace QuantLib; > > int main() > { > > 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<StochasticProcess1D> 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<PathPricer<Path> > myPathPricer(new > MCEuropeanEngine(diffusion, timeSteps, timeStepsPerYear, > brownianBridge, antitheticVariate, controlVariate, > requiredSamples, requiredTolerance, maxSamples, seed)); > > return 0; > } > > Thanx in advance.. > > ------------------------------------------------------------------------ > " Upgrade to Internet Explorer 8 Optimised for MSN. " Download Now > <http://extras.uk.msn.com/internet-explorer-8/?ocid=T010MSN07A0716U> > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > Crystal Reports - New Free Runtime and 30 Day Trial > Check out the new simplified licensing option that enables > unlimited royalty-free distribution of the report engine > for externally facing server and web deployment. > http://p.sf.net/sfu/businessobjects > ------------------------------------------------------------------------ > > _______________________________________________ > QuantLib-users mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-users > ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
In reply to this post by hrisquo
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. 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |