This commit is contained in:
Boki 2025-06-11 10:35:15 -04:00
parent d85cd58acd
commit 597c6efc9b
91 changed files with 2224 additions and 1400 deletions

View file

@ -7,7 +7,7 @@
* Calculate percentage change between two values
*/
export function percentageChange(oldValue: number, newValue: number): number {
if (oldValue === 0) return 0;
if (oldValue === 0) {return 0;}
return ((newValue - oldValue) / oldValue) * 100;
}
@ -15,7 +15,7 @@ export function percentageChange(oldValue: number, newValue: number): number {
* Calculate simple return
*/
export function simpleReturn(initialPrice: number, finalPrice: number): number {
if (initialPrice === 0) return 0;
if (initialPrice === 0) {return 0;}
return (finalPrice - initialPrice) / initialPrice;
}
@ -23,7 +23,7 @@ export function simpleReturn(initialPrice: number, finalPrice: number): number {
* Calculate logarithmic return
*/
export function logReturn(initialPrice: number, finalPrice: number): number {
if (initialPrice <= 0 || finalPrice <= 0) return 0;
if (initialPrice <= 0 || finalPrice <= 0) {return 0;}
return Math.log(finalPrice / initialPrice);
}
@ -31,7 +31,7 @@ export function logReturn(initialPrice: number, finalPrice: number): number {
* Calculate compound annual growth rate (CAGR)
*/
export function cagr(startValue: number, endValue: number, years: number): number {
if (years <= 0 || startValue <= 0 || endValue <= 0) return 0;
if (years <= 0 || startValue <= 0 || endValue <= 0) {return 0;}
return Math.pow(endValue / startValue, 1 / years) - 1;
}
@ -91,8 +91,8 @@ export function internalRateOfReturn(
dnpv += (-j * cashFlows[j]) / Math.pow(1 + rate, j + 1);
}
if (Math.abs(npv) < 1e-10) break;
if (Math.abs(dnpv) < 1e-10) break;
if (Math.abs(npv) < 1e-10) {break;}
if (Math.abs(dnpv) < 1e-10) {break;}
rate = rate - npv / dnpv;
}
@ -186,7 +186,7 @@ export function bondYield(
);
const diff = calculatedPrice - price;
if (Math.abs(diff) < tolerance) break;
if (Math.abs(diff) < tolerance) {break;}
// Numerical derivative
const delta = 0.0001;
@ -199,7 +199,7 @@ export function bondYield(
);
const derivative = (priceUp - calculatedPrice) / delta;
if (Math.abs(derivative) < tolerance) break;
if (Math.abs(derivative) < tolerance) {break;}
yield_ = yield_ - diff / derivative;
}
@ -358,7 +358,7 @@ export function dividendDiscountModel(
growthRate: number,
discountRate: number
): number {
if (discountRate <= growthRate) return NaN; // Indeterminate
if (discountRate <= growthRate) {return NaN;} // Indeterminate
return (currentDividend * (1 + growthRate)) / (discountRate - growthRate);
}