Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Is there a better way to keep a track of certain stock's profits and loss so that we can buy more or less

If I long stock A with $100, I'd like to buy more A with unrealized profits if A>$103, and if A >$106, I will buy more A again. Assuming I always do a order_target_percent(A,1.0). I tried to record the last trading value of A every time I buy A. Then I realized if there's a stock split with A, my method won't work. Any ideas guys?

1 response

Always use context.portfolio.positions[stock].cost_basis to look up what you paid for a security as that value will be adjusted for splits. It will be the average price paid for that position.

The reason your method won't work is because unrealized profits are equal to the increased price of the share. To realize the profit you need to sell shares, which are as expensive to buy and as they are to sell (minus fees and slippage). What you're trying to do is a paradox.