Skip to content

Commit 1d616e6

Browse files
committedOct 30, 2018
dispatch for am and eu options
1 parent cb40994 commit 1d616e6

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
[![Build Status](https://travis-ci.org/JuliaQuant/FinancialDerivatives.jl.svg?branch=master)](https://travis-ci.org/JuliaQuant/FinancialDerivatives.jl)
44

5-
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliaquant.github.io/FinancialDerivatives.jl/stable) or [![](https://img.shields.io/badge/docs-dev-blue.svg)](https://juliaquant.github.io/FinancialDerivatives.jl/dev/)
5+
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliaquant.github.io/FinancialDerivatives.jl/stable)[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://juliaquant.github.io/FinancialDerivatives.jl/dev/)

‎src/models/black_scholes.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Evaluate option `O` using `BlackScholes` model.
1313
# Arguments
1414
- `O::Option`: Option
1515
"""
16-
function evaluate(O::Option, m::BlackScholes)
16+
function evaluate(O::EuropeanOption, m::BlackScholes)
1717
d1 = (log(O.s / O.k) + (O.r + O.σ * O.σ / 2) * O.t) / (O.σ * O.t)
1818
d2 = d1 - O.σ * O.t
1919

@@ -30,4 +30,4 @@ end
3030
3131
Evaluate option `o` using Back-Scholes model as default valuation model.
3232
"""
33-
evaluate(O::Option) = evaluate(O::Option, m::BlackScholes)
33+
evaluate(O::EuropeanOption) = evaluate(O::EuropeanOption, m::BlackScholes)

‎src/models/longstaff_schwartz.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Evaluate option `O` using `LongstaffSchwartz` binomial model.
1414
- `N`: number of paths to simulate
1515
- `P`: number of periods
1616
"""
17-
function evaluate(O::Option, m::LongstaffSchwartz, N::Int64 = 1000, P::Int64 = 10000)
17+
function evaluate(O::AmericanOption, m::LongstaffSchwartz, N::Int64 = 1000, P::Int64 = 10000)
1818
Δt = O.t / N
1919
R = exp(O.r * Δt)
2020
T = typeof(O.s * exp(-O.σ^2 * Δt / 2 + O.σ * Δt * 0.1) / R)

‎test/runtests.jl

+19-16
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
using FinancialDerivatives
22
using Test
33

4-
op = AmericanOption(100.0, 90.0, 0.05, 0.3, 180/365, -1)
5-
oc = AmericanOption(100.0, 90.0, 0.05, 0.3, 180/365, 1)
4+
eu_put = AmericanOption(100.0, 90.0, 0.05, 0.3, 180/365, -1)
5+
eu_call = AmericanOption(100.0, 90.0, 0.05, 0.3, 180/365, 1)
6+
7+
am_put = AmericanOption(100.0, 90.0, 0.05, 0.3, 180/365, -1)
8+
am_call = AmericanOption(100.0, 90.0, 0.05, 0.3, 180/365, 1)
69

710
@testset "Black-Scholes" begin
8-
@test isapprox(evaluate(op, BlackScholes()), 3.22, atol=0.1)
9-
@test isapprox(evaluate(oc, BlackScholes()), 15.42, atol=0.1)
11+
@test isapprox(evaluate(eu_put, BlackScholes()), 3.22, atol=0.1)
12+
@test isapprox(evaluate(eu_call, BlackScholes()), 15.42, atol=0.1)
1013
end
1114

1215
@testset "Cox-Ross-Rubinstein" begin
13-
@test isapprox(evaluate(op, CoxRossRubinstein()), 3.22, atol=0.1)
14-
@test isapprox(evaluate(oc, CoxRossRubinstein()), 15.42, atol=0.1)
16+
@test isapprox(evaluate(am_put, CoxRossRubinstein()), 3.22, atol=0.1)
17+
@test isapprox(evaluate(am_call, CoxRossRubinstein()), 15.42, atol=0.1)
1518
end
1619

1720
@testset "Jarrow-Rudd" begin
18-
@test isapprox(evaluate(op, JarrowRudd()), 3.22, atol=0.25)
19-
@test isapprox(evaluate(oc, JarrowRudd()), 15.42, atol=0.25)
20-
@test isapprox(evaluate(op, JarrowRudd(), false), 3.22, atol=0.25)
21-
@test isapprox(evaluate(oc, JarrowRudd(), false), 15.42, atol=0.25)
21+
@test isapprox(evaluate(am_put, JarrowRudd()), 3.22, atol=0.25)
22+
@test isapprox(evaluate(am_call, JarrowRudd()), 15.42, atol=0.25)
23+
@test isapprox(evaluate(am_put, JarrowRudd(), false), 3.22, atol=0.25)
24+
@test isapprox(evaluate(am_call, JarrowRudd(), false), 15.42, atol=0.25)
2225
end
2326

2427
@testset "Longstaff-Schwartz" begin
25-
@test isapprox(evaluate(op, LongstaffSchwartz()), 3.22, atol=1)
26-
@test isapprox(evaluate(oc, LongstaffSchwartz()), 15.42, atol=1)
28+
@test isapprox(evaluate(am_put, LongstaffSchwartz()), 3.22, atol=1)
29+
@test isapprox(evaluate(am_call, LongstaffSchwartz()), 15.42, atol=1)
2730
end
2831

2932
@testset "Tian" begin
30-
@test isapprox(evaluate(op, Tian()), 5.15, atol=0.25)
31-
@test isapprox(evaluate(oc, Tian()), 11.87, atol=0.25)
33+
@test isapprox(evaluate(am_put, Tian()), 5.15, atol=0.25)
34+
@test isapprox(evaluate(am_call, Tian()), 11.87, atol=0.25)
3235
end
3336

3437
@testset "Garman–Kohlhagen" begin
@@ -45,8 +48,8 @@ ird = InterestRateDerivative(0.01875, 0.20, 0.01, 0.012, 180/365)
4548
end
4649

4750
@testset "Rendleman-Bartter" begin
48-
@test isapprox(evaluate(op, RendlemanBartter()), 3.22, atol=0.25)
49-
@test isapprox(evaluate(oc, RendlemanBartter()), 15.42, atol=0.25)
51+
@test isapprox(evaluate(am_put, RendlemanBartter()), 3.22, atol=0.25)
52+
@test isapprox(evaluate(am_call, RendlemanBartter()), 15.42, atol=0.25)
5053
@test isapprox(evaluate(ird, RendlemanBartter(), 2), [0.2, 0.2, 0.2, 0.2], atol=0.025)
5154
end
5255

0 commit comments

Comments
 (0)
Please sign in to comment.