@ -150,6 +150,7 @@ export abstract class PortfolioCalculator {
( {
( {
assetProfile ,
assetProfile ,
date ,
date ,
exchangeRate ,
feeInAssetProfileCurrency ,
feeInAssetProfileCurrency ,
feeInBaseCurrency ,
feeInBaseCurrency ,
quantity ,
quantity ,
@ -172,6 +173,7 @@ export abstract class PortfolioCalculator {
tags ,
tags ,
type ,
type ,
date : format ( date , DATE_FORMAT ) ,
date : format ( date , DATE_FORMAT ) ,
exchangeRate ,
fee : new Big ( feeInAssetProfileCurrency ) ,
fee : new Big ( feeInAssetProfileCurrency ) ,
feeInBaseCurrency : new Big ( feeInBaseCurrency ) ,
feeInBaseCurrency : new Big ( feeInBaseCurrency ) ,
quantity : new Big ( quantity ) ,
quantity : new Big ( quantity ) ,
@ -1013,6 +1015,13 @@ export abstract class PortfolioCalculator {
const exchangeRateAtActivityDate = exchangeRates [ activity . date ] ;
const exchangeRateAtActivityDate = exchangeRates [ activity . date ] ;
// Manual override of the asset to base currency rate at the activity
// date. It only applies to the cost-basis path (with currency effect of
// the activity itself). Current valuations and historical market prices
// stay on market rates.
const exchangeRateAtActivityDateForCostBasis =
activity . exchangeRate ? ? exchangeRateAtActivityDate ;
if ( activity . itemType === 'start' ) {
if ( activity . itemType === 'start' ) {
// Take the unit price of the activity as the market price if there are no
// Take the unit price of the activity as the market price if there are no
// activities of this symbol before the start date
// activities of this symbol before the start date
@ -1025,7 +1034,7 @@ export abstract class PortfolioCalculator {
if ( activity . fee ) {
if ( activity . fee ) {
activity . feeInBaseCurrency = activity . fee . mul ( currentExchangeRate ? ? 1 ) ;
activity . feeInBaseCurrency = activity . fee . mul ( currentExchangeRate ? ? 1 ) ;
activity . feeInBaseCurrencyWithCurrencyEffect = activity . fee . mul (
activity . feeInBaseCurrencyWithCurrencyEffect = activity . fee . mul (
exchangeRateAtActivityDate ? ? 1
exchangeRateAtActivityDateForCostBasis ? ? 1
) ;
) ;
}
}
@ -1039,7 +1048,7 @@ export abstract class PortfolioCalculator {
) ;
) ;
activity . unitPriceInBaseCurrencyWithCurrencyEffect = unitPrice . mul (
activity . unitPriceInBaseCurrencyWithCurrencyEffect = unitPrice . mul (
exchangeRateAtActivityDate ? ? 1
exchangeRateAtActivityDateForCostBasis ? ? 1
) ;
) ;
}
}
@ -1486,7 +1495,8 @@ export abstract class PortfolioCalculator {
let totalLiabilitiesInBaseCurrency = new Big ( 0 ) ;
let totalLiabilitiesInBaseCurrency = new Big ( 0 ) ;
for ( const activity of activities ) {
for ( const activity of activities ) {
const exchangeRateAtActivityDate = exchangeRates [ activity . date ] ;
const exchangeRateAtActivityDate =
activity . exchangeRate ? ? exchangeRates [ activity . date ] ;
if ( activity . type === 'DIVIDEND' ) {
if ( activity . type === 'DIVIDEND' ) {
const dividend = activity . quantity . mul ( activity . unitPrice ) ;
const dividend = activity . quantity . mul ( activity . unitPrice ) ;