mirror of
https://github.com/Tomato6966/investment-portfolio-simulator.git
synced 2025-04-07 12:00:35 +02:00
Merge branch 'main' of https://github.com/Tomato6966/investment-portfolio-simulator
This commit is contained in:
commit
4c641701eb
2 changed files with 15 additions and 13 deletions
|
@ -12,8 +12,7 @@ Why this Project?
|
|||
- Portfolio Performance & Value
|
||||
- All assets (except the TTWOR and Portfolio-Value) are scaled by percentage of their price. Thus their referenced, scale is on the right. The referenced scale on the left is only for the portfolio-value
|
||||
|
||||
https://github.com/user-attachments/assets/78b027fa-9883-4813-8086-8b6aa19767de
|
||||
|
||||
https://github.com/user-attachments/assets/4507e102-8dfb-4614-b2ba-938e20e3d97b
|
||||
|
||||
## Features
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { differenceInDays, isAfter, isBefore } from "date-fns";
|
||||
import { isAfter, isBefore } from "date-fns";
|
||||
|
||||
import type { Asset, InvestmentPerformance, PortfolioPerformance } from "../../types";
|
||||
|
||||
|
@ -166,20 +166,23 @@ export const calculateInvestmentPerformance = (assets: Asset[]): PortfolioPerfor
|
|||
: 0;
|
||||
|
||||
// Berechne die jährliche Performance
|
||||
const performancePerAnnoPerformance = (() => {
|
||||
if (!earliestDate || totalInvested === 0) return 0;
|
||||
// const performancePerAnnoPerformance = (() => {
|
||||
// if (!earliestDate || totalInvested === 0) return 0;
|
||||
|
||||
const years = differenceInDays(new Date(), earliestDate) / 365;
|
||||
if (years < 0.01) return 0; // Verhindere Division durch sehr kleine Zahlen
|
||||
// const years = differenceInDays(new Date(), earliestDate) / 365;
|
||||
// if (years < 0.01) return 0; // Verhindere Division durch sehr kleine Zahlen
|
||||
|
||||
// Formel: (1 + r)^n = FV/PV
|
||||
// r = (FV/PV)^(1/n) - 1
|
||||
const totalReturn = totalCurrentValue / totalInvested;
|
||||
const annualizedReturn = Math.pow(totalReturn, 1 / years) - 1;
|
||||
// // Formel: (1 + r)^n = FV/PV
|
||||
// // r = (FV/PV)^(1/n) - 1
|
||||
// const totalReturn = totalCurrentValue / totalInvested;
|
||||
// const annualizedReturn = Math.pow(totalReturn, 1 / years) - 1;
|
||||
|
||||
return annualizedReturn * 100;
|
||||
})();
|
||||
// return annualizedReturn * 100;
|
||||
// })();
|
||||
|
||||
const performancePerAnnoPerformance = annualPerformances.reduce((acc, curr) => acc + curr.percentage, 0) / annualPerformances.length;
|
||||
|
||||
console.log(performancePerAnnoPerformance, annualPerformances);
|
||||
return {
|
||||
investments,
|
||||
summary: {
|
||||
|
|
Loading…
Add table
Reference in a new issue