I need to make an example of a walk of a stock price.I have this data:


and i need to resolve this equation:


where "W" is a Wiener process [0,Δt]. I need to make a path of 157 steps(date of expiration of an option).At each step ( 157 ) W (t ) changes randomly. I can also use this equation.

enter image description here

where ε is a random variable [0,Δt] (Δt=157/252) I have done this:

randomWalk[157] := 
    NormalDistribution[(r - σ^2/2)*T, σ Sqrt[T]], 157], 
   Log[Subscript[S, t]]]]

rwalks = Table[randomWalk[157], {5000}]

final = rwalks[[All, -1]]

{Mean[final], StandardDeviation[final], Max[final], Min[final]}

N[E^(-(r)*(T)) (E^Mean[final] - 20)]

The result must to be about 12.667.

  • $\begingroup$ the Wiener process is a continuous-time stochastic process. Its gave rise to the study of continuous time martingales. Wt−Ws ~ N(0, t−s) are independent random variables $\endgroup$ – Madmex May 17 '15 at 7:51
  • $\begingroup$ I've tried a similar process and failed. Will help try to improve the question. $\endgroup$ – djp May 17 '15 at 8:08
  • $\begingroup$ I don't know how to do the code. Is this the problem =) $\endgroup$ – Madmex May 17 '15 at 8:22

I'll add that your stock price update equation can be resolved using an Itō or Stratonovich integral. As it turns out, your equation is precisely the definition of a GeometricBrownianMotionProcess with parameters $S_0 = 32.68$, $\mu=0005214$, $\sigma=0.24$. You should simulate using the GeometricBrownianMotionProcess and not use the Wiener process directly as a driver in this case.

With[{S0 = 32.68, s = 0.24, m = 0.0005214, nsteps = 157, dstep = 157/252},
   GeometricBrownianMotionProcess[m, s, S0],{0, dstep*nsteps, dstep}, 3],
 PlotTheme -> "Business", PlotRange -> Full, 
 DataRange -> {0, 60*60*24*nsteps}]]

This gives plausible simulations of the price without dipping below zero and gives a more realistic returns distribution:

enter image description here

You can also get the price drift, volatility and price distribution etc. directly from the process using :

Mean[GeometricBrownianMotionProcess[m, s, S0][t]] // Simplify
(* returns E^(m t)S0 *)

Variance[GeometricBrownianMotionProcess[m, s, S0][t]] // Simplify
(* returns E^(2 m t) (-1 + E^(s^2 t)) S0^2 *)

GeometricBrownianMotionProcess[m, s, S0][t]
(* returns LogNormalDistribution[(m - s^2/2) t + Log[S0], s Sqrt[t]] *)

Probability[S[t] > 48, S[t] \[Distributed]
 GeometricBrownianMotionProcess[m, s, S0][t]]
(* returns 
  1/2 Erfc[-(((m - s^2/2) t - Log[48] + Log[S0])/(Sqrt[2] s Sqrt[t]))] *)
  • $\begingroup$ Fantastic it's pefect! now just two thing: 1. how I can see the listlineplot ; two what i must to do for vote you up?=) $\endgroup$ – Madmex May 18 '15 at 6:02
  • $\begingroup$ @Madmex you can get the listlineplot and path coordinates with ListLinePlot[ RandomFunction[ GeometricBrownianMotionProcess[0.0005214, 0.24, 32.68], {0, 157/252*157, 157/252}]["Path"]] , to vote up press the up arrow and if you want to accept the answer, press the tick underneath $\endgroup$ – Histograms May 18 '15 at 8:30

I unfortunately don't fully understand the financial aspect of the problem, but I'm going to throw something out there, and hopefully we can improve the answer as we go. You might want to comment on this answer / edit your question as appropriate, so we can move towards a satisfactory answer.

Here I generate some data points from a Wiener process $W(0,\sqrt{157/252})$ as you specified. You want the process to last 157 days, and I assume a time step of 1 day. The time step is assumed to be in seconds for TemporalData objects, which is the origin of those conversion factors (i.e. 157 days = 157*24*60*60 seconds).


data = RandomFunction[
  WienerProcess[0, Sqrt[157/252]],
  {0, 157*24*60*60, 1*24*60*60}

This time-dependent data set is stored in a TemporalData object:

Mathematica graphics

We can do quite a few things with it. First, let's visualize it. The most straightforward way to do so is to use a generic plotting function, e.g. ListPlot:

ListPlot[data, Joined -> True]

Mathematica graphics

Since this is time-dependent data, however, we can use a more specialized plotting function that is aware of time spans, such as DateListPlot:


Mathematica graphics

You will notice that the DateListPlot took care of the time conversion and is showing dates on its horizontal axis.

Finally, if you just want to have the values of the raw data points that were generated, you can extract them from the TemporalData object using Normal:


Here I'll show only a part of the long output from that command:

{{{0, 0.}, {86400, 104.835}, {172800, -75.3291}, <<152>>, {13392000, -1017.42}, {13478400, -1290.62}, {13564800, -933.656}}}

If you want to generate more than one such path, you can also do so easily from the RandomFunction expression:


multipledata = RandomFunction[
  WienerProcess[0, Sqrt[157/252]],
  {0, 157*24*60*60, 1*24*60*60},
  3 (* this is the number of processes to generate *)


Mathematica graphics Mathematica graphics


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.