mirror of
https://github.com/Tomato6966/investment-portfolio-simulator.git
synced 2025-04-12 08:28:41 +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
|
- 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
|
- 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
|
## 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";
|
import type { Asset, InvestmentPerformance, PortfolioPerformance } from "../../types";
|
||||||
|
|
||||||
|
@ -166,20 +166,23 @@ export const calculateInvestmentPerformance = (assets: Asset[]): PortfolioPerfor
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
// Berechne die jährliche Performance
|
// Berechne die jährliche Performance
|
||||||
const performancePerAnnoPerformance = (() => {
|
// const performancePerAnnoPerformance = (() => {
|
||||||
if (!earliestDate || totalInvested === 0) return 0;
|
// if (!earliestDate || totalInvested === 0) return 0;
|
||||||
|
|
||||||
const years = differenceInDays(new Date(), earliestDate) / 365;
|
// const years = differenceInDays(new Date(), earliestDate) / 365;
|
||||||
if (years < 0.01) return 0; // Verhindere Division durch sehr kleine Zahlen
|
// if (years < 0.01) return 0; // Verhindere Division durch sehr kleine Zahlen
|
||||||
|
|
||||||
// Formel: (1 + r)^n = FV/PV
|
// // Formel: (1 + r)^n = FV/PV
|
||||||
// r = (FV/PV)^(1/n) - 1
|
// // r = (FV/PV)^(1/n) - 1
|
||||||
const totalReturn = totalCurrentValue / totalInvested;
|
// const totalReturn = totalCurrentValue / totalInvested;
|
||||||
const annualizedReturn = Math.pow(totalReturn, 1 / years) - 1;
|
// 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 {
|
return {
|
||||||
investments,
|
investments,
|
||||||
summary: {
|
summary: {
|
||||||
|
|
Loading…
Add table
Reference in a new issue