Created
June 9, 2021 22:23
-
-
Save galo2099/986deeed17cc3cbde6c1e3bc2ee73cdc to your computer and use it in GitHub Desktop.
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
def calc_derivative(principal, apr, gas, t=days_between_compounds): | |
return (principal*((-gas/principal) + ((apr/100)/365) * t + 1)(365/t)) * ( ((apr/100)/( t( (-gas/principal) + t(apr/100)/365 + 1) )) - (365np.log( (-gas/principal) + t(apr/100)/365 + 1))/t2 ) | |
def calc_final_value(principal, apr, gas, num_days): | |
return principal(1+(num_days(apr/100)/365 - gas/principal))**(365/num_days) | |
def find_ideal_compound_rate(principal, apr, gas): | |
der = 99999999999999999 | |
ideal_days = 365 | |
for days in np.arange(0.5,365.25,.25): | |
der_test = calc_derivative(principal, apr, gas, days) | |
if (abs(der_test)<der) and (calc_final_value(principal, apr, gas, days) > calc_final_value(principal, apr, gas, days-0.25)) and (calc_final_value(principal, apr, gas, days) > calc_final_value(principal, apr, gas, days+0.25)): | |
### the above tests to make sure the derivative is a maximum and not a minimum point | |
der = abs(der_test) | |
ideal_days=days | |
return(ideal_days) | |
def accumulate_funds(principal, apr, gas): | |
""" | |
principal is in dollars | |
apr is in % so 283% --> 283 | |
gas cost is in dollars | |
returns a print of when to compound | |
""" | |
wen = [] | |
starting_funds = principal | |
days_of_trial = 0 | |
num_compounds=0 | |
final_monies=0 | |
price = 1 ###used to deteriorate ALCX price | |
price_end_percent = 1 ### use this if you want to have ALCX price deteriorate | |
price_depr = (1-price_end_percent)/365 | |
dep_APR = 1 # Use this to depreciate the ALCX emissions rate and hence the APR | |
while days_of_trial < 365: | |
days_between_compounds = find_ideal_compound_rate(principal, apr, gas) | |
prior_compound = days_of_trial | |
prior_value = final_monies | |
days_of_trial+=days_between_compounds | |
final_monies = principal+(principal*(days_between_compounds * (apr/365.)/100.) - gas)price | |
period_rewards = (principal(days_between_compounds * (apr/365.)/100.) )price | |
wen.append([days_of_trial, round(final_monies,2), round((principal(days_between_compounds * (apr/365.)/100.) )price,2)]) | |
print(f"Day of Compound: {days_of_trial:6.2f} Value: ${final_monies:10.2f} Rewards Earned: {period_rewards:8.2f}, APR: {apr:6.2f}")### Amount Compounded: {(principaldays_between_compounds*(apr/365)/100 - gas):8.2f}" ) | |
principal = final_monies | |
num_compounds+=1 | |
year_money = prior_value + ( (365-prior_compound)/(days_of_trial-prior_compound) ) * (final_monies-prior_value) | |
price = price-(price_depr*days_between_compounds) | |
apr = apr * dep_APR | |
print(f'\nSelf-compound APY = {100*((year_money-starting_funds)/starting_funds):.2f}%') | |
#return wen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment