# Forecasting future Stock Prices II

I intend to do the following: I want to forecast future stock price under the following assumptions: The stock price is governed by the stochastic differential equation:

dS = μSdt + σSdWt

whereas dW_t~N(0,√dt)

In the first step I want to define the Brownian Motion for one path and for multiple paths, which is done by:

1Path:

BrownianMotion[period_, steps_Integer: 1000, init_: 0] := Accumulate[
Prepend[RandomVariate[NormalDistribution[0, Sqrt[period/steps]],
steps], init]]

ListLinePlot[BrownianMotion[1,1000], AxesLabel->{"Time",B_t},
PlotLabel -> Style["Stochastic Brownian Motion",Bold]]


Multiple Paths:

BrownianMotionPaths[period_, steps_Integer: 1000, paths_Integer, init_List]
/; (Length[init] == paths) := Transpose[
Accumulate[
Prepend[RandomVariate[NormalDistribution[0, Sqrt[period/ steps ]],
{steps, paths}], init]]]

ListLinePlot[BrownianMotionPaths[1, 1000, 50,
ConstantArray[0.5, 50]],
AxesLabel->{"Time",B_t},
PlotLabel -> Style["Stochastic Brownian Motion",Bold]]


So I get the following, which works perfectly for one path:

μ2 = 0.01; σ2 = 0.3; S2 = 100;

ListLinePlot[S2*(1+μ2ConstantArray[1,251] + BrownianMotion[1, 250]*σ2),
AxesLabel→{"Time","St"},
PlotLabel -> Style["Price by proxy data"],
PlotRange -> All]


NOW I want to manipulate S2,μ2, and σ2. In order to do so, I entered the following code:

Manipulate[
ListLinePlot[S1*(1 + μ1 ConstantArray[1, 251] + BrownianMotion[1, 250] * σ2),
AxesLabel -> {"Time", "St"},
PlotLabel -> Style["Price by proxy data"],
PlotRange -> All],
{S1, 100, 500, Appearance -> "Labeled"},
{μ1, 0, 1, Appearance -> "Labeled"},
{σ1, 0, 1, Appearance -> "Labeled"}]


It works, but the results must be wrong, because when I choose Sigma to be small and increase Mu drastically, I should get something which looks like an exponentially increasing function, because the function is driven heavily by the drift. However, according to my code this is not the case. So something must be wrong.

Does anybody have a solution when I want to manipulate the start value (S1), Sigma, and Mu, for one and for multiple paths?

• You're forgetting the special characters need backslashes eg \[Mu], and you're calling a function BrownianMotion1 that isn't there, and your Manipulate is varying a \[Sigma]1 that I can't see. Keep editing! :) May 24, 2013 at 17:54
• Done, hope it's now ok. If you find anything please contact me. thanks for your Feedback :) May 24, 2013 at 17:57
• Please check my edits - except for the MathJAX, which I can't do yet... :) May 24, 2013 at 18:33
• Just generic remarks : I don't think your solution for S(t) is correct. You don't accumulate the "random stuff" only and then add the drift bit at the end. Also, the section regarding multiple paths doesn't seem relevant at this point. May 24, 2013 at 19:49
• @Milan Ivica I really don't understand why you keep insisting in developing your own proprietary code (or use someone's code), when Mathematica already have all this GBM stuff internally... I think in my answer I've already shown exactly what you want for the 1-case and multiple-case paths...
– Rod
May 24, 2013 at 20:24

Using Manipulate on a random process is a great way to build intuition.

The key here is to fix the y-axis with PlotRange to get a sense of how the parameters change the scale of the randomness

Using the inbuilt functions that @Rod mentioned in the comments:

Manipulate[
ListLinePlot[
RandomFunction[
GeometricBrownianMotionProcess[drift, volatility, startValue], {0,
1, 0.01}],
PlotRange -> {0, 5}
],
{{volatility, 0.0001}, 0.0001, 1},
{{drift, 0}, -0.5, 0.5},
{{startValue, 1}, 0.0001, 2}
]