Last active
June 21, 2025 06:36
-
-
Save sadiqsalau/e19f938c78b5387e6691458b2232b7da to your computer and use it in GitHub Desktop.
AI Earn - TP Calculator
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 INITIAL_CAPITAL = 100; | |
const DAYS = 30; | |
/** Static */ | |
const REINVEST = true; | |
const PERCENTAGE = 0.04; | |
const INVESTMENT_DURATION = 30; | |
const getDate = (i = 0) => | |
new Date(Date.now() + i * 1000 * 60 * 60 * 24).toDateString(); | |
let investments = [ | |
{ | |
amount: INITIAL_CAPITAL, | |
start: 1, | |
ends: INVESTMENT_DURATION, | |
startDate: getDate(), | |
endDate: getDate(INVESTMENT_DURATION), | |
}, | |
]; | |
let balance = 0; | |
let tp = 0; | |
for (let i = 1; i <= DAYS; i++) { | |
investments = investments.filter((item) => item.ends >= i); | |
tp = investments.reduce((result, item) => result + item.amount, 0); | |
balance += PERCENTAGE * tp; | |
if (REINVEST && balance >= 1) { | |
investments.push({ | |
amount: balance, | |
start: i, | |
ends: i + INVESTMENT_DURATION, | |
startDate: getDate(i), | |
endDate: getDate(i + INVESTMENT_DURATION), | |
}); | |
balance = 0; | |
} | |
} | |
console.table(investments); | |
console.log("TP:", tp); | |
console.log("Balance:", balance); | |
console.log("Profit Per Day:", PERCENTAGE * tp); | |
let profit = 0; | |
let lastDate; | |
for (let i = DAYS + 1; ; i++) { | |
investments = investments.filter((item) => item.ends >= i); | |
if (!investments.length) { | |
lastDate = getDate(i - 1); | |
break; | |
} | |
tp = investments.reduce((result, item) => result + item.amount, 0); | |
profit += PERCENTAGE * tp; | |
} | |
console.log("Total Profit:", profit); | |
console.log("Last Date:", lastDate); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment