Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
SMA Help

Hi all,

I'm new to Quantopian and Python. In order to learn how to use Quantopian, I put together a sma algo.
I would like to ask you if there's a way to prevent shares for being sold at a loss (and/or sold for such a low margin that the broker's commissions wold turn the transaction into a loss). Ideally, we should be able to hold the shares until the prices come back up.

Thanks in advance!

Cheers,

Ariel

1 response

Hi Ariel,

Try using the average cost price of your stock position. This can be done by (as per help documentation):

The position object represents a current open position, and is contained inside the positions dictionary. For example, if you had an open AAPL position, you'd access it using context.portfolio.positions[symbol('AAPL')]. The position object has the following properties:

cost_basis
Float: The volume-weighted average price paid (price and commission) per share in this position.