-
-
Save AHaliq/2a7525e78af55c575aa1f0d04d18d00d to your computer and use it in GitHub Desktop.
Compound Stake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rate[x_] := rated[x*365] | |
rated[x_] := | |
If[x < 7, 1.5, | |
If[x < 30.4167, 3, If[x < 365/2, 5, If[x < 365, 17, 30]]]] | |
f[ip_, r_, p_, t_, n_] := | |
If[t <= 0, ip, | |
If[t < p, ip + ip*r*t - rate[t], | |
f[ip + (ip * r * p) - rate[p] - rate[0]*n, r, p, (t - p), n + 1]]] | |
g[ip_, r_, t_] := ip + ip*r*t - rate[t] | |
init := 10000 | |
apy := 0.159 | |
ri := 1/365 | |
t := 1 | |
precs := 365*2 | |
Manipulate[ | |
Function[{m}, | |
Plot[{f[init, apy, x, t, 0], g[init, apy, t]}, {x, ri, t}, | |
Filling -> {1 -> {2}}, | |
PlotRange -> Automatic, | |
AxesLabel -> {"years", | |
"peak : " <> ToString[N[m[[1]]*365]] <> "days"}, | |
GridLines -> {{{ m[[1]], Red}}, {{m[[2]], Red}}} | |
] | |
] | |
[Fold[If[#1[[2]] > #2[[2]], #1, #2] &, {#, | |
f[init, apy, #, t, 0]} & /@ (#/precs & /@ Range[1, precs])]] | |
, {{init, 10000}, 10, 500000}, {{apy, 0.156}, 0.01, 1}, {{t, 1}, | |
0.01, 10}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment