Last active
May 25, 2016 15:00
-
-
Save olliefr/1246bdc97e26e9b4ac0712f53fa1eaa9 to your computer and use it in GitHub Desktop.
Generate a binomial lattice for a given up, down, start value and number of steps. A function by Rory Winston.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate a binomial lattice | |
# for a given up, down, start value and number of steps | |
# This function was borrowed Rory Winston: | |
# http://www.theresearchkitchen.com/archives/738 | |
genlattice <- function(X0=100, u=1.1, d=.75, N=5) { | |
X <- c() | |
X[1] <- X0 | |
count <- 2 | |
for (i in 1:N) { | |
for (j in 0:i) { | |
X[count] <- X0 * u^j * d^(i-j) | |
count <- count + 1 | |
} | |
} | |
return(X) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment