Login  Register

QuantLibAddin and Monte Carlo simulation

Posted by Lapin on Sep 25, 2009; 2:21pm
URL: http://quantlib.414.s1.nabble.com/QuantLibAddin-and-Monte-Carlo-simulation-tp8185.html

Hi all,

I am trying to expose MCBarrierEngine into quantLibXL but I am really struggling to pass the PseudoRandomNumber generator...

Let appart the relevant includes, in my view you would need to add the following code in pricingengine.cpp

        template<typename T>
        class MCBarrierEngine : public PricingEngine {
      public:
        MCBarrierEngine(
            const boost::shared_ptr<ObjectHandler::ValueObject>& properties ,
                        const boost::shared_ptr<QuantLib::GeneralizedBlackScholesProcess>& process ,
                        const QuantLib::Size maxTimeStepsPerYear ,
                        bool brownianBridge ,
                        bool antitheticVariate ,
                        bool controlVariate ,
                        const QuantLib::Size requiredSamples ,
                        const QuantLib::Real requiredTolerance ,
                        const QuantLib::Size maxSamples ,
                        bool isBiased ,
                        const T& RSQ ,
                        const QuantLib::BigNatural seed ,
            bool permanent );



And this in pricingengine.cpp

        template<typename T>
        MCBarrierEngine<T>::MCBarrierEngine(
            const boost::shared_ptr<ObjectHandler::ValueObject>& properties ,
                        const boost::shared_ptr<QuantLib::GeneralizedBlackScholesProcess>& process ,
                        const QuantLib::Size maxTimeStepsPerYear ,
                        const bool brownianBridge ,
                        const bool antitheticVariate ,
                        const bool controlVariate ,
                        const QuantLib::Size requiredSamples ,
                        const QuantLib::Real requiredTolerance ,
                        const QuantLib::Size maxSamples ,
                        const bool isBiased ,
                        const T& RSQ ,
                        const QuantLib::BigNatural seed ,
            bool permanent )
                        : PricingEngine(properties, permanent)
        {
        libraryObject_ = boost::shared_ptr<QuantLib::PricingEngine>(new
                        QuantLib::MCBarrierEngine<RSQ>(process,
                                            maxTimeStepsPerYear, brownianBridge,
                                            antitheticVariate, controlVariate,
                                            requiredSamples, requiredTolerance,
                                            maxSamples, isBiased, seed)) ;
        }

To finish, you need to add the following constructor in pricingengine.xml


          <Constructor name='qlMCBarrierEnginer'>
                  <libraryFunction>MCBarrierEngine</libraryFunction>
                  <SupportedPlatforms>
                          <SupportedPlatform name='Excel'/>
                  </SupportedPlatforms>
                  <ParameterList>
                          <Parameters>
                                  <Parameter name='ProcessID' >
                                          <type>QuantLib::GeneralizedBlackScholesProcess</type>
                                          <superType>libraryClass</superType>
                                          <tensorRank>scalar</tensorRank>
                                          <description>GeneralizedBlackScholesProcess object ID.</description>
                                  </Parameter>
                                  <Parameter name='TimeStepPerYear'>
                                          <type>long</type>
                                          <tensorRank>scalar</tensorRank>
                                          <description>Time Steps Per Year</description>
                                  </Parameter>
                                  <Parameter name='BrownianBridge' default='FALSE'>
                                          <type>bool</type>
                                          <tensorRank>scalar</tensorRank>
                                          <description>Using a Brownian Bridge?</description>
                                  </Parameter>
                                  <Parameter name='AntitheticVariate' default='FALSE'>
                                          <type>bool</type>
                                          <tensorRank>scalar</tensorRank>
                                          <description>Using a Antithetic Variate?</description>
                                  </Parameter>
                                  <Parameter name='ControlVariate' default='FALSE'>
                                          <type>bool</type>
                                          <tensorRank>scalar</tensorRank>
                                          <description>Using a Control Variate?</description>
                                  </Parameter>
                                  <Parameter name='RequiredSamples'>
                                          <type>long</type>
                                          <tensorRank>scalar</tensorRank>
                                          <description>Minimum number of pathes</description>
                                  </Parameter>
                                  <Parameter name='RequiredTolerance'>
                                          <type>long</type>
                                          <tensorRank>scalar</tensorRank>
                                          <description>Tolerance on the error</description>
                                  </Parameter>
                                  <Parameter name='MaxSamples'>
                                          <type>long</type>
                                          <tensorRank>scalar</tensorRank>
                                          <description>Maximum number of pathes</description>
                                  </Parameter>
                                  <Parameter name='RandomNumberGenerator'>
                                          <type>QuantLib::PseudoRandomSequenceGenerator</type>
                                          <superType>underlyingClass</superType>
                                          <tensorRank>scalar</tensorRank>
                                          <description>Random Number Generator</description>
                                  </Parameter>
                                  <Parameter name='Seed' default='123'>
                                          <type>long</type>
                                          <tensorRank>scalar</tensorRank>
                                          <description>Seed used for the random numbers</description>
                                  </Parameter>
                          </Parameters>
                  </ParameterList>
          </Constructor>


I get an error C3203: 'PseudoRandomSequenceGenerator' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type ... since I use a non unspecialized template class for the generator.

Is there a way to do 1 XL function for all the Pseudo Random Generators?

Cheers