# Plot two functions within manipulate

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?

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]


• Thank you a lot, you have really be a great help – Milan Ivica Jun 3 '13 at 17:52
• 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? – Milan Ivica Jun 3 '13 at 18:37
• @MilanIvica Sorry that's already beyond my understanding... :( – cormullion Jun 3 '13 at 19:41
• no problem, thank you a lot for your help – Milan Ivica Jun 3 '13 at 19:43