Created
August 19, 2021 19:28
-
-
Save larry0x/300534035b097d79f71b2aa2d017b335 to your computer and use it in GitHub Desktop.
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
const MONTHLY_PAYMENT = 558; | |
const BORROW_APR = 0.2607; | |
const REWARD_APR = 0.446; | |
const TARGET_LTV = 0.3; | |
const ETH_STAKING_APR = 0.0483; | |
let collateral = 100000; | |
let debt = 30000; | |
let cost = 0; | |
for (let month = 1; debt > 0; month++) { | |
const interest = (debt * BORROW_APR) / 12; | |
const reward = (debt * REWARD_APR) / 12; | |
debt += interest - reward; | |
if (debt > MONTHLY_PAYMENT) { | |
cost += MONTHLY_PAYMENT; | |
debt -= MONTHLY_PAYMENT; | |
} else { | |
cost += debt; | |
debt = 0; | |
} | |
cost += (collateral * ETH_STAKING_APR) / 12; | |
collateral = debt / TARGET_LTV; | |
console.log( | |
`month ${month},`, | |
`debt: $${debt.toFixed(2)},`, | |
`cost: $${cost.toFixed(2)}` | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment