Feature/refactor portfolio calculator factory (#4454)
* Refactor portfolio calculator factory
This commit is contained in:
parent
f17a95eb48
commit
6036547cf5
@ -5,7 +5,7 @@ import {
|
|||||||
} from '@ghostfolio/common/interfaces';
|
} from '@ghostfolio/common/interfaces';
|
||||||
import { PortfolioSnapshot } from '@ghostfolio/common/models';
|
import { PortfolioSnapshot } from '@ghostfolio/common/models';
|
||||||
|
|
||||||
export class MWRPortfolioCalculator extends PortfolioCalculator {
|
export class MwrPortfolioCalculator extends PortfolioCalculator {
|
||||||
protected calculateOverallPerformance(): PortfolioSnapshot {
|
protected calculateOverallPerformance(): PortfolioSnapshot {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,15 @@ import { Filter, HistoricalDataItem } from '@ghostfolio/common/interfaces';
|
|||||||
|
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
import { MWRPortfolioCalculator } from './mwr/portfolio-calculator';
|
import { MwrPortfolioCalculator } from './mwr/portfolio-calculator';
|
||||||
import { PortfolioCalculator } from './portfolio-calculator';
|
import { PortfolioCalculator } from './portfolio-calculator';
|
||||||
import { RoaiPortfolioCalculator } from './roai/portfolio-calculator';
|
import { RoaiPortfolioCalculator } from './roai/portfolio-calculator';
|
||||||
|
import { TwrPortfolioCalculator } from './twr/portfolio-calculator';
|
||||||
|
|
||||||
export enum PerformanceCalculationType {
|
export enum PerformanceCalculationType {
|
||||||
MWR = 'MWR', // Money-Weighted Rate of Return
|
MWR = 'MWR', // Money-Weighted Rate of Return
|
||||||
ROAI = 'ROAI' // Return on Average Investment
|
ROAI = 'ROAI', // Return on Average Investment
|
||||||
|
TWR = 'TWR' // Time-Weighted Rate of Return
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -44,7 +46,7 @@ export class PortfolioCalculatorFactory {
|
|||||||
}): PortfolioCalculator {
|
}): PortfolioCalculator {
|
||||||
switch (calculationType) {
|
switch (calculationType) {
|
||||||
case PerformanceCalculationType.MWR:
|
case PerformanceCalculationType.MWR:
|
||||||
return new MWRPortfolioCalculator({
|
return new MwrPortfolioCalculator({
|
||||||
accountBalanceItems,
|
accountBalanceItems,
|
||||||
activities,
|
activities,
|
||||||
currency,
|
currency,
|
||||||
@ -61,10 +63,23 @@ export class PortfolioCalculatorFactory {
|
|||||||
accountBalanceItems,
|
accountBalanceItems,
|
||||||
activities,
|
activities,
|
||||||
currency,
|
currency,
|
||||||
currentRateService: this.currentRateService,
|
|
||||||
filters,
|
filters,
|
||||||
userId,
|
userId,
|
||||||
configurationService: this.configurationService,
|
configurationService: this.configurationService,
|
||||||
|
currentRateService: this.currentRateService,
|
||||||
|
exchangeRateDataService: this.exchangeRateDataService,
|
||||||
|
portfolioSnapshotService: this.portfolioSnapshotService,
|
||||||
|
redisCacheService: this.redisCacheService
|
||||||
|
});
|
||||||
|
case PerformanceCalculationType.TWR:
|
||||||
|
return new TwrPortfolioCalculator({
|
||||||
|
accountBalanceItems,
|
||||||
|
activities,
|
||||||
|
currency,
|
||||||
|
filters,
|
||||||
|
userId,
|
||||||
|
configurationService: this.configurationService,
|
||||||
|
currentRateService: this.currentRateService,
|
||||||
exchangeRateDataService: this.exchangeRateDataService,
|
exchangeRateDataService: this.exchangeRateDataService,
|
||||||
portfolioSnapshotService: this.portfolioSnapshotService,
|
portfolioSnapshotService: this.portfolioSnapshotService,
|
||||||
redisCacheService: this.redisCacheService
|
redisCacheService: this.redisCacheService
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
import { PortfolioCalculator } from '@ghostfolio/api/app/portfolio/calculator/portfolio-calculator';
|
||||||
|
import {
|
||||||
|
AssetProfileIdentifier,
|
||||||
|
SymbolMetrics
|
||||||
|
} from '@ghostfolio/common/interfaces';
|
||||||
|
import { PortfolioSnapshot } from '@ghostfolio/common/models';
|
||||||
|
|
||||||
|
export class TwrPortfolioCalculator extends PortfolioCalculator {
|
||||||
|
protected calculateOverallPerformance(): PortfolioSnapshot {
|
||||||
|
throw new Error('Method not implemented.');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getSymbolMetrics({}: {
|
||||||
|
end: Date;
|
||||||
|
exchangeRates: { [dateString: string]: number };
|
||||||
|
marketSymbolMap: {
|
||||||
|
[date: string]: { [symbol: string]: Big };
|
||||||
|
};
|
||||||
|
start: Date;
|
||||||
|
step?: number;
|
||||||
|
} & AssetProfileIdentifier): SymbolMetrics {
|
||||||
|
throw new Error('Method not implemented.');
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user