|
|
@ -926,14 +926,22 @@ export abstract class PortfolioCalculator { |
|
|
.mul(factor) |
|
|
.mul(factor) |
|
|
.plus(oldAccumulatedSymbol.quantity); |
|
|
.plus(oldAccumulatedSymbol.quantity); |
|
|
|
|
|
|
|
|
if (type === 'BUY') { |
|
|
if (type === 'BUY' && oldAccumulatedSymbol.investment.gte(0)) { |
|
|
investment = oldAccumulatedSymbol.investment.plus( |
|
|
investment = oldAccumulatedSymbol.investment.plus( |
|
|
quantity.mul(unitPrice) |
|
|
quantity.mul(unitPrice) |
|
|
); |
|
|
); |
|
|
} else if (type === 'SELL') { |
|
|
} else if (type === 'BUY' && oldAccumulatedSymbol.investment.lt(0)) { |
|
|
|
|
|
investment = oldAccumulatedSymbol.investment.plus( |
|
|
|
|
|
quantity.mul(oldAccumulatedSymbol.averagePrice) |
|
|
|
|
|
); |
|
|
|
|
|
} else if (type === 'SELL' && oldAccumulatedSymbol.investment.gt(0)) { |
|
|
investment = oldAccumulatedSymbol.investment.minus( |
|
|
investment = oldAccumulatedSymbol.investment.minus( |
|
|
quantity.mul(oldAccumulatedSymbol.averagePrice) |
|
|
quantity.mul(oldAccumulatedSymbol.averagePrice) |
|
|
); |
|
|
); |
|
|
|
|
|
} else if (type === 'SELL' && oldAccumulatedSymbol.investment.lte(0)) { |
|
|
|
|
|
investment = oldAccumulatedSymbol.investment.minus( |
|
|
|
|
|
quantity.mul(unitPrice) |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
currentTransactionPointItem = { |
|
|
currentTransactionPointItem = { |
|
|
@ -942,8 +950,8 @@ export abstract class PortfolioCalculator { |
|
|
investment, |
|
|
investment, |
|
|
skipErrors, |
|
|
skipErrors, |
|
|
symbol, |
|
|
symbol, |
|
|
averagePrice: newQuantity.gt(0) |
|
|
averagePrice: !newQuantity.eq(0) |
|
|
? investment.div(newQuantity) |
|
|
? investment.div(newQuantity).abs() |
|
|
: new Big(0), |
|
|
: new Big(0), |
|
|
dividend: new Big(0), |
|
|
dividend: new Big(0), |
|
|
fee: oldAccumulatedSymbol.fee.plus(fee), |
|
|
fee: oldAccumulatedSymbol.fee.plus(fee), |
|
|
|