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.

I'm relatively new to Mathematica programming, so forgive my rather unsophisticated question: I'm trying to do a Monte Carlo simulation using geometric Brownian motion (GBM). I want to write a indicator function which produces is 1 if my GBM stays within a certain corridor [L, U]. I found a function which produces the paths of my GBM:

data = RandomFunction[
  GeometricBrownianMotionProcess[0.01, .15, 100], {0, 1, .01}, 100]

How can I access data so that I can write the indicator function?

EDIT: Ive got a follow up question: Let's say one sample path is the following list

pts=data["Paths"]       
pts    
{{0,100},{0.01,98}...}

How can I select from all my pahts only those values where the x-variable is >=1? I tried Select[pts,#1.0&], but this gives me an empty list.

share|improve this question
    
Try data["Paths"]. It's explained in the docs. –  b.gatessucks Jan 28 '13 at 17:25
add comment

1 Answer 1

up vote 6 down vote accepted

You can get the state values for every with data["States"], which you can then easily feed into a indicator function.

data = RandomFunction[
  GeometricBrownianMotionProcess[0.01, .15, 100], {0, 1, .01}, 100];
corridorIndicator[data_, upperBound_, lowerBound_] := 
 Boole[Max@# < upperBound && Min@# > lowerBound] & /@ data
corridorIndicator[data["States"], 120, 80]

(*{1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 
1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 
1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 
1}*)

EDIT: You just need to make sure you get the syntax for Select correct.

data2 = RandomFunction[
  GeometricBrownianMotionProcess[0.01, .15, 100], {0, 1.3, .01}];
Select[#, #[[1]] >= 1 &] & /@ data2["Paths"]

(*{{1., 136.038}, {1.01, 133.344}, {1.02, 136.278}, {1.03, 
134.923}, {1.04, 131.44}, {1.05, 131.136}, {1.06, 130.272}, 
{1.07, 132.126}, {1.08, 130.555}, {1.09, 126.961}, {1.1, 
129.282}, {1.11, 128.943}, {1.12, 129.941}, {1.13, 128.51}, 
{1.14, 126.807}, {1.15, 127.05}, {1.16, 129.184}, {1.17, 
129.768}, {1.18, 130.598}, {1.19, 129.944}, {1.2, 128.456}, 
{1.21, 129.06}, {1.22, 128.27}, {1.23, 129.513}, {1.24, 
128.668}, {1.25, 128.651}, {1.26, 127.765}, {1.27, 128.401}, 
{1.28, 127.564}, {1.29, 126.732}, {1.3, 127.631}}*)
share|improve this answer
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.