Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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]
share|improve this question
    
Where exactly is the problem so that you don't implement this your self? –  Ajasja Jun 6 '13 at 13:19
    
@ 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 –  Milan Ivica Jun 6 '13 at 13:22
    
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. –  Ajasja Jun 6 '13 at 13:40
    
@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. –  Milan Ivica Jun 6 '13 at 13:44
add comment

1 Answer 1

up vote 5 down vote accepted

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

share|improve this answer
    
@ Rod Lm thank you. you have been a really great help! :) –  Milan Ivica Jun 6 '13 at 15:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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