1
$\begingroup$

Rod Lm helped me to generate the following code, which I want to extend a little bit. So my intention is to use the threshold (the green line) as boundary in the following way: as soon as the process hits the threshold (watermark) it stops and is also excluded from the calculation of the mean function. So all processes which equal or fall beneath the threshold should stop and all processes that remain beyond the threshold should continue and the mean should only be calculated from the processes that remain beyond the threshold.

Is this or something similar even possible?

Thank you.

the code:

Manipulate[SeedRandom[seed];
meanvector := Mean[assets];
assets = Table[
RandomFunction[GeometricBrownianMotionProcess[μ, σ, S0], {0, time, 0.1}]["Path"], {P}];
G1 := ListLogPlot[
assets, GridLines -> {{}, {threshold}}, GridLinesStyle -> Directive[Green, Thick], Joined -> True, AxesLabel -> {"Time", "St"}, PlotLabel -> Style["Forecasted Stock Price\n (Brownian Motion)", Bold], PlotRange -> All, PlotStyle -> Directive[{Thin, Lighter@Gray}]];

G2 := ListLogPlot[
Mean[assets], Joined -> True, PlotStyle -> Directive[{Thick, Darker@Red}]];
    Show[G1, G2],
    {{S0, 25, "Initial Stock Value"}, 1, 500, 0.5, Appearance -> "Labeled"},
    {{μ, 0.08, "Drift μ"}, 0.01, 0.2, 0.01, Appearance -> "Labeled"}, 

{{σ, 0.2, "Standard Deviation σ"}, 0.01, 1, 0.05, Appearance -> "Labeled"},
        {{P, 6, "Paths"}, 1, 20, 1, Appearance -> "Labeled"},
        {{time, 10, "Time t"}, 1, 20, 1, Appearance -> "Labeled"},
        {{threshold, 25, "Watermark"}, 1, 500, Appearance -> "Labeled"},
        {{seed, 1, "New Random Case"}, 1, 100, 1},
Button["Set Initial Values", {S0 = 25, μ = 0.08, σ = 0.20, P = 6, time = 10, threshold = 25}, ImageSize -> 150],
            ControlPlacement -> Left]
$\endgroup$
  • $\begingroup$ Where exactly is the problem so that you don't implement this your self? $\endgroup$ – Ajasja Jun 6 '13 at 13:19
  • $\begingroup$ @ Ajasja: I am not sure, if i should do it by generating my own Brownian Motion by including an "If" condition. or just including an "If" condition into "assets" that only those processes are displayed that remain beyond the threshold? or is there a third easier way? I am thankful for any suggestions $\endgroup$ – Milan Ivica Jun 6 '13 at 13:22
  • $\begingroup$ Depends on how long the simulations take. If I understood the problem correctly the easiest would be to select the assets after they have been generated and discard those that you do not want. $\endgroup$ – Ajasja Jun 6 '13 at 13:40
  • $\begingroup$ @Ajasja thanks. I am also considering that, but it would be cool if it could be done directly within the given model. Trying to figure out how. $\endgroup$ – Milan Ivica Jun 6 '13 at 13:44
5
$\begingroup$

Well, I think this solves your question:

Manipulate[SeedRandom[seed];
meanvector := Mean[assets];
assets = Table[RandomFunction[GeometricBrownianMotionProcess[μ, σ, S0], {0, time, 0.1}]["Path"], {P}];
processes = Transpose[assets[[#]]][[2]] & /@ Range@Length[assets];
processesposition=Flatten[Position[Min[processes[[#]]]&/@Range@Length[assets], _?(# > watermark &)]];
watermarkedassets = assets[[#]] & /@ processesposition;
watermarkedmeanvector = Mean[watermarkedassets];
G1 := ListLogPlot[assets, GridLines -> {{}, {watermark}},GridLinesStyle -> Directive[Green, Thick], Joined -> True, AxesLabel -> {"Time", "St"}, PlotLabel -> Style["Forecasted Stock Price\n (Brownian Motion)", Bold], PlotRange -> All, PlotStyle -> Directive[{Thin, Lighter@Gray}]];
G2 := ListLogPlot[{meanvector, watermarkedmeanvector},Joined -> True, PlotStyle -> {Directive[{Thick, Darker@Red}], Directive[{Thick, Darker@Blue}]}];
Show[G1, G2], 
{{S0, 100, "Initial Stock Value"}, 1, 500, 0.5, Appearance -> "Labeled"}, 
{{μ, 0.08, "Drift μ"}, 0.01, 0.2, 0.01, Appearance -> "Labeled"}, 
{{σ, 0.2, "Standard Deviation σ"}, 0.01, 1, 0.05, Appearance -> "Labeled"}, 
{{P, 6, "Paths"}, 1, 20, 1, Appearance -> "Labeled"}, 
{{time, 10, "Time t"}, 1, 20, 1, Appearance -> "Labeled"}, 
{{watermark, 75, "Watermark"}, 1, 500, Appearance -> "Labeled"}, 
{{seed, 1, "New Random Case"}, 1, 100, 1}, 
Button["Set Initial Values", {S0 = 100, μ = 0.08, σ = 0.20, P = 6, time = 10, watermark = 75}, ImageSize -> 150], 
ControlPlacement -> Left]

Watermarked mean: blue

Mean of all processes: red

I hope it helps!

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ @ Rod Lm thank you. you have been a really great help! :) $\endgroup$ – Milan Ivica Jun 6 '13 at 15:08

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.