Happy Holidays, everyone !
I'm trying to generate paths of a square root process using the QuantLib/Boost C++ libraries and have encountered what I believe to be an annoying little problem with a fast and simple solution! I'm pretty new to programming so please don't be too harsh on me :) Here's what I know: 1. The constructor looks like this:
SquareRootProcess( Real b, Real a, Volatility sigma, Real x0 = 0.0,
const boost::shared_ptr<discretization>& d =
boost::shared_ptr<discretization>(new EulerDiscretization))
The crucial function to be used when simulating a stochastic process with QuantLib is evolve(t,x,dt,dw).
Here's what my code looks like:
#include "stdafx.h" #include <ql/quantlib.hpp> #include <ql/stochasticprocess.hpp> #include <ql/processes/squarerootprocess.hpp> #include <ql/Processes/eulerdiscretization.hpp> using namespace QuantLib; void SquareRootProcessSimulation() { Real miu0=0.0; Real miu; Real b=0.3; Real a=5.5; Volatility sigma=2.02; BigInteger seed=12324; MersenneTwisterUniformRng unifMt(seed); BoxMullerGaussianRng<MersenneTwisterUniformRng> bmGauss(unifMt); const boost::shared_ptr<StochasticProcess1D::discretization> &d = boost::shared_ptr<StochasticProcess1D::discretization>( EndEulerDiscretization); boost::shared_ptr<SquareRootProcess> squareRootProcess(new SquareRootProcess(b, a, sigma, miu0, d&)); Time dt=0.1,t=0.0; Real dw; Size numVals=10; for (Size j=1;j<=numVals;++j) { dw=bmGauss.next().value; miu=squareRootProcess->evolve(t,miu0,dt,dw); std::cout << "Time: " << t+dt << ", miu_t: " << miu << std::endl; t+=dt; } }; int _tmain(int argc, _TCHAR* argv[]) { SquareRootProcessSimulation(); std::cin.get(); return 0; }
`
I get no errors when compiling/running the code, but what comes out is a constant value, i.e. something is obviously wrong. I think the problem is in the way I've defined the stochastic process, I cannot quite figure out how the interpret the last part of the constructor with the boost::shared_ptr.
I'm happy to hear any suggestions and hints and thanks for taking the time to read my question!
best regards :)