Skip to content

Instantly share code, notes, and snippets.

@martijndwars
Last active December 25, 2015 14:09
Show Gist options
  • Save martijndwars/6988776 to your computer and use it in GitHub Desktop.
Save martijndwars/6988776 to your computer and use it in GitHub Desktop.
R code to calculate option value recursively backward in the binomial asset pricing model.
p <- 1/2;
u <- 2;
d <- 1/u;
r <- 1/4;
v <- function(n, s) {
if (n == 3) {
return(pmax(s-10, 0));
}
(p*v(n+1, u*s)+(1-p)*v(n+1, d*s))/(1+r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment