# Martingale pricing_Simulation random walk stock price

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. where ε is a random variable [0,Δt] (Δt=157/252) I have done this:

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

rwalks = Table[randomWalk, {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.

• 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 – Madmex May 17 '15 at 7:51
• I've tried a similar process and failed. Will help try to improve the question. – djp May 17 '15 at 8:08
• I don't know how to do the code. Is this the problem =) – Madmex May 17 '15 at 8:22

## 2 Answers

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},
DateListPlot[
RandomFunction[
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: 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 + Log[S0])/(Sqrt s Sqrt[t]))] *)

• 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?=) – Madmex May 18 '15 at 6:02
• @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 – 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).

SeedRandom

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: 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] Since this is time-dependent data, however, we can use a more specialized plotting function that is aware of time spans, such as DateListPlot:

DateListPlot[data] 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:

Normal[data]


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:

SeedRandom

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 *)
]

DateListPlot[multipledata]  