hoostus / portfolio-returns

Beancount portfolio returns generator
Other
38 stars 6 forks source link

Issue with multicurrency portfolio. #5

Open grostim opened 4 years ago

grostim commented 4 years ago

Hello,

I have a portfolio whose main currency is EURO, but some of the stocks are quoted in CAD, USD or other currencies.

When i use you script, I can see some cashflows entries that should not exist.

Exemple:

python irr.py --currency EUR --internal Revenus --internal Depenses Famille.beancount  --account Actif:Bink:CTO --year 2019 --debug-cashflows --debug-inflows --debug-outflows
25.18%
[(datetime.date(2019, 1, 1), Decimal('14844.08551197826805000953313')),
 (datetime.date(2019, 1, 10), Decimal('150.00')),
 (datetime.date(2019, 1, 14), Decimal('0.093647131589160751001238694')),
 (datetime.date(2019, 1, 24), Decimal('0.93243922021409590941076062')),
 (datetime.date(2019, 2, 4), Decimal('0.022447982097499665471847500')),
 (datetime.date(2019, 2, 11), Decimal('150.00')),
 (datetime.date(2019, 3, 11), Decimal('150.00')),
 (datetime.date(2019, 4, 1), Decimal('0.090920135139649239445324253')),
 (datetime.date(2019, 4, 10), Decimal('150.00')),
 (datetime.date(2019, 4, 11), Decimal('-0.050000000000000000000000001')),
 (datetime.date(2019, 4, 19), Decimal('-2843.796426581529348899641038')),
 (datetime.date(2019, 4, 25), Decimal('0.075807582443060723234804055')),
 (datetime.date(2019, 5, 10), Decimal('150.00')),
 (datetime.date(2019, 6, 10), Decimal('150.00')),
 (datetime.date(2019, 7, 1), Decimal('0.074201957713688278299761169')),
 (datetime.date(2019, 7, 10), Decimal('150.00')),
 (datetime.date(2019, 7, 25), Decimal('0.121507743894273941608576125')),
 (datetime.date(2019, 8, 1), Decimal('-2.901127047095921066015665370')),
 (datetime.date(2019, 8, 5), Decimal('0.032744018669264658502304616')),
 (datetime.date(2019, 8, 5), Decimal('5000.00')),
 (datetime.date(2019, 8, 12), Decimal('150.00')),
 (datetime.date(2019, 9, 10), Decimal('150.00')),
 (datetime.date(2019, 10, 10), Decimal('150.00')),
 (datetime.date(2019, 10, 25), Decimal('0.098772563176895306859205776')),
 (datetime.date(2019, 11, 4), Decimal('0.022749326145552560646900270')),
 (datetime.date(2019, 11, 11), Decimal('150.00')),
 (datetime.date(2019, 11, 27), Decimal('4.82362891304347826086956431')),
 (datetime.date(2019, 12, 11), Decimal('150.00')),
 (datetime.date(2019, 12, 31), Decimal('-22746.48983458110516934046346'))]
>> [inflows]
{'Actif:Boursorama:CCTim'}
<< [outflows]
set()

What i expect: The cashflows should only include the situation at 01/01/2019, 31/12/2019 and the monthly deposit of 150EUR. All the other values (with many decimal digits) should not be taken in consideration in the IRR calculation.

In order to understand what happen, here is the transaction of the January 14th that created the following cashflow: (datetime.date(2019, 1, 14), Decimal('0.093647131589160751001238694')),

2019-01-14 * "Dividende Communications Systems Inc" 
  Revenus:Dividendes                                  -6.70 USD
  Depenses:Impots:PS                                   0.85 EUR
  Actif:Bink:CTO:Cash                                 -0.85 EUR
  Depenses:Impots:RetenueSource                        1.01 EUR
  Actif:Bink:CTO:Cash                                 -1.01 EUR
  Actif:Bink:CTO:Cash                                  5.94 EUR @@ 6.70 USD

As the "Revenus" and "Depenses" should be treated as internal, i do not expect any cashflow for this transaction.

Other situation which is probably not related to the multicurrencies but to a split: On April 19th, i have th follwing cashflow: (datetime.date(2019, 4, 19), Decimal('-2843.796426581529348899641038')),

Here is the corresponding transaction (a stock split):

2019-04-19 * "Transfert de titres 800 Appliance Recycling Centers Split- @ 0,99852 $" "Dépôt 160 Appliance Recycling Centers Am -Isin chn @ 4,99262 $"
  Actif:Bink:CTO:US03814F4037                          -800 US03814F4037 {}
  Actif:Bink:CTO:US03814F4037                           160 US03814F4037 {4.99262 USD} @4.99262 USD

Any idea of what may happen ?

hoostus commented 4 years ago

Hmm, I'm not sure. It is almost certainly related to the conversion from USD to EUR. I added some extra logging/warning around that a week or two ago. Could you download the most recent version and see if those warnings trigger anything?

It is probably similar to #3 which is caused by convert_position() doing weird/bad things if the price_map isn't 100% perfect.

Once I have a fix for #3 we'll see if it also fixes this.

hoostus commented 4 years ago

Ah, forgot to mention. One other thing to try is to add explicit price statements for the USD/EUR conversion on 2019-01-14 and see if that makes the spurious cashflow go away.