Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Stock splits are not correctly accounted for within portfolio #4182

Closed
JerBouma opened this issue Feb 9, 2023 · 3 comments
Closed
Assignees
Labels
bug Fix bug portfolio Portfolio menu

Comments

@JerBouma
Copy link
Contributor

JerBouma commented Feb 9, 2023

As noted here: https://twitter.com/jrp980/status/1623386325142347784?s=46&t=_PF5iVHF-dn4emakfIM6ag

If I purchase a share of Tesla at 890 on July 2022 and the stock split occurs on Aug 2022 (3:1), my initial order size needs to be adjusted (3 shares instead of 1). Currently, this isn't happening while the stock price data is adjusted. So when we display a table like below (or any other performance metric) it falsely tells me I made a massive loss on some tickers.

This can be relatively easy acquired by collecting split data which we already have within stocks/fa/splits and multiplying volumes when orders are before the split. Do let the user know this is happening. A flag ("adjust for splits") shouldn't be required since it is entirely wrong without the adjustment.

(🦋) /portfolio/ $ perf --show_trades

                              Portfolio vs. Benchmark - Individual Trades in period
┏━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Date       ┃ Ticker ┃ Portfolio Value ┃ Portfolio % Return ┃ Benchmark Value ┃ Benchmark % Return ┃ Alpha     ┃
┡━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ 2010-05-03 │ GOOGL  │ 303.84          │ 863.35%            │ 137.32          │ 335.38%            │ 527.97%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2010-07-06 │ AMZN   │ 3313.95         │ 10765.41%          │ 154.62          │ 406.95%            │ 10358.46% │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2011-08-06 │ AAPL   │ 298.11          │ 667.73%            │ 196.85          │ 406.95%            │ 260.78%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2011-12-12 │ APTV   │ 657.10          │ 629.30%            │ 368.94          │ 309.48%            │ 319.83%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2012-02-03 │ ASML   │ 1023.96         │ 147.22%            │ 1555.92         │ 275.65%            │ -128.43%  │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2012-05-04 │ NKE    │ 282.84          │ 237.32%            │ 307.98          │ 267.30%            │ -29.98%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2012-08-04 │ TSM    │ 5789.50         │ 713.13%            │ 2615.16         │ 267.30%            │ 445.83%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2012-10-12 │ DGX    │ 737.46          │ 88.93%             │ 1360.27         │ 248.48%            │ -159.55%  │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2013-02-03 │ YUM    │ 400.20          │ 106.37%            │ 675.78          │ 248.48%            │ -142.11%  │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2013-03-04 │ GOOGL  │ 151.92          │ 26.03%             │ 389.74          │ 223.33%            │ -197.30%  │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2013-08-08 │ AMZN   │ 662.79          │ 3847.53%           │ 48.42           │ 188.37%            │ 3659.15%  │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2013-10-09 │ AAPL   │ 496.85          │ 440.64%            │ 270.42          │ 194.25%            │ 246.39%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2014-02-03 │ APTV   │ 657.10          │ 161.12%            │ 700.25          │ 178.26%            │ -17.15%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2014-02-05 │ ASML   │ 438.84          │ 69.78%             │ 715.15          │ 176.68%            │ -106.90%  │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2014-12-08 │ NKE    │ 942.80          │ 92.17%             │ 1134.99         │ 131.35%            │ -39.18%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2015-02-02 │ BABA   │ 3153.30         │ 16.58%             │ 6367.93         │ 135.42%            │ -118.84%  │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2015-03-08 │ TSM    │ 2315.80         │ 387.54%            │ 1118.25         │ 135.42%            │ 252.11%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2015-12-05 │ DGX    │ 2581.11         │ 78.32%             │ 3407.57         │ 135.42%            │ -57.10%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2016-02-06 │ YUM    │ 200.10          │ 98.16%             │ 237.73          │ 135.42%            │ -37.26%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2016-09-07 │ GOOGL  │ 303.84          │ 276.04%            │ 170.07          │ 110.48%            │ 165.56%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2017-01-10 │ AMZN   │ 1325.58         │ 1565.30%           │ 160.27          │ 101.34%            │ 1463.96%  │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2017-05-10 │ AAPL   │ 993.70          │ 159.32%            │ 725.26          │ 89.26%             │ 70.05%    │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2017-12-08 │ APTV   │ 1314.20         │ 53.49%             │ 1449.69         │ 69.32%             │ -15.82%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2018-07-05 │ ASML   │ 731.40          │ -25.52%            │ 1594.54         │ 62.39%             │ -87.90%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2018-09-03 │ NKE    │ 282.84          │ 17.46%             │ 391.02          │ 62.39%             │ -44.93%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2019-05-04 │ BABA   │ 525.55          │ -44.22%            │ 1529.99         │ 62.39%             │ -106.61%  │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2019-09-09 │ TSM    │ 347.37          │ 152.54%            │ 200.60          │ 45.84%             │ 106.70%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2019-12-10 │ DGX    │ 983.28          │ 16.98%             │ 1160.50         │ 38.07%             │ -21.08%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2020-02-03 │ YUM    │ 1000.50         │ -6.85%             │ 1427.53         │ 32.91%             │ -39.76%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2020-03-08 │ GOOGL  │ 455.76          │ 136.92%            │ 255.67          │ 32.91%             │ 104.01%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2020-06-09 │ AMZN   │ 1325.58         │ 188.12%            │ 614.21          │ 33.50%             │ 154.62%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2020-12-12 │ AAPL   │ 397.48          │ -20.04%            │ 663.65          │ 33.50%             │ -53.54%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2021-01-07 │ APTV   │ 2628.40         │ -9.55%             │ 3241.56         │ 11.55%             │ -21.10%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2021-05-06 │ ASML   │ 4388.40         │ -77.31%            │ 19452.08        │ 0.58%              │ -77.89%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2021-12-28 │ NKE    │ 1225.64         │ -43.87%            │ 1910.76         │ -12.49%            │ -31.38%   │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2022-02-02 │ BABA   │ 3153.30         │ -14.46%            │ 3363.68         │ -8.75%             │ -5.71%    │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2022-03-04 │ TSM    │ 3473.70         │ 10.21%             │ 3043.44         │ -3.44%             │ 13.65%    │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2022-04-12 │ DGX    │ 1229.10         │ -12.38%            │ 1331.43         │ -5.08%             │ -7.29%    │
├────────────┼────────┼─────────────────┼────────────────────┼─────────────────┼────────────────────┼───────────┤
│ 2022-05-02 │ YUM    │ 1100.55         │ -16.20%            │ 1318.24         │ 0.37%              │ -16.57%   │
└────────────┴────────┴─────────────────┴────────────────────┴─────────────────┴────────────────────┴───────────┘
@github-actions github-actions bot added bug Fix bug portfolio Portfolio menu labels Feb 9, 2023
@jmaslek
Copy link
Collaborator

jmaslek commented Feb 9, 2023

also any dividends are likely not accounted for ?

@JerBouma
Copy link
Contributor Author

JerBouma commented Feb 9, 2023

Indeed, dividends need to be written down as well but the stock splits take by far is the biggest hit. There are a lot more subtle things we need to take into account but it's a MVP. It works, just not 100% correct.

@rajanprabu
Copy link
Contributor

would be great if openBB can support multi currency portfolio. openBB already has currency exchange rate. Just the return column need to be normalised to one currency ( default USD, but user preference like GBP or EUR). But its not as crucial as splits. One can also adjust this in the reports..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fix bug portfolio Portfolio menu
Projects
None yet
Development

No branches or pull requests

4 participants