Skip to content

Instantly share code, notes, and snippets.

@olliefr
Last active May 25, 2016 15:00
Show Gist options
  • Save olliefr/1246bdc97e26e9b4ac0712f53fa1eaa9 to your computer and use it in GitHub Desktop.
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.
# 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