Question on PathGenerator

Posted by Penschke, Walter on
URL: http://quantlib.414.s1.nabble.com/Question-on-PathGenerator-tp3287.html

Hi,

I am currently investigating quantlib's MonteCarlo package.

I tried to simulate a geometric brownian motion process, which I did define
in my own class GeometricBrownianMotionProcess. Basically this class is
derived from StochasticProcess and defines the methods drift and diffusion.
Here my source code:

 <<GeometricBrownianMotionProcess.cpp>>  
<<GeometricBrownianMotionProcess.hpp>>

The stochastic differential equation of this process is:

        dS = mue * S * dt + sigma * S * dz


The problem now is that class PathGenerator from Quantlib (defined in
pathgenerator.hpp) does not produce proper paths for this process. Having
had a look at the next() method of PathGenerator (brownianBridge_ == false)
I realised that the drift and the diffusion arrays in the returned Path are
computed correctly in principal. However the asset_ variable, which tracks
the evolvement of the process, in my case S, within this method is adjusted
as follows per step:

        asset_ *= QL_EXP(next_.value[i])

This is correct if the Path variable (next_) is modelling a process defined
on dS/S, i.e.: on the change of the process, rather than the process itself.
For my GeometricBrownianProcess, which defines the process on dS, the line
above in my (simple) opinion should be (May be that's not quite correct, but
I hope you get the idea.):

        asset_ *= QL_EXP(next_.value[i] / asset_)

As I am modelling S in my path, next_.value[i] does not contain a percentage
change, but the new simulated value itself.

This would mean that I can't reuse the existing PathGenerator class, but I
need to implement my own one which basically only differs in the line above.
I would not fear this extra effort. However, I think this code duplication
is not nice and should be avoided if possible.

Are there any comments on this? Please let me know if you need more
information on this issue.

Any help would be highly appreciated.


wpe



GeometricBrownianMotionProcess.cpp (1K) Download Attachment
GeometricBrownianMotionProcess.hpp (1K) Download Attachment