Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change recession #35

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RetirementPlanners"
uuid = "2683bf95-d0b8-4c71-a7d3-b42f78bf1cf0"
authors = ["itsdfish"]
version = "0.4.5"
version = "0.5.0"

[deps]
ConcreteStructs = "2569d6c7-a4a2-43d3-a901-331e8e4be471"
Expand Down
3 changes: 1 addition & 2 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ config = (
ασᵣ = 0.035,
ησᵣ = 0.010
),
# recession: age => duration
recessions = Dict(0 => 0)
recessions = Transaction(; start_age = 0, end_age = 0)
),
# inflation parameters
kw_inflation = (gbm = VarGBM(; αμ = 0.035, ημ = 0.005, ασ = 0.005, ησ = 0.0025),),
Expand Down
6 changes: 2 additions & 4 deletions docs/src/advanced_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ config = (
ασᵣ = 0.035,
ησᵣ = 0.010
),
# recession: age => duration
recessions = Dict(0 => 0)
recessions = Transaction(; start_age = 0, end_age = 0)
),
# inflation parameters
kw_inflation = (gbm = VarGBM(; αμ = 0.035, ημ = 0.005, ασ = 0.005, ησ = 0.0025),),
Expand Down Expand Up @@ -299,8 +298,7 @@ config = (
ασᵣ = 0.035,
ησᵣ = 0.010
),
# recession: age => duration
recessions = Dict(0 => 0)
recessions = Transaction(; start_age = 0, end_age = 0)
),
# inflation parameters
kw_inflation = (gbm = VarGBM(; αμ = 0.035, ημ = 0.005, ασ = 0.005, ησ = 0.0025),),
Expand Down
6 changes: 2 additions & 4 deletions docs/src/plotting.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ config = (
ασᵣ = 0.035,
ησᵣ = 0.010
),
# recession: age => duration
recessions = Dict(0 => 0)
recessions = Transaction(; start_age = 0, end_age = 0)
),
# inflation parameters
kw_inflation = (gbm = VarGBM(; αμ = 0.035, ημ = 0.005, ασ = 0.005, ησ = 0.0025),),
Expand Down Expand Up @@ -314,8 +313,7 @@ config = (
ασᵣ = 0.035,
ησᵣ = 0.010
),
# recession: age => duration
recessions = Dict(0 => 0)
Transaction(; start_age = 0, end_age = 0)
),
# inflation parameters
kw_inflation = (gbm = VarGBM(; αμ = 0.035, ημ = 0.005, ασ = 0.005, ησ = 0.0025),),
Expand Down
22 changes: 16 additions & 6 deletions src/distributions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,30 @@ Increment the stock price over the period `Δt`.
"""
function increment!(dist::AbstractGBM; Δt, t = 0, kwargs...)
(; x) = dist
μ′, σ′ = modify(dist, t; kwargs...)
μ′, σ′ = modify(dist, t; Δt, kwargs...)
dist.x += x * (μ′ * Δt + σ′ * randn() * √(Δt))
return nothing
end

function modify(dist::AbstractGBM, t; recessions = nothing)
function modify(dist::AbstractGBM, t; Δt, recessions = nothing)
(; μ, μᵣ, σ, σᵣ) = dist
isnothing(recessions) ? (return μ, σ) : nothing
for (start_time, duration) ∈ recessions
if (t ≥ start_time) && (t < (start_time + duration))
return μᵣ, σᵣ
if _modify!(dist, recessions, t, Δt)
return μᵣ, σᵣ
end
return μ, σ
end

_modify!(::AbstractGBM, recession::AbstractTransaction, t, Δt) =
can_transact(recession, t; Δt)

function _modify!(dist::AbstractGBM, recessions, t, Δt)
for recession ∈ recessions
if _modify!(dist, recession, t, Δt)
return true
end
end
return return μ, σ
return false
end

"""
Expand Down
6 changes: 3 additions & 3 deletions src/structs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,19 @@ Specifies the time range and amount of a transaction.

- `start_age = 0.0`: the age at which a series of transactions begin
- `end_age = Inf`: the age at which a series of transactions end
- `amount`: the amount of each transaction
- `amount = 0`: the amount of each transaction

# Constructor

Transaction(; start_age = 0.0, end_age = Inf, amount)
Transaction(; start_age = 0.0, end_age = Inf, amount = 0)
"""
struct Transaction{T, D} <: AbstractTransaction{T, D}
start_age::T
end_age::T
amount::D
end

function Transaction(; start_age = 0.0, end_age = Inf, amount)
function Transaction(; start_age = 0.0, end_age = Inf, amount = 0)
return Transaction(promote(start_age, end_age)..., amount)
end

Expand Down
8 changes: 4 additions & 4 deletions test/distributions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
μᵣ = -0.10
σᵣ = 0.01
dist = GBM(; μ, σ, μᵣ, σᵣ, x0 = 1)
recessions = Dict(1 => 1)
recessions = Transaction(; start_age = 1, end_age = 2, amount = 0)

increment!(dist; t = 1, Δt, recessions)
@test dist.x ≈ 0.90 atol = 1e-2
Expand All @@ -57,7 +57,7 @@
μᵣ = -0.10
σᵣ = 0.01
dist = GBM(; μ, σ, μᵣ, σᵣ, x0 = 1)
recessions = Dict(1 => 1)
recessions = Transaction(; start_age = 1, end_age = 2, amount = 0)

increment!(dist; t = 0, Δt, recessions)
@test dist.x ≈ 1.10 atol = 1e-2
Expand All @@ -76,9 +76,9 @@
μᵣ = -0.10
σᵣ = 0.001
dist = GBM(; μ, σ, μᵣ, σᵣ, x0 = 1)
recessions = Dict(1 => 1)
recessions = Transaction(; start_age = 1, end_age = 2, amount = 0)

increment!(dist; t = 2, Δt, recessions)
increment!(dist; t = 2 + Δt / 2 + 2eps(), Δt, recessions)
@test dist.x ≈ 1.1 atol = 1e-2
end
end
Expand Down
Loading