6
$\begingroup$

I just want to plot all stochastic processes and their average process. The original code without the average is:

Manipulate[SeedRandom[seed]; 

 test2[μ_, σ_, S_, P_] := 
  Table[RandomFunction[
     GeometricBrownianMotionProcess[μ, σ, S], {0, 250, 0.05}]["Path"], {P}];

 ListLogPlot[test2[μ, σ, S, P], Joined -> True, 
  AxesLabel -> {"Time", "St"}, 
  PlotLabel -> Style["Forecasted Stock Price\n (Brownian Motion)", Bold], 
  PlotRange -> {{0, 250}, {0, 3000}}, ImageSize -> 500, 
  PlotStyle -> Directive[{Thin, Lighter@Gray}]], 

{{S, 100, "Initial Stock Value"}, 100, 500, 0.05, Appearance -> "Labeled"}, 
{{μ, 0.01, "Drift μ"}, 0.01, 1, 0.05, Appearance -> "Labeled"}, 
{{σ, 0.01, "Standard Deviation σ"}, 0.01, 1, 0.05, Appearance -> "Labeled"}, 
{{P, 1, "Paths"}, 1, 100, 1, Appearance -> "Labeled"},

{{seed, 77777, "New Random Case"}, 10000, 999999, 1}, 

 Button["Set Initial Values", {S = 100, μ = 0.01, σ = 0.01}, 
ImageSize -> 150], 
ControlPlacement -> Left]

So far I have done the following (changed the original gode a Little bit) but it’s not working properly since I only get the mean of all processes and not both, the processes (in grey colour) and their average process (in red colour).

Manipulate[SeedRandom[seed]; 

 test2[μ_, σ_, S_, P_] := 
  Table[RandomFunction[
     GeometricBrownianMotionProcess[μ, σ, S], {0, 250, 0.05}]["Path"], {P}];

meanPaths=Mean[test2[μ,σ,S,P][[All]]];

 ListLogPlot[{test2[μ, σ, S, P],meanPaths}, Joined -> True, 
  AxesLabel -> {"Time", "St"}, 
  PlotLabel -> Style["Forecasted Stock Price\n (Brownian Motion)", Bold], 
  PlotRange -> {{0, 250}, {0, 3000}}, ImageSize -> 500, 
PlotStyle -> Directive[{{Thin,Lighter@Gray},{Thickness[Medium],Red}}]],



{{S, 100, "Initial Stock Value"}, 100, 500, 0.05, Appearance -> "Labeled"}, 
{{μ, 0.01, "Drift μ"}, 0.01, 1, 0.05, Appearance -> "Labeled"}, 
{{σ, 0.01, "Standard Deviation σ"}, 0.01, 1, 0.05, Appearance -> "Labeled"}, 
{{P, 1, "Paths"}, 1, 100, 1, Appearance -> "Labeled"},

{{seed, 77777, "New Random Case"}, 10000, 999999, 1}, 

 Button["Set Initial Values", {S = 100, μ = 0.01, σ = 0.01}, 
ImageSize -> 150], 
ControlPlacement -> Left]

Any ideas what I could be missing?

Thank you for your help

$\endgroup$

1 Answer 1

6
$\begingroup$

A bit puzzling, but I think you have problems with the levels in ListLogPlot (where you added another set of values), and with the PlotStyle directives (where you added options to a Directive). I changed a few things quasi-randomly and got something which I think is closer to what you want.

Manipulate[
 SeedRandom[seed];
 Column[{
   test2[μ_, σ_, S_, P_] := 
    Table[RandomFunction[
       GeometricBrownianMotionProcess[μ, σ, S], {0, 250, 
        0.05}]["Path"], {P}]; 
   meanPaths = Mean[test2[μ, σ, S, P][[All]]];
   ListLogPlot[{meanPaths, Flatten[test2[μ, σ, S, P], 1]},
    Joined -> True,
    AxesLabel -> {"Time", "St"},
    PlotLabel -> 
     Style["Forecasted Stock Price\n (Brownian Motion)", Bold],
    PlotRange -> Full,
    PlotStyle -> {Directive[{Thick, Red}], Directive[{Thin, Gray}]},
    ImageSize -> 500]
   }],
 {{S, 100, "Initial Stock Value"}, 100, 500, 0.05, Appearance -> "Labeled"}, 
 {{μ, 0.01, "Drift μ"}, 0.01, 1, 0.05, Appearance -> "Labeled"}, 
 {{σ, 0.01, "Standard Deviation σ"}, 0.01, 1, 0.05, Appearance -> "Labeled"},
 {{P, 1, "Paths"}, 1, 100, 1, Appearance -> "Labeled"},
 {{seed, 77777, "New Random Case"}, 10000, 999999, 1}, 
 Button["Set Initial Values", {S = 100, μ = 0.01, σ = 
    0.01}, ImageSize -> 150],
 ControlPlacement -> Left]

wacky stock plot

$\endgroup$
4
  • $\begingroup$ Thank you a lot, you have really be a great help $\endgroup$ Commented Jun 3, 2013 at 17:52
  • $\begingroup$ I have one more question. When I decrease the time then there are some straigt lines visible in the chart? do you also have the same problem? what couldbe the reason? $\endgroup$ Commented Jun 3, 2013 at 18:37
  • $\begingroup$ @MilanIvica Sorry that's already beyond my understanding... :( $\endgroup$
    – cormullion
    Commented Jun 3, 2013 at 19:41
  • $\begingroup$ no problem, thank you a lot for your help $\endgroup$ Commented Jun 3, 2013 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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