//option.fs file
#light
type optionType = Call | Put
//oneBarrierOption: (call or put, strike, expiry)
type oneBarrierOption = optionType * float * float
//twoBarriersOption:
// (call or put, lowerBarrier, upperBarrier, expiry)
type twoBarriersOption = optionType * float * float * float
type EuropeanOption = SimpleOption of oneBarrierOption
| DigitalOption of oneBarrierOption
| TwoBarriersDigitalOption of twoBarriersOption
//payoffs.fs file
#light
open System
open Options
let payoff myOption spot =
match myOption with
| SimpleOption (payoffType, strike, _) -> match payoffType with
| Call -> max(spot - strike) 0.0
| Put -> max(strike - spot) 0.0
| DigitalOption (payoffType, strike, _) -> match payoffType with
| Call -> if(spot > strike) then 1.0 else 0.0
| Put -> if(spot < strike) then 1.0 else 0.0
| TwoBarriersDigitalOption (_, lower, upper, _) ->
if(spot > lower && spot < upper)
then 1.0
else 0.0
We can now price this kind of option:
//main.fs file
#light
open System
open Options
open Payoffs
open Montecarlo
let T = 0.3 //maturity
let strikeInf = 99.5 //lower barrier
let strikeSup = 102.5 //upper barrier
let S0 = 100.0 //current underlying price
let r = 0.06 //risk free rate
let sigma = 0.19 //volatility
let n = 100000 //number of simulations
let myOption
= TwoBarriersDigitalOption(Call, strikeInf, strikeSup, T)
let price = mean (simulPayoffs myOption S0 r T sigma n)
print_any price
output:
0.1111708073
No comments:
Post a Comment