Skip to content

Instantly share code, notes, and snippets.

@JohannSuarez
Created November 9, 2021 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohannSuarez/ef199111477dadf53d00d7c9237caa47 to your computer and use it in GitHub Desktop.
Save JohannSuarez/ef199111477dadf53d00d7c9237caa47 to your computer and use it in GitHub Desktop.
Incrementing Continuous Compound Interest
'''
Suppose I spend $20,000 on a mining rig, and it mines $120 worth of crypto each day.
We then consistently stake its daily revenue into a yield farming platform at a rate of 12% per year,
with the yield immediately claimed and restaked.
How much money would we make after n days?
At what day do we break even? (Assuming we're not paying for maintenance or electric bill)
'''
from typing import List
import pandas as pd
def incremental_continuous_compound(daily_mine_revenue: float, days_elapsed: int):
'''
Each day I get daily_mine_revenue and
I stake it to a pool at 12% per annum.
'''
interest_rate: float = 0.12 # 12 percent
compound_frequency: int = 365 # number of times interest applied per time period per annum (so that's daily)
balance: float = 0 # This is supposed to be the principal, but we add to it daily.
pure_yield_profit: float = 0 # Amount earned solely from the yield farming activity
# These lists will be ever-expanding.
pure_yield_profit_log: List[float] = []
staking_yield_by_day: List[float] = []
total_balance_log: List[float] = []
for i in range(days_elapsed):
day_yield = balance * ( interest_rate / compound_frequency)
pure_yield_profit += day_yield
balance += daily_mine_revenue + day_yield
# Building the dataframe columns
pure_yield_profit_log.append(pure_yield_profit)
staking_yield_by_day.append(day_yield)
total_balance_log.append(balance)
return pd.DataFrame(zip(pure_yield_profit_log,
staking_yield_by_day,
total_balance_log),
columns=['Yield Profit Total', 'Yield Amount of The Day', 'Total Profit'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment