remove getPerformance from portfolio.ts
Co-authored-by: Thomas <dotsilver@gmail.com>
This commit is contained in:
parent
d23addb673
commit
328d814922
@ -208,28 +208,6 @@ describe('Portfolio', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return zero performance for 1d', async () => {
|
|
||||||
const performance = await portfolio.getPerformance('1d');
|
|
||||||
expect(performance).toEqual({
|
|
||||||
currentGrossPerformance: 0,
|
|
||||||
currentGrossPerformancePercent: 0,
|
|
||||||
currentNetPerformance: 0,
|
|
||||||
currentNetPerformancePercent: 0,
|
|
||||||
currentValue: 0
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return zero performance for max', async () => {
|
|
||||||
const performance = await portfolio.getPerformance('max');
|
|
||||||
expect(performance).toEqual({
|
|
||||||
currentGrossPerformance: 0,
|
|
||||||
currentGrossPerformancePercent: 0,
|
|
||||||
currentNetPerformance: 0,
|
|
||||||
currentNetPerformancePercent: 0,
|
|
||||||
currentValue: 0
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe(`works with today's orders`, () => {
|
describe(`works with today's orders`, () => {
|
||||||
@ -303,32 +281,6 @@ describe('Portfolio', () => {
|
|||||||
|
|
||||||
expect(portfolio.getFees()).toEqual(0);
|
expect(portfolio.getFees()).toEqual(0);
|
||||||
|
|
||||||
/*const performance1d = await portfolio.getPerformance('1d');
|
|
||||||
expect(performance1d).toEqual({
|
|
||||||
currentGrossPerformance: 0,
|
|
||||||
currentGrossPerformancePercent: 0,
|
|
||||||
currentNetPerformance: 0,
|
|
||||||
currentNetPerformancePercent: 0,
|
|
||||||
currentValue: exchangeRateDataService.toBaseCurrency(
|
|
||||||
1 * 49631.24,
|
|
||||||
Currency.USD,
|
|
||||||
baseCurrency
|
|
||||||
)
|
|
||||||
});*/
|
|
||||||
|
|
||||||
/*const performanceMax = await portfolio.getPerformance('max');
|
|
||||||
expect(performanceMax).toEqual({
|
|
||||||
currentGrossPerformance: 0,
|
|
||||||
currentGrossPerformancePercent: 0,
|
|
||||||
currentNetPerformance: 0,
|
|
||||||
currentNetPerformancePercent: 0,
|
|
||||||
currentValue: exchangeRateDataService.toBaseCurrency(
|
|
||||||
1 * 49631.24,
|
|
||||||
Currency.USD,
|
|
||||||
baseCurrency
|
|
||||||
)
|
|
||||||
});*/
|
|
||||||
|
|
||||||
expect(portfolio.getPositions(getYesterday())).toMatchObject({});
|
expect(portfolio.getPositions(getYesterday())).toMatchObject({});
|
||||||
|
|
||||||
expect(portfolio.getSymbols(getYesterday())).toEqual([]);
|
expect(portfolio.getSymbols(getYesterday())).toEqual([]);
|
||||||
@ -367,55 +319,8 @@ describe('Portfolio', () => {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/*const details = await portfolio.getDetails('1d');
|
|
||||||
expect(details).toMatchObject({
|
|
||||||
ETHUSD: {
|
|
||||||
accounts: {
|
|
||||||
[UNKNOWN_KEY]: {
|
|
||||||
current: exchangeRateDataService.toCurrency(
|
|
||||||
0.2 * 991.49,
|
|
||||||
Currency.USD,
|
|
||||||
baseCurrency
|
|
||||||
),
|
|
||||||
original: exchangeRateDataService.toCurrency(
|
|
||||||
0.2 * 991.49,
|
|
||||||
Currency.USD,
|
|
||||||
baseCurrency
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// allocationCurrent: 1,
|
|
||||||
allocationInvestment: 1,
|
|
||||||
countries: [],
|
|
||||||
currency: Currency.USD,
|
|
||||||
exchange: UNKNOWN_KEY,
|
|
||||||
// grossPerformance: 0,
|
|
||||||
// grossPerformancePercent: 0,
|
|
||||||
investment: exchangeRateDataService.toCurrency(
|
|
||||||
0.2 * 991.49,
|
|
||||||
Currency.USD,
|
|
||||||
baseCurrency
|
|
||||||
),
|
|
||||||
marketPrice: 3915.337,
|
|
||||||
name: 'Ethereum USD',
|
|
||||||
quantity: 0.2,
|
|
||||||
transactionCount: 1,
|
|
||||||
symbol: 'ETHUSD',
|
|
||||||
type: 'Cryptocurrency'
|
|
||||||
}
|
|
||||||
});*/
|
|
||||||
|
|
||||||
expect(portfolio.getFees()).toEqual(0);
|
expect(portfolio.getFees()).toEqual(0);
|
||||||
|
|
||||||
/*const performance = await portfolio.getPerformance('max');
|
|
||||||
expect(performance).toEqual({
|
|
||||||
currentGrossPerformance: 0,
|
|
||||||
currentGrossPerformancePercent: 0,
|
|
||||||
currentNetPerformance: 0,
|
|
||||||
currentNetPerformancePercent: 0,
|
|
||||||
currentValue: 0
|
|
||||||
});*/
|
|
||||||
|
|
||||||
expect(portfolio.getPositions(getYesterday())).toMatchObject({
|
expect(portfolio.getPositions(getYesterday())).toMatchObject({
|
||||||
ETHUSD: {
|
ETHUSD: {
|
||||||
averagePrice: 991.49,
|
averagePrice: 991.49,
|
||||||
|
@ -426,49 +426,6 @@ export class Portfolio implements PortfolioInterface {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getPerformance(
|
|
||||||
aDateRange: DateRange = 'max'
|
|
||||||
): Promise<PortfolioPerformance> {
|
|
||||||
const dateRangeDate = this.convertDateRangeToDate(
|
|
||||||
aDateRange,
|
|
||||||
this.getMinDate()
|
|
||||||
);
|
|
||||||
|
|
||||||
const currentInvestment = this.getInvestment(new Date());
|
|
||||||
const currentValue = await this.getValue();
|
|
||||||
|
|
||||||
let originalInvestment = currentInvestment;
|
|
||||||
let originalValue = this.getCommittedFunds();
|
|
||||||
|
|
||||||
if (dateRangeDate) {
|
|
||||||
originalInvestment = this.getInvestment(dateRangeDate);
|
|
||||||
originalValue = (await this.getValue(dateRangeDate)) || originalValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fees = this.getFees(dateRangeDate);
|
|
||||||
|
|
||||||
const currentGrossPerformance =
|
|
||||||
currentValue - currentInvestment - (originalValue - originalInvestment);
|
|
||||||
|
|
||||||
// https://www.skillsyouneed.com/num/percent-change.html
|
|
||||||
const currentGrossPerformancePercent =
|
|
||||||
currentGrossPerformance / originalInvestment || 0;
|
|
||||||
|
|
||||||
const currentNetPerformance = currentGrossPerformance - fees;
|
|
||||||
|
|
||||||
// https://www.skillsyouneed.com/num/percent-change.html
|
|
||||||
const currentNetPerformancePercent =
|
|
||||||
currentNetPerformance / originalInvestment || 0;
|
|
||||||
|
|
||||||
return {
|
|
||||||
currentGrossPerformance,
|
|
||||||
currentGrossPerformancePercent,
|
|
||||||
currentNetPerformance,
|
|
||||||
currentNetPerformancePercent,
|
|
||||||
currentValue
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public getPositions(aDate: Date) {
|
public getPositions(aDate: Date) {
|
||||||
const [portfolioItem] = this.get(aDate);
|
const [portfolioItem] = this.get(aDate);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user