Browse Source

Refactoring

pull/5650/head
Thomas Kaul 1 week ago
parent
commit
40e7d13aa2
  1. 23
      apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-cash.spec.ts
  2. 4
      apps/api/src/app/portfolio/portfolio.service.ts

23
apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-cash.spec.ts

@ -207,20 +207,19 @@ describe('PortfolioCalculator', () => {
userId: userDummyData.id userId: userDummyData.id
}); });
const portfolioSnapshot = await portfolioCalculator.computeSnapshot(); const { historicalData } = await portfolioCalculator.computeSnapshot();
const historicalData20231231 = portfolioSnapshot.historicalData.find( const historicalData20231231 = historicalData.find(({ date }) => {
({ date }) => date === '2023-12-31' return date === '2023-12-31';
); });
const historicalData20240101 = portfolioSnapshot.historicalData.find( const historicalData20240101 = historicalData.find(({ date }) => {
({ date }) => date === '2024-01-01' return date === '2024-01-01';
); });
const historicalData20241231 = portfolioSnapshot.historicalData.find( const historicalData20241231 = historicalData.find(({ date }) => {
({ date }) => date === '2024-12-31' return date === '2024-12-31';
); });
/** /**
* Expected logic:
* Investment value with currency effect: 1000 USD * 0.85 = 850 CHF * Investment value with currency effect: 1000 USD * 0.85 = 850 CHF
* Total investment: 1000 USD * 0.91 = 910 CHF * Total investment: 1000 USD * 0.91 = 910 CHF
* Value (current): 1000 USD * 0.91 = 910 CHF * Value (current): 1000 USD * 0.91 = 910 CHF
@ -242,7 +241,6 @@ describe('PortfolioCalculator', () => {
}); });
/** /**
* Expected logic:
* Net performance with currency effect: (1000 * 0.86) - (1000 * 0.85) = 10 CHF * Net performance with currency effect: (1000 * 0.86) - (1000 * 0.85) = 10 CHF
* Total investment: 1000 USD * 0.91 = 910 CHF * Total investment: 1000 USD * 0.91 = 910 CHF
* Total investment value with currency effect: 1000 USD * 0.85 = 850 CHF * Total investment value with currency effect: 1000 USD * 0.85 = 850 CHF
@ -265,7 +263,6 @@ describe('PortfolioCalculator', () => {
}); });
/** /**
* Expected logic:
* Investment value with currency effect: 1000 USD * 0.90 = 900 CHF * Investment value with currency effect: 1000 USD * 0.90 = 900 CHF
* Net performance: (1000 USD * 1.0) - (1000 USD * 1.0) = 0 CHF * Net performance: (1000 USD * 1.0) - (1000 USD * 1.0) = 0 CHF
* Net performance with currency effect: (1000 USD * 0.9) - (1000 USD * 0.85) = 50 CHF * Net performance with currency effect: (1000 USD * 0.9) - (1000 USD * 0.85) = 50 CHF

4
apps/api/src/app/portfolio/portfolio.service.ts

@ -1542,7 +1542,9 @@ export class PortfolioService {
return cashSymbols.map<EnhancedSymbolProfile>((currency) => { return cashSymbols.map<EnhancedSymbolProfile>((currency) => {
const account = cashDetails.accounts.find( const account = cashDetails.accounts.find(
({ currency: accountCurrency }) => accountCurrency === currency ({ currency: accountCurrency }) => {
return accountCurrency === currency;
}
); );
return { return {

Loading…
Cancel
Save