Skip to content

Commit

Permalink
fix withdraw and nominalamount
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdfish committed May 18, 2024
1 parent 4940296 commit 594d9d6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
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.1"
version = "0.4.2"

[deps]
ConcreteStructs = "2569d6c7-a4a2-43d3-a901-331e8e4be471"
Expand Down
2 changes: 1 addition & 1 deletion src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function transact(
income.amount.adjust ? nothing : (return income.amount.amount)
(; Δt, state, start_age) = model
(; amount) = income
amount.amount = start_age t ? (amount.initial_amount) : amount.amount
amount.amount = (start_age + Δt) t ? (amount.initial_amount) : amount.amount
r = (1 + state.inflation_rate)^Δt
amount.amount /= r
return amount.amount
Expand Down
9 changes: 5 additions & 4 deletions src/update_functions/withdraw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ end
function _withdraw!(model::AbstractModel, t, withdraw::AbstractTransaction)
(; Δt) = model
if can_transact(withdraw, t; Δt)
model.state.withdraw_amount += transact(model, withdraw; t)
withdraw_amount = transact(model, withdraw; t)
if model.state.net_worth < withdraw_amount
withdraw_amount = model.state.net_worth
end
model.state.withdraw_amount += withdraw_amount
end
return nothing
end
Expand Down Expand Up @@ -63,8 +67,5 @@ function transact(
withdraw_amount = max(withdraw_amount, min_withdraw)
withdraw_amount =
max(withdraw_amount - state.income_amount * income_adjustment, 0)
if state.net_worth < withdraw_amount
withdraw_amount = state.net_worth
end
return withdraw_amount
end
4 changes: 2 additions & 2 deletions test/transaction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
amount = transact(model, transaction; t = 2)
@test amount 100 / 1.03^(2 / 12) atol = 1e-10

# reset amount
amount = transact(model, transaction; t = 1)
# reset amount (recorded time starts at start_time + Δt)
amount = transact(model, transaction; t = 1 + 1 / 12)
@test amount 100 / 1.03^(1 / 12) atol = 1e-10
end

Expand Down

0 comments on commit 594d9d6

Please sign in to comment.