Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Calculation for adjusted cost base per unit of a position?

Hi Everyone
Does anyone know how to calculate the adjusted cost base per unit of a position by including stock splits ?
If yes, can you please share, in particular where to get the split info from?
Here are the calculations I am trying to implement
https://www.adjustedcostbase.ca/blog/the-effect-of-stock-splits-on-adjusted-cost-base/
A related question if I may - can anyone confirm whether the context.portfolio.positions.amount is updated in case of a stock split?
Much appreciate and a pleasant evening
Savio

5 responses

Hi Everyone
I am going to use a workaround for now by using today's price and yesterday's closing shares and value.
Would love to know whether context.portfolio.positions.amount is updated automatically.
In the meantime I will add code to check this amount.
Kind regards
Savio

Both the amount and cost basis are automatically adjusted for splits. No need to worry about doing the calculation on your own. See attached backtest. This buys AAPL once and holds. It logs the current amount and cost_basis each day. Run it between dates 6/5/2014 and 6/15/2014 when AAPL had a 7:1 split on 6/9/2014. Notice the logs correctly reflect the split.

Hello Dan
Thank you for your kind help and all your time - much appreciate.
And for the detailed guidance.
Do you know if the cost basis is the adjusted cost base or the volume weighted average price?
I was reading through the API docs and perhaps incorrectly concluded that the cost basis was the VWAP.
Do let me know at your convenience.
Much appreciate and a pleasant day
Savio

The cost_basis is the volume weighted average cost per share. The cost per share also includes commissions. If you really want to see how it's calculated one can look at the open source code at https://github.com/quantopian/zipline/blob/master/zipline/finance/position.py

Thank you Dan that is most helpful, in particular the link - I will digest it. At first glance it seems like the the cost_basis is the same as ACB per unit - let me run some sample calculations. Much appreciate and a pleasant day Savio