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

Hi All,

I am playing around with my first algo and wanted some help on capital used/borrowing and max notionals. My aim is to try and create a long only portfolio where a -1 signal would sell all my current holding and if I am already long then dont add to the current longs.

Please could someone have a look at my code and let me know whether I am doing something totally wrong in terms of capital used. I pretty much want to be sensible and in theory want to see if I laid down say 50k max capital then how I can abide by that?

thanks.

3 responses

You could put in a check before getting "long" like:

new_capital_requirement = context.portfolio.capital_used - (num_shares*price)  
if net_sig > 0 and (curr_shares == 0 or new_capital_requirement > context.min_notional):  
# buying "more"  

Hi Hardik,

Thanks for your reply. Are you able to elaborate further on the additional check? ie what it would do and how that would limit me from using more than say initial capital.

thanks,

Hi,

I have added a contraint to avoid the algo from using more than 50k cash and always equally weighting the current cash to the len(stocks) if a buy signal occurs.

does this seem sensible?

thanks.