モンテカルロ法でコール・オプション価格
とりあえず慣れてるのからということで・・・Wolfram Alphaで出した結果と大体あってるので、これでよさげだ。
import scala.util.Random import scala.math object App { def main(args: Array[String]) = { val random = new Random() // Monte Carlo setting val size = math.pow(10, 5).toInt // market information val volatility = 0.3 val spotPrice = 100.0 val rate = 0.01 // option parameters val maturity = 5.0 val strike = 102.0 //Monte Cralo val result = {for (i <- 1 to size) yield { val noize = volatility * math.sqrt(maturity) * random.nextGaussian() val drift = (rate - 0.5 * volatility * volatility) * maturity val price = spotPrice * math.exp( drift + + noize ) math.max(price - strike, 0.0) }}.sum * ( math.exp( -rate * maturity) )/ size // Show result println("Option price is: " + result) } }
結果
Option price is: 27.24