# Counting Stochastic Processes and displaying relative value

Counting Stochastic Processes and displaying relative value

I have two watermarks and multiple stochastic processes given. I want both to display and count the stochastic processes which are below the two watermarks, namely watermark and watermark2:

Furthermore I also want do display the relative proportion af all processes below watermark and watermark2 to all processes.

In order to count the processes I used first generated a random matrix to get a little bit familiar with the counting fucntion the code is:

dataX = Table[RandomFunction[
GeometricBrownianMotionProcess[0.1, 0.2, 10], {0, 10, 0.1}]["Path"], {3}]


Then:

processesX = Transpose[dataX[[#]]][[2]] & /@ Range@Length[assetsX]


Then I just wanted to count the process values beyond 20 by this code:

Count[Flatten[dataX], _?(# >= 20 &)]


this worked so I tried to apply it for my code, however, I have some problems and I am not sure if I have allpied it properly. I would be greateful for any help.

my code:

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 &)]];
processesposition2 =
Flatten[Position[
Min[processes[[#]]] & /@
Range@Length[assets], _?(# > watermark2 &)]];
watermarkedassets = assets[[#]] & /@ processesposition;
watermarkedassets2 = assets[[#]] & /@ processesposition2;
watermarkedmeanvector = Mean[watermarkedassets];
watermarkedmeanvector2 = Mean[watermarkedassets2];

(*Counting Stochastig processes below watermark and watermark2*)
StoProcbelowwatermark =
Count[Flatten[assets], _?(# >= watermarkedassets &)];
StoProcbelowwatermark2 =
Count[Flatten[assets], _?(# >= watermarkedassets2 &)];
(*Relative proportion of assetes belos watermark and watermark2 to \
all assets*)
RelProportionwatermarktoall = StoProcbelowwatermark/P;
RelProportionwatermark2toall = StoProcbelowwatermark2/P;

(*Functions and Plotting*)
G1 := ListLogPlot[assets,
GridLines -> {{}, {{watermark,
Directive[Green, Thick]}, {watermark2,
Directive[Orange, 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,
watermarkedmeanvector2}, Joined -> True,
PlotStyle -> {Directive[{Thick, Darker@Red}],
Directive[{Thick, Darker@Blue}], Directive[{Thick, Black}]}];
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"}, {{watermark2, 70, "Watermark2"}, 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, watermark2 = 70},
ImageSize -> 150],
Dynamic["Mean watermarked processes = " <>
ToString[watermarkedmeanvector[[-1]][[2]]]],
Dynamic["Mean watermarked2 processes = " <>
ToString[watermarkedmeanvector2[[-1]][[2]]]],
Dynamic["Mean of all processes = " <>
ToString[meanvector[[-1]][[2]]]],
(*Displaying Processes below the two watermakrs*)
Dynamic["Processes below watermark = " <>
ToString[StoProcbelowwatermark[[-1]][[2]]]],
Dynamic["Processes below watermark2 = " <>
ToString[StoProcbelowwatermark2[[-1]][[2]]]],
(*Displaying relative proportions Processes below watermakrs in \
relation to all processes*)
Dynamic["relation processes below watermark and all processes= " <>
ToString[RelProportionwatermarktoall[[-1]][[2]]]],
Dynamic["relation processes below watermark and all processes= " <>
ToString[RelProportionwatermark2toall[[-1]][[2]]]],
ControlPlacement -> Left]

-
Did you try Length[processesposition] and Length[processesposition2]? – Rod Jun 9 '13 at 13:05
For the proportions, just divide Length[processesposition] and Length[processesposition2] by Length[assets]. – Rod Jun 9 '13 at 13:09

For the amount of processes below your watermarks you can use Length[processesposition] and Length[processesposition2].
For the proportions, just divide Length[processesposition] and Length[processesposition2] by Length[assets].
@MilanIvica You don't have to use ToString[Length[processesposition][[-1]][[2]]]... Just use ToString[Length[processesposition]]... – Rod Jun 9 '13 at 13:21