Skip to content

Commit 30d21ff

Browse files
committed
Integrate Dates (#17)
1 parent 6362187 commit 30d21ff

File tree

5 files changed

+123
-50
lines changed

5 files changed

+123
-50
lines changed

Manifest.toml

+42-22
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# This file is machine-generated - editing it directly is not advised
22

3-
julia_version = "1.10.6"
3+
julia_version = "1.11.1"
44
manifest_format = "2.0"
5-
project_hash = "cdcdfda7ba9b287b3aa8184dac9e588eb8707539"
5+
project_hash = "7345b6c3a11314a9f49e968bcff4c787aa8aa617"
66

77
[[deps.AliasTables]]
88
deps = ["PtrArrays", "Random"]
@@ -12,13 +12,15 @@ version = "1.1.3"
1212

1313
[[deps.ArgTools]]
1414
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
15-
version = "1.1.1"
15+
version = "1.1.2"
1616

1717
[[deps.Artifacts]]
1818
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
19+
version = "1.11.0"
1920

2021
[[deps.Base64]]
2122
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
23+
version = "1.11.0"
2224

2325
[[deps.Compat]]
2426
deps = ["TOML", "UUIDs"]
@@ -49,6 +51,7 @@ version = "0.18.20"
4951
[[deps.Dates]]
5052
deps = ["Printf"]
5153
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
54+
version = "1.11.0"
5255

5356
[[deps.Distributions]]
5457
deps = ["AliasTables", "FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SpecialFunctions", "Statistics", "StatsAPI", "StatsBase", "StatsFuns"]
@@ -79,6 +82,7 @@ version = "1.6.0"
7982

8083
[[deps.FileWatching]]
8184
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
85+
version = "1.11.0"
8286

8387
[[deps.FillArrays]]
8488
deps = ["LinearAlgebra"]
@@ -101,6 +105,7 @@ version = "0.3.25"
101105
[[deps.InteractiveUtils]]
102106
deps = ["Markdown"]
103107
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
108+
version = "1.11.0"
104109

105110
[[deps.IrrationalConstants]]
106111
git-tree-sha1 = "630b497eafcc20001bba38a4651b327dcfc491d2"
@@ -121,16 +126,17 @@ version = "0.6.4"
121126
[[deps.LibCURL_jll]]
122127
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
123128
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
124-
version = "8.4.0+0"
129+
version = "8.6.0+0"
125130

126131
[[deps.LibGit2]]
127132
deps = ["Base64", "LibGit2_jll", "NetworkOptions", "Printf", "SHA"]
128133
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
134+
version = "1.11.0"
129135

130136
[[deps.LibGit2_jll]]
131137
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll"]
132138
uuid = "e37daf67-58a4-590a-8e99-b0245dd2ffc5"
133-
version = "1.6.4+0"
139+
version = "1.7.2+0"
134140

135141
[[deps.LibSSH2_jll]]
136142
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
@@ -139,10 +145,12 @@ version = "1.11.0+1"
139145

140146
[[deps.Libdl]]
141147
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
148+
version = "1.11.0"
142149

143150
[[deps.LinearAlgebra]]
144151
deps = ["Libdl", "OpenBLAS_jll", "libblastrampoline_jll"]
145152
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
153+
version = "1.11.0"
146154

147155
[[deps.LogExpFunctions]]
148156
deps = ["DocStringExtensions", "IrrationalConstants", "LinearAlgebra"]
@@ -162,15 +170,17 @@ version = "0.3.28"
162170

163171
[[deps.Logging]]
164172
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
173+
version = "1.11.0"
165174

166175
[[deps.Markdown]]
167176
deps = ["Base64"]
168177
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
178+
version = "1.11.0"
169179

170180
[[deps.MbedTLS_jll]]
171181
deps = ["Artifacts", "Libdl"]
172182
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
173-
version = "2.28.2+1"
183+
version = "2.28.6+0"
174184

175185
[[deps.Missings]]
176186
deps = ["DataAPI"]
@@ -180,7 +190,7 @@ version = "1.2.0"
180190

181191
[[deps.MozillaCACerts_jll]]
182192
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
183-
version = "2023.1.10"
193+
version = "2023.12.12"
184194

185195
[[deps.NetworkOptions]]
186196
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
@@ -189,7 +199,7 @@ version = "1.2.0"
189199
[[deps.OpenBLAS_jll]]
190200
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
191201
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
192-
version = "0.3.23+4"
202+
version = "0.3.27+1"
193203

194204
[[deps.OpenLibm_jll]]
195205
deps = ["Artifacts", "Libdl"]
@@ -214,9 +224,15 @@ uuid = "90014a1f-27ba-587c-ab20-58faa44d9150"
214224
version = "0.11.31"
215225

216226
[[deps.Pkg]]
217-
deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
227+
deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "Random", "SHA", "TOML", "Tar", "UUIDs", "p7zip_jll"]
218228
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
219-
version = "1.10.0"
229+
version = "1.11.0"
230+
231+
[deps.Pkg.extensions]
232+
REPLExt = "REPL"
233+
234+
[deps.Pkg.weakdeps]
235+
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
220236

221237
[[deps.Preferences]]
222238
deps = ["TOML"]
@@ -227,6 +243,7 @@ version = "1.4.3"
227243
[[deps.Printf]]
228244
deps = ["Unicode"]
229245
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
246+
version = "1.11.0"
230247

231248
[[deps.PtrArrays]]
232249
git-tree-sha1 = "77a42d78b6a92df47ab37e177b2deac405e1c88f"
@@ -245,13 +262,10 @@ version = "2.11.1"
245262
[deps.QuadGK.weakdeps]
246263
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
247264

248-
[[deps.REPL]]
249-
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
250-
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
251-
252265
[[deps.Random]]
253266
deps = ["SHA"]
254267
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
268+
version = "1.11.0"
255269

256270
[[deps.Reexport]]
257271
git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b"
@@ -276,9 +290,7 @@ version = "0.7.0"
276290

277291
[[deps.Serialization]]
278292
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
279-
280-
[[deps.Sockets]]
281-
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
293+
version = "1.11.0"
282294

283295
[[deps.SortingAlgorithms]]
284296
deps = ["DataStructures"]
@@ -289,7 +301,7 @@ version = "1.2.1"
289301
[[deps.SparseArrays]]
290302
deps = ["Libdl", "LinearAlgebra", "Random", "Serialization", "SuiteSparse_jll"]
291303
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
292-
version = "1.10.0"
304+
version = "1.11.0"
293305

294306
[[deps.SpecialFunctions]]
295307
deps = ["IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"]
@@ -304,9 +316,14 @@ version = "2.4.0"
304316
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
305317

306318
[[deps.Statistics]]
307-
deps = ["LinearAlgebra", "SparseArrays"]
319+
deps = ["LinearAlgebra"]
320+
git-tree-sha1 = "ae3bb1eb3bba077cd276bc5cfc337cc65c3075c0"
308321
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
309-
version = "1.10.0"
322+
version = "1.11.1"
323+
weakdeps = ["SparseArrays"]
324+
325+
[deps.Statistics.extensions]
326+
SparseArraysExt = ["SparseArrays"]
310327

311328
[[deps.StatsAPI]]
312329
deps = ["LinearAlgebra"]
@@ -341,7 +358,7 @@ uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
341358
[[deps.SuiteSparse_jll]]
342359
deps = ["Artifacts", "Libdl", "libblastrampoline_jll"]
343360
uuid = "bea87d4a-7f5b-5778-9afe-8cc45184846c"
344-
version = "7.2.1+1"
361+
version = "7.7.0+0"
345362

346363
[[deps.TOML]]
347364
deps = ["Dates"]
@@ -356,13 +373,16 @@ version = "1.10.0"
356373
[[deps.Test]]
357374
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
358375
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
376+
version = "1.11.0"
359377

360378
[[deps.UUIDs]]
361379
deps = ["Random", "SHA"]
362380
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
381+
version = "1.11.0"
363382

364383
[[deps.Unicode]]
365384
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
385+
version = "1.11.0"
366386

367387
[[deps.Zlib_jll]]
368388
deps = ["Libdl"]
@@ -377,7 +397,7 @@ version = "5.11.0+0"
377397
[[deps.nghttp2_jll]]
378398
deps = ["Artifacts", "Libdl"]
379399
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"
380-
version = "1.52.0+1"
400+
version = "1.59.0+0"
381401

382402
[[deps.p7zip_jll]]
383403
deps = ["Artifacts", "Libdl"]

Project.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1313
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1414

1515
[compat]
16-
Distributions = "0.25"
17-
QuadGK = "2.1"
18-
Statistics = "1.1"
19-
Dates = "1.1"
20-
Random = "1.1"
21-
Test = "1.1"
22-
julia = "1.10, 1.11.1"
16+
Distributions = "0.25.113"
17+
QuadGK = "2.11.1"
18+
Statistics = "1.1.0"
19+
Dates = "1.11.0"
20+
Random = "1.1.0"
21+
Test = "1.11.0"
22+
julia = "1.11.1"

src/FinancialDerivatives.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ The `FinancialDerivatives` module provides convenient models for pricing financi
33
"""
44
module FinancialDerivatives
55

6-
import Distributions: cdf, Normal
7-
import Statistics: mean
6+
using Distributions: cdf, Normal
7+
using Statistics: mean
8+
using Dates
89

910
export InterestRateDerivative,
1011
AmericanOption,

src/derivatives.jl

+46-6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ Abstract type for [swaption](https://en.wikipedia.org/wiki/Swaption).
3434
"""
3535
abstract type Swaption <: Derivative end
3636

37+
"Compute the time to expiration in years between two dates."
38+
function time_to_expiration(t0::Date, t1::Date)
39+
τ = t1 - t0
40+
year_days = Dates.value(lastdayofyear(t0)) - Dates.value(firstdayofyear(t0))
41+
return Dates.value(τ) / year_days
42+
end
43+
3744
"""
3845
InterestRateDerivative(k, r, σ, θ, t)
3946
@@ -46,14 +53,20 @@ abstract type Swaption <: Derivative end
4653
- `θ`: long term mean level
4754
- `t`: time interval
4855
"""
49-
@kwdef struct InterestRateDerivative{KT<:Real,RT<:Real,σT<:Real,θT<:Real,TT<:Real}
56+
struct InterestRateDerivative{KT<:Real,RT<:Real,σT<:Real,θT<:Real,TT<:Real}
5057
k::KT
5158
r::RT
5259
σ::σT
5360
θ::θT
5461
t::TT
5562
end
5663

64+
"Construct `InterestRateDerivative` with parameters and start `t0` and final `t1` `Date`s."
65+
function InterestRateDerivative(; k::Real, r::Real, σ::Real, θ::Real, t0::Date, t1::Date)
66+
t = time_to_expiration(t0, t1)
67+
return InterestRateDerivative(k, r, σ, θ, t)
68+
end
69+
5770
"""
5871
AmericanOption(s, k, r, σ, t, call)
5972
@@ -67,7 +80,7 @@ end
6780
- `t`: time to expiration
6881
- `call`: `true` if call, `false` if put
6982
"""
70-
@kwdef struct AmericanOption{ST<:Real,KT<:Real,RT<:Real,σT<:Real,TT<:Real} <: Option
83+
struct AmericanOption{ST<:Real,KT<:Real,RT<:Real,σT<:Real,TT<:Real} <: Option
7184
s::ST
7285
k::KT
7386
r::RT
@@ -76,6 +89,13 @@ end
7689
call::Bool
7790
end
7891

92+
"Construct [`AmericanOption`](@ref) with issue `t0` and expiry `t1` `Date`s."
93+
function AmericanOption(; s::Real, k::Real, r::Real, σ::Real, t0::Date, t1::Date,
94+
call::Bool)
95+
t = time_to_expiration(t0, t1)
96+
return AmericanOption(s, k, r, σ, t, call)
97+
end
98+
7999
"""
80100
AsianOption(s, k, r, σ, t, call)
81101
@@ -89,7 +109,7 @@ end
89109
- `t`: time to expiration
90110
- `call`: `true` if call, `false` if put
91111
"""
92-
@kwdef struct AsianOption{ST<:Real,KT<:Real,RT<:Real,σT<:Real,TT<:Real} <: Option
112+
struct AsianOption{ST<:Real,KT<:Real,RT<:Real,σT<:Real,TT<:Real} <: Option
93113
s::ST
94114
k::KT
95115
r::RT
@@ -98,6 +118,12 @@ end
98118
call::Bool
99119
end
100120

121+
"Construct [`AsianOption`](@ref) with issue `t0` and expiry `t1` `Date`s."
122+
function AsianOption(; s::Real, k::Real, r::Real, σ::Real, t0::Date, t1::Date, call::Bool)
123+
t = time_to_expiration(t0, t1)
124+
return AsianOption(s, k, r, σ, t, call)
125+
end
126+
101127
"""
102128
EuropeanOption(s, k, r, σ, t, call)
103129
@@ -112,8 +138,8 @@ end
112138
- `t`: time to expiration
113139
- `call`: `true` if call, `false` if put
114140
"""
115-
@kwdef struct EuropeanOption{ST<:Real,KT<:Real,RT<:Real,QT<:Real,σT<:Real,TT<:Real} <:
116-
Option
141+
struct EuropeanOption{ST<:Real,KT<:Real,RT<:Real,QT<:Real,σT<:Real,TT<:Real} <:
142+
Option
117143
s::ST
118144
k::KT
119145
r::RT
@@ -123,6 +149,13 @@ end
123149
call::Bool
124150
end
125151

152+
"Construct [`EuropeanOption`](@ref) with issue `t0` and expiry `t1` `Date`s."
153+
function EuropeanOption(; s::Real, k::Real, r::Real, q::Real, σ::Real, t0::Date, t1::Date,
154+
call::Bool)
155+
t = time_to_expiration(t0, t1)
156+
return EuropeanOption(s, k, r, q, σ, t, call)
157+
end
158+
126159
"""
127160
FXOption(s, k, r_d, r_f, σ, t, call)
128161
@@ -137,7 +170,7 @@ end
137170
- `t`: time to expiration
138171
- `call`: `true` if call, `false` if put
139172
"""
140-
@kwdef struct FXOption{ST<:Real,KT<:Real,RDT<:Real,RFT<:Real,σT<:Real,TT<:Real} <: Option
173+
struct FXOption{ST<:Real,KT<:Real,RDT<:Real,RFT<:Real,σT<:Real,TT<:Real} <: Option
141174
s::ST
142175
k::KT
143176
r_d::RDT
@@ -146,3 +179,10 @@ end
146179
t::TT
147180
call::Bool
148181
end
182+
183+
"Construct [`FXOption`](@ref) with issue `t0` and expiry `t1` `Date`s."
184+
function FXOption(; s::Real, k::Real, r_d::Real, r_f::Real, σ::Real, t0::Date, t1::Date,
185+
call::Bool)
186+
t = time_to_expiration(t0, t1)
187+
return FXOption(s, k, r_d, r_f, σ, t, call)
188+
end

0 commit comments

Comments
 (0)