Saturday, December 20, 2014

C++ Coding - Time to first exit (C++11 VS2012)

4.1 Time To First Exit

Calculate the expected hitting time E[t] for a Brownian motion X(t), where the process must hit either X(t) = 0 or X(t) = 1 for t < T. If neither boundary is hit within the time T then t = T.

Assume that the process X follows the SDE

dX  =  μdt + σdW
where μ = 0.01 is the drift and σ = 0.75 is the standard deviation of the Brownian motion. We have that the initial start point of the Brownian motion is X(t = 0) = 0.56, and we set T = 1.

Friday, December 19, 2014

C++ Coding - Random Numbers (Update c++11 VS2012)

The example question for these solutions can be found on my website (click here).

2.1 Random Numbers

To use the new random number generator we need to include the random library, the cmath library for any calculations and also iostream to show results onscreen. We first create a new project with an empty program with the correct libraries, and then declare a variable of type mt19937. This declares a new random number generator, which generates pseudo random sequence of integers defined by the Mersenne Twister algorithm. A computer can only generate a random sequence of integers, but of course we can then take that sequence of integers and convert it to any required distribution. Some of the conversions are simple but others are more complex, luckily we now have inbuilt c++ conversion to all standard distributions (more on this later). This means you will always have to create a generator to pass as an argument to the probability distribution you want to generate.

Thursday, February 27, 2014

C++ Coding - Time to first exit

Question Calculate the expected time to first exit from the interval [0,1] for a Brownian motion X with the following SDE
where dW is a standard Wiener process and X(t=0)=0.56.