OpenBB icon indicating copy to clipboard operation
OpenBB copied to clipboard

Adjust for stock splits in portfolio engine

Open rajanprabu opened this issue 2 years ago • 4 comments

@JerBouma @jmaslek

As we discussed over twitter ( https://twitter.com/jrp980/status/1623386325142347784?s=46&t=_PF5iVHF-dn4emakfIM6ag) about the stock split bug in portfolio_engine. Here is the fix to adjust for stock splits.

https://github.com/OpenBB-finance/OpenBBTerminal/issues/4182

here is the PR for that. Its done in step 5 of __preprocess_transactions.

rajanprabu avatar Feb 09 '23 23:02 rajanprabu

I haven't looked into the code but basically what my expectation is, is that the volume and price is corrected after the split in which the user is informed this happend. So the following (values are random). Please note the remark regarding Yahoo Finance. If this source is used, the split is factored in within all historical data. We will also need an argument in which you can disable this correction if you entered values that are split-adjusted already (which you do by default if you would make an example portfolio with Yahoo Finance data)

Alternatively, you can also adjust the historical prices of Yahoo Finance which would correctly reflect the actual historical prices. I believe this is what @jmaslek does? Why I wouldn't like it as much is because it doesn't reflect your actual current positions (given that you gained a lot more shares).

image

Book1.xlsx

JerBouma avatar Feb 13 '23 09:02 JerBouma

@JerBouma for the example here

https://github.com/OpenBB-finance/OpenBBTerminal/pull/4195#discussion_r1102819521

Date Ticker Type Price Quantity Side Currency Fees yf_Ticker
02/11/22 GOOGL Stock 89.25 5 Buy USD 1 GOOGL
27/09/22 GOOGL Stock 99.75 5 Buy USD 1 GOOGL
26/04/22 GOOGL Stock 2400 1 Buy USD 1 GOOGL
22/04/22 GOOGL Stock 2400 1 Buy USD 1 GOOGL

with the modified code.. I got the following as portfolio returns

Screenshot 2023-02-20 at 21 30 03

rajanprabu avatar Feb 20 '23 20:02 rajanprabu

@JerBouma for the example here

#4195 (comment)

Date Ticker Type Price Quantity Side Currency Fees yf_Ticker 02/11/22 GOOGL Stock 89.25 5 Buy USD 1 GOOGL 27/09/22 GOOGL Stock 99.75 5 Buy USD 1 GOOGL 26/04/22 GOOGL Stock 2400 1 Buy USD 1 GOOGL 22/04/22 GOOGL Stock 2400 1 Buy USD 1 GOOGL with the modified code.. I got the following as portfolio returns

Screenshot 2023-02-20 at 21 30 03

Yes, this is correct. @jmaslek Can you take it from here? This is how it should be. Note again that Yahoo Finance adjusts all prices also those before the split.

JerBouma avatar Feb 21 '23 09:02 JerBouma

can merge once the linters pass

jmaslek avatar Feb 21 '23 13:02 jmaslek

Codecov Report

:exclamation: No coverage uploaded for pull request base (develop@1fb918f). Click here to learn what that means. Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #4195   +/-   ##
==========================================
  Coverage           ?   55.99%           
==========================================
  Files              ?      591           
  Lines              ?    53860           
  Branches           ?        0           
==========================================
  Hits               ?    30157           
  Misses             ?    23703           
  Partials           ?        0           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar Mar 27 '23 22:03 codecov[bot]