Last active
January 4, 2016 12:29
-
-
Save martijndwars/8621515 to your computer and use it in GitHub Desktop.
Algorithm to value a path-independent American put option in the binomial model. Up-factor u=2, down-factor d=1/u, s=4 and expiry is at time N, such that the risk neutral probabilities p=q=1/2. The function g determines the intrinsic value (value if exercises immediately). By changing the function g one can value different kinds of American opti…
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
object OptionValue { | |
val N = 2 | |
val u: Double = 2 | |
val d: Double = 1/u | |
def main(args: Array[String]): Unit = { | |
println(v(0,4,(s: Double) => 0.0 max (4.0-s))) | |
} | |
def v(n: Double, s: Double, g: Double => Double): Double = | |
if (n == N) | |
g(s) | |
else | |
g(s) max (0.4*(v(n+1, u*s, g) + v(n+1, d*s, g))) | |
} |
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
object PerpetualPut { | |
def main(args: Array[String]): Unit = { | |
val j = 1 | |
val s = 2^j | |
def v(s: Double): Double = | |
if (s <=2) | |
4-s | |
else | |
4/s | |
println(v(8)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment