0

Suppose it is a multi-period binomial tree, each period it can only go UP(Head) or DOWN(Tail). for a 3 period tree, there will be 2^3=8 scenarios/paths. For example, one of the path is all Heads, that is HHH, then there is HHT, HTH, HTT...

When the period gets large, it is easier to have a loop. Using R, how could I generate a large amount of binomial paths, then I can loop over these paths for other purposes.

1
  • Your questions is a bit unclear, I would suggest to add some reproducible example and some desired output Commented Oct 28, 2014 at 18:50

1 Answer 1

2

You may find the package gtools useful.

library(gtools)
permutations(2,3,c('H','T'),repeats.allowed=TRUE)
     [,1] [,2] [,3]
[1,] "H"  "H"  "H" 
[2,] "H"  "H"  "T" 
[3,] "H"  "T"  "H" 
[4,] "H"  "T"  "T" 
[5,] "T"  "H"  "H" 
[6,] "T"  "H"  "T" 
[7,] "T"  "T"  "H" 
[8,] "T"  "T"  "T" 

For large N,

N<-20
paths=permutations(2,N,c('H','T'),repeats.allowed=TRUE)
for (i in 1:ncol(paths)){ 
    path<-paths[i,]
    # blah blah
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.