Browse Source

Code review changes

pull/4597/head
csehatt741 4 months ago
committed by Attila Cseh
parent
commit
ed115f5833
  1. 74
      apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btceur.spec.ts
  2. 14
      apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd.spec.ts
  3. 9
      apps/api/src/services/exchange-rate-data/exchange-rate-data.service.mock.ts
  4. 2
      test/import/ok-btceur.json
  5. 2
      test/import/ok-btcusd.json

74
apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btceur.spec.ts

@ -113,19 +113,21 @@ describe('PortfolioCalculator', () => {
...activityDummyData, ...activityDummyData,
...activity, ...activity,
date: parseDate(activity.date), date: parseDate(activity.date),
feeInAssetProfileCurrency: 4.46,
SymbolProfile: { SymbolProfile: {
...symbolProfileDummyData, ...symbolProfileDummyData,
currency: 'USD', currency: 'USD',
dataSource: activity.dataSource, dataSource: activity.dataSource,
name: 'Bitcoin', name: 'Bitcoin',
symbol: activity.symbol symbol: activity.symbol
} },
unitPriceInAssetProfileCurrency: 44558.42
})); }));
const portfolioCalculator = portfolioCalculatorFactory.createCalculator({ const portfolioCalculator = portfolioCalculatorFactory.createCalculator({
activities, activities,
calculationType: PerformanceCalculationType.ROAI, calculationType: PerformanceCalculationType.ROAI,
currency: 'EUR', currency: 'USD',
userId: userDummyData.id userId: userDummyData.id
}); });
@ -155,17 +157,17 @@ describe('PortfolioCalculator', () => {
expect(portfolioSnapshot.historicalData[1]).toEqual({ expect(portfolioSnapshot.historicalData[1]).toEqual({
date: '2021-12-12', date: '2021-12-12',
investmentValueWithCurrencyEffect: 39380.731596, investmentValueWithCurrencyEffect: 44558.42,
netPerformance: -3.892688, netPerformance: -4.46,
netPerformanceInPercentage: 0, netPerformanceInPercentage: 0,
netPerformanceInPercentageWithCurrencyEffect: 0, netPerformanceInPercentageWithCurrencyEffect: 0,
netPerformanceWithCurrencyEffect: -3.941748, netPerformanceWithCurrencyEffect: -4.46,
netWorth: 39380.731596, netWorth: 44558.42,
totalAccountBalance: 0, totalAccountBalance: 0,
totalInvestment: 38890.588976, totalInvestment: 44558.42,
totalInvestmentValueWithCurrencyEffect: 39380.731596, totalInvestmentValueWithCurrencyEffect: 44558.42,
value: 38890.588976, value: 44558.42,
valueWithCurrencyEffect: 39380.731596 valueWithCurrencyEffect: 44558.42
}); });
expect( expect(
@ -175,20 +177,20 @@ describe('PortfolioCalculator', () => {
).toEqual({ ).toEqual({
date: '2022-01-14', date: '2022-01-14',
investmentValueWithCurrencyEffect: 0, investmentValueWithCurrencyEffect: 0,
netPerformance: -1277.063504, netPerformance: -1463.18,
netPerformanceInPercentage: -0.032837340282712, netPerformanceInPercentage: -0.032837340282712,
netPerformanceInPercentageWithCurrencyEffect: -0.044876138974002826, netPerformanceInPercentageWithCurrencyEffect: -0.032837340282712,
netPerformanceWithCurrencyEffect: -1767.255184, netPerformanceWithCurrencyEffect: -1463.18,
netWorth: 37617.41816, netWorth: 43099.7,
totalAccountBalance: 0, totalAccountBalance: 0,
totalInvestment: 38890.588976, totalInvestment: 44558.42,
totalInvestmentValueWithCurrencyEffect: 39380.731596, totalInvestmentValueWithCurrencyEffect: 44558.42,
value: 37617.41816, value: 43099.7,
valueWithCurrencyEffect: 37617.41816 valueWithCurrencyEffect: 43099.7
}); });
expect(portfolioSnapshot).toMatchObject({ expect(portfolioSnapshot).toMatchObject({
currentValueInBaseCurrency: new Big('37617.41816'), currentValueInBaseCurrency: new Big('43099.7'),
errors: [], errors: [],
hasErrors: false, hasErrors: false,
positions: [ positions: [
@ -199,39 +201,39 @@ describe('PortfolioCalculator', () => {
dividend: new Big('0'), dividend: new Big('0'),
dividendInBaseCurrency: new Big('0'), dividendInBaseCurrency: new Big('0'),
fee: new Big('4.46'), fee: new Big('4.46'),
feeInBaseCurrency: new Big('3.941748'), feeInBaseCurrency: new Big('4.46'),
firstBuyDate: '2021-12-12', firstBuyDate: '2021-12-12',
grossPerformance: new Big('-1273.170816'), grossPerformance: new Big('-1458.72'),
grossPerformancePercentage: new Big('-0.03273724696701543726'), grossPerformancePercentage: new Big('-0.03273724696701543726'),
grossPerformancePercentageWithCurrencyEffect: new Big( grossPerformancePercentageWithCurrencyEffect: new Big(
'-0.04477604565830626119' '-0.03273724696701543726'
), ),
grossPerformanceWithCurrencyEffect: new Big('-1763.313436'), grossPerformanceWithCurrencyEffect: new Big('-1458.72'),
investment: new Big('38890.588976'), investment: new Big('44558.42'),
investmentWithCurrencyEffect: new Big('39380.731596'), investmentWithCurrencyEffect: new Big('44558.42'),
netPerformance: new Big('-1277.063504'), netPerformance: new Big('-1463.18'),
netPerformancePercentage: new Big('-0.03283734028271199921'), netPerformancePercentage: new Big('-0.03283734028271199921'),
netPerformancePercentageWithCurrencyEffectMap: { netPerformancePercentageWithCurrencyEffectMap: {
max: new Big('-0.04487613897400282314') max: new Big('-0.03283734028271199921')
}, },
netPerformanceWithCurrencyEffectMap: { netPerformanceWithCurrencyEffectMap: {
max: new Big('-1767.255184') max: new Big('-1463.18')
}, },
marketPrice: 43099.7, marketPrice: 43099.7,
marketPriceInBaseCurrency: 37617.41816, marketPriceInBaseCurrency: 43099.7,
quantity: new Big('1'), quantity: new Big('1'),
symbol: 'BTCUSD', symbol: 'BTCUSD',
tags: [], tags: [],
timeWeightedInvestment: new Big('38890.588976'), timeWeightedInvestment: new Big('44558.42'),
timeWeightedInvestmentWithCurrencyEffect: new Big('39380.731596'), timeWeightedInvestmentWithCurrencyEffect: new Big('44558.42'),
transactionCount: 1, transactionCount: 1,
valueInBaseCurrency: new Big('37617.41816') valueInBaseCurrency: new Big('43099.7')
} }
], ],
totalFeesWithCurrencyEffect: new Big('3.941748'), totalFeesWithCurrencyEffect: new Big('4.46'),
totalInterestWithCurrencyEffect: new Big('0'), totalInterestWithCurrencyEffect: new Big('0'),
totalInvestment: new Big('38890.588976'), totalInvestment: new Big('44558.42'),
totalInvestmentWithCurrencyEffect: new Big('39380.731596'), totalInvestmentWithCurrencyEffect: new Big('44558.42'),
totalLiabilitiesWithCurrencyEffect: new Big('0'), totalLiabilitiesWithCurrencyEffect: new Big('0'),
totalValuablesWithCurrencyEffect: new Big('0') totalValuablesWithCurrencyEffect: new Big('0')
}); });
@ -241,7 +243,7 @@ describe('PortfolioCalculator', () => {
]); ]);
expect(investmentsByMonth).toEqual([ expect(investmentsByMonth).toEqual([
{ date: '2021-12-01', investment: 39380.731596 }, { date: '2021-12-01', investment: 44558.42 },
{ date: '2022-01-01', investment: 0 } { date: '2022-01-01', investment: 0 }
]); ]);
}); });

14
apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd.spec.ts

@ -100,13 +100,15 @@ describe('PortfolioCalculator', () => {
...activityDummyData, ...activityDummyData,
...activity, ...activity,
date: parseDate(activity.date), date: parseDate(activity.date),
feeInAssetProfileCurrency: 4.46,
SymbolProfile: { SymbolProfile: {
...symbolProfileDummyData, ...symbolProfileDummyData,
currency: 'USD', currency: 'USD',
dataSource: activity.dataSource, dataSource: activity.dataSource,
name: 'Bitcoin', name: 'Bitcoin',
symbol: activity.symbol symbol: activity.symbol
} },
unitPriceInAssetProfileCurrency: 44558.42
})); }));
const portfolioCalculator = portfolioCalculatorFactory.createCalculator({ const portfolioCalculator = portfolioCalculatorFactory.createCalculator({
@ -223,16 +225,6 @@ describe('PortfolioCalculator', () => {
totalValuablesWithCurrencyEffect: new Big('0') totalValuablesWithCurrencyEffect: new Big('0')
}); });
expect(portfolioSnapshot.historicalData.at(-1)).toMatchObject(
expect.objectContaining({
netPerformance: -1463.18,
netPerformanceInPercentage: -0.032837340282712,
netPerformanceInPercentageWithCurrencyEffect: -0.032837340282712,
netPerformanceWithCurrencyEffect: -1463.18,
totalInvestmentValueWithCurrencyEffect: 44558.42
})
);
expect(investments).toEqual([ expect(investments).toEqual([
{ date: '2021-12-12', investment: new Big('44558.42') } { date: '2021-12-12', investment: new Big('44558.42') }
]); ]);

9
apps/api/src/services/exchange-rate-data/exchange-rate-data.service.mock.ts

@ -22,16 +22,11 @@ export const ExchangeRateDataServiceMock = {
USDUSD: { USDUSD: {
'2018-01-01': 1, '2018-01-01': 1,
'2021-11-16': 1, '2021-11-16': 1,
'2021-12-12': 1,
'2022-01-14': 1,
'2023-07-10': 1 '2023-07-10': 1
} }
}); });
} else if (targetCurrency === 'EUR') {
return Promise.resolve({
USDEUR: {
'2021-12-12': 0.8838,
'2022-01-14': 0.8728
}
});
} }
return Promise.resolve({}); return Promise.resolve({});

2
test/import/ok-btceur.json

@ -11,11 +11,9 @@
"accountId": null, "accountId": null,
"comment": null, "comment": null,
"fee": 3.94, "fee": 3.94,
"feeInAssetProfileCurrency": 4.46,
"quantity": 1, "quantity": 1,
"type": "BUY", "type": "BUY",
"unitPrice": 39378.5, "unitPrice": 39378.5,
"unitPriceInAssetProfileCurrency": 44558.42,
"currency": "EUR", "currency": "EUR",
"dataSource": "YAHOO", "dataSource": "YAHOO",
"date": "2021-12-12T00:00:00.000Z", "date": "2021-12-12T00:00:00.000Z",

2
test/import/ok-btcusd.json

@ -11,11 +11,9 @@
"accountId": null, "accountId": null,
"comment": null, "comment": null,
"fee": 4.46, "fee": 4.46,
"feeInAssetProfileCurrency": 4.46,
"quantity": 1, "quantity": 1,
"type": "BUY", "type": "BUY",
"unitPrice": 44558.42, "unitPrice": 44558.42,
"unitPriceInAssetProfileCurrency": 44558.42,
"currency": "USD", "currency": "USD",
"dataSource": "YAHOO", "dataSource": "YAHOO",
"date": "2021-12-12T00:00:00.000Z", "date": "2021-12-12T00:00:00.000Z",

Loading…
Cancel
Save