Skip to content

Commit 7a8b033

Browse files
authored
Merge pull request #35 from itsdfish/dev
change recession
2 parents 6c1b914 + fcb8dc5 commit 7a8b033

File tree

7 files changed

+29
-24
lines changed

7 files changed

+29
-24
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RetirementPlanners"
22
uuid = "2683bf95-d0b8-4c71-a7d3-b42f78bf1cf0"
33
authors = ["itsdfish"]
4-
version = "0.4.5"
4+
version = "0.5.0"
55

66
[deps]
77
ConcreteStructs = "2569d6c7-a4a2-43d3-a901-331e8e4be471"

benchmark/benchmarks.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ config = (
5151
ασᵣ = 0.035,
5252
ησᵣ = 0.010
5353
),
54-
# recession: age => duration
55-
recessions = Dict(0 => 0)
54+
recessions = Transaction(; start_age = 0, end_age = 0)
5655
),
5756
# inflation parameters
5857
kw_inflation = (gbm = VarGBM(; αμ = 0.035, ημ = 0.005, ασ = 0.005, ησ = 0.0025),),

docs/src/advanced_example.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ config = (
7171
ασᵣ = 0.035,
7272
ησᵣ = 0.010
7373
),
74-
# recession: age => duration
75-
recessions = Dict(0 => 0)
74+
recessions = Transaction(; start_age = 0, end_age = 0)
7675
),
7776
# inflation parameters
7877
kw_inflation = (gbm = VarGBM(; αμ = 0.035, ημ = 0.005, ασ = 0.005, ησ = 0.0025),),
@@ -299,8 +298,7 @@ config = (
299298
ασᵣ = 0.035,
300299
ησᵣ = 0.010
301300
),
302-
# recession: age => duration
303-
recessions = Dict(0 => 0)
301+
recessions = Transaction(; start_age = 0, end_age = 0)
304302
),
305303
# inflation parameters
306304
kw_inflation = (gbm = VarGBM(; αμ = 0.035, ημ = 0.005, ασ = 0.005, ησ = 0.0025),),

docs/src/plotting.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ config = (
6565
ασᵣ = 0.035,
6666
ησᵣ = 0.010
6767
),
68-
# recession: age => duration
69-
recessions = Dict(0 => 0)
68+
recessions = Transaction(; start_age = 0, end_age = 0)
7069
),
7170
# inflation parameters
7271
kw_inflation = (gbm = VarGBM(; αμ = 0.035, ημ = 0.005, ασ = 0.005, ησ = 0.0025),),
@@ -314,8 +313,7 @@ config = (
314313
ασᵣ = 0.035,
315314
ησᵣ = 0.010
316315
),
317-
# recession: age => duration
318-
recessions = Dict(0 => 0)
316+
Transaction(; start_age = 0, end_age = 0)
319317
),
320318
# inflation parameters
321319
kw_inflation = (gbm = VarGBM(; αμ = 0.035, ημ = 0.005, ασ = 0.005, ησ = 0.0025),),

src/distributions.jl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,30 @@ Increment the stock price over the period `Δt`.
8181
"""
8282
function increment!(dist::AbstractGBM; Δt, t = 0, kwargs...)
8383
(; x) = dist
84-
μ′, σ′ = modify(dist, t; kwargs...)
84+
μ′, σ′ = modify(dist, t; Δt, kwargs...)
8585
dist.x += x * (μ′ * Δt + σ′ * randn() * (Δt))
8686
return nothing
8787
end
8888

89-
function modify(dist::AbstractGBM, t; recessions = nothing)
89+
function modify(dist::AbstractGBM, t; Δt, recessions = nothing)
9090
(; μ, μᵣ, σ, σᵣ) = dist
9191
isnothing(recessions) ? (return μ, σ) : nothing
92-
for (start_time, duration) recessions
93-
if (t start_time) && (t < (start_time + duration))
94-
return μᵣ, σᵣ
92+
if _modify!(dist, recessions, t, Δt)
93+
return μᵣ, σᵣ
94+
end
95+
return μ, σ
96+
end
97+
98+
_modify!(::AbstractGBM, recession::AbstractTransaction, t, Δt) =
99+
can_transact(recession, t; Δt)
100+
101+
function _modify!(dist::AbstractGBM, recessions, t, Δt)
102+
for recession recessions
103+
if _modify!(dist, recession, t, Δt)
104+
return true
95105
end
96106
end
97-
return return μ, σ
107+
return false
98108
end
99109

100110
"""

src/structs.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,19 @@ Specifies the time range and amount of a transaction.
250250
251251
- `start_age = 0.0`: the age at which a series of transactions begin
252252
- `end_age = Inf`: the age at which a series of transactions end
253-
- `amount`: the amount of each transaction
253+
- `amount = 0`: the amount of each transaction
254254
255255
# Constructor
256256
257-
Transaction(; start_age = 0.0, end_age = Inf, amount)
257+
Transaction(; start_age = 0.0, end_age = Inf, amount = 0)
258258
"""
259259
struct Transaction{T, D} <: AbstractTransaction{T, D}
260260
start_age::T
261261
end_age::T
262262
amount::D
263263
end
264264

265-
function Transaction(; start_age = 0.0, end_age = Inf, amount)
265+
function Transaction(; start_age = 0.0, end_age = Inf, amount = 0)
266266
return Transaction(promote(start_age, end_age)..., amount)
267267
end
268268

test/distributions.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
μᵣ = -0.10
3939
σᵣ = 0.01
4040
dist = GBM(; μ, σ, μᵣ, σᵣ, x0 = 1)
41-
recessions = Dict(1 => 1)
41+
recessions = Transaction(; start_age = 1, end_age = 2, amount = 0)
4242

4343
increment!(dist; t = 1, Δt, recessions)
4444
@test dist.x 0.90 atol = 1e-2
@@ -57,7 +57,7 @@
5757
μᵣ = -0.10
5858
σᵣ = 0.01
5959
dist = GBM(; μ, σ, μᵣ, σᵣ, x0 = 1)
60-
recessions = Dict(1 => 1)
60+
recessions = Transaction(; start_age = 1, end_age = 2, amount = 0)
6161

6262
increment!(dist; t = 0, Δt, recessions)
6363
@test dist.x 1.10 atol = 1e-2
@@ -76,9 +76,9 @@
7676
μᵣ = -0.10
7777
σᵣ = 0.001
7878
dist = GBM(; μ, σ, μᵣ, σᵣ, x0 = 1)
79-
recessions = Dict(1 => 1)
79+
recessions = Transaction(; start_age = 1, end_age = 2, amount = 0)
8080

81-
increment!(dist; t = 2, Δt, recessions)
81+
increment!(dist; t = 2 + Δt / 2 + 2eps(), Δt, recessions)
8282
@test dist.x 1.1 atol = 1e-2
8383
end
8484
end

0 commit comments

Comments
 (0)