Created
May 28, 2021 09:09
-
-
Save LefterisJP/742086b82d2524bc19c02361a4be80d5 to your computer and use it in GitHub Desktop.
test_cdp_calculations.py
This file contains hidden or 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
import argparse | |
from typing import NamedTuple | |
from rotkehlchen.constants.assets import A_ETH, A_USD | |
from rotkehlchen.externalapis.coingecko import Coingecko | |
from rotkehlchen.fval import FVal | |
class VaultType(NamedTuple): | |
name: str | |
min_collateral_ratio: FVal | |
stability_fee: FVal | |
def max_debt(self, collateral_value: FVal) -> FVal: | |
return collateral_value / self.min_collateral_ratio | |
def safe_debt(self, collateral_value: FVal, max_price_drop: FVal) -> FVal: | |
target_collateralization_ratio = (FVal(100) - max_price_drop) / 100 * self.min_collateral_ratio | |
return collateral_value / target_collateralization_ratio | |
def net_income(self, collateral_value: FVal, max_price_drop: FVal, working_apy: FVal) -> FVal: | |
safe_debt = self.safe_debt(collateral_value, max_price_drop) | |
net_apy = working_apy - self.stability_fee | |
net_income = net_apy * safe_debt | |
print(f'{self.name} net income for a max {max_price_drop}% price drop with working apy {working_apy * 100}% and net apy {net_apy * 100}% is {net_income} USD') | |
return net_income | |
ETH_A = VaultType( | |
name='ETH-A', | |
min_collateral_ratio=FVal('1.5'), | |
stability_fee=FVal('0.055'), | |
) | |
ETH_C = VaultType( | |
name='ETH-C', | |
min_collateral_ratio=FVal('1.75'), | |
stability_fee=FVal('0.03'), | |
) | |
def parse_args(): | |
p = argparse.ArgumentParser( | |
prog='CDP Calculator', | |
description='Calculate some stats on CDP loans', | |
) | |
p.add_argument( | |
'--working-apy', | |
help='The APY our debt can work with', | |
) | |
p.add_argument( | |
'--eth-amount', | |
help='The ETH amount we have available', | |
) | |
p.add_argument( | |
'--max-price-drop', | |
help='The max price drop needed to liquidate the CDP in %', | |
) | |
return p.parse_args() | |
def compare(args): | |
working_apy = FVal(args.working_apy) / FVal(100) | |
eth_amount = FVal(args.eth_amount) | |
max_price_drop = FVal(args.max_price_drop) | |
coingecko = Coingecko() | |
eth_price = coingecko.query_current_price(A_ETH, A_USD) | |
collateral_value = eth_amount * eth_price | |
etha = ETH_A.net_income(collateral_value, max_price_drop, working_apy) | |
ethc = ETH_C.net_income(collateral_value, max_price_drop, working_apy) | |
def main(): | |
args = parse_args() | |
compare(args) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment