Sunday 2 November 2008

Adding a new option type

Adding a new option type to this Monte Carlo pricer is very easy: For example, let's suppose that we want to price an option with two barriers which pays one if the price of the underlying is between these barriers, zero otherwise. We just need to add one line to option.fs to define a new type for two barriers options, and add a new case to our payoff function in payoff.fs:

//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: