hoostus / portfolio-returns Goto Github PK
View Code? Open in Web Editor NEWBeancount portfolio returns generator
License: Other
Beancount portfolio returns generator
License: Other
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 ?
Example below involves a stock conversion (eg: a stock split), which should make no change to inflows, outflows, or cashflows.
Expected output: 50%
Actual output: 150%
option "operating_currency" "USD"
plugin "beancount.plugins.auto_accounts"
2018-01-01 * "Buy"
Assets:Investments 100 HOOLI {1 USD}
Assets:Bank
2018-04-01 * "Conversion"
Assets:Investments -100 HOOLI {}
Assets:Investments 50 IOOLI {2 USD}
2018-12-31 price HOOLI 1.5 USD
2018-12-31 price IOOLI 3 USD
irr.py --account Assets:Investments test.bc --from 2018-01-01 --to 2018-12-31```
option "operating_currency" "USD"
plugin "beancount.plugins.auto_accounts"
plugin "beancount.plugins.implicit_prices"
2018-01-01 * "Buy"
Assets:Investments 100 HOOLI {2 USD}
Assets:Bank
Expected: 0%
Result: error:
$ /home/user/gnu/portfolio-returns/irr.py --currency USD --account Assets:Investments test.bc --from 2018-01-01 --to 2018-12-31
/usr/lib/python3.6/site-packages/numpy/core/numeric.py:2531: RuntimeWarning: invalid value encountered in multiply
x = x * ones_like(cond)
Traceback (most recent call last):
File "/home/user/gnu/portfolio-returns/irr.py", line 248, in <module>
r = xirr([(d, float(f)) for (d,f) in cashflows])
File "/home/user/gnu/portfolio-returns/irr.py", line 65, in xirr
return optimize.newton(lambda r: xnpv(r,cashflows),guess)
File "/usr/lib/python3.6/site-packages/scipy/optimize/zeros.py", line 338, in newton
q1 = func(p1, *args)
File "/home/user/gnu/portfolio-returns/irr.py", line 65, in <lambda>
return optimize.newton(lambda r: xnpv(r,cashflows),guess)
File "/home/user/gnu/portfolio-returns/irr.py", line 46, in xnpv
return sum([cf/(1+rate)**((t-t0).days/365.0) for (t,cf) in chron_order])
File "/home/user/gnu/portfolio-returns/irr.py", line 46, in <listcomp>
return sum([cf/(1+rate)**((t-t0).days/365.0) for (t,cf) in chron_order])
OverflowError: complex exponentiation
I was wondering if you've thought of a license this code is being released under?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.