Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Algorithm Performance in Day Trading Strategy

Hello I have coded a strategy that all days rank the stocks with the biggest gap, between yesterday close and today open. Then the strategy, have a for loop to retrieve information(technical indicators) for each of the stocks in the universe. Some of these indicators are the RSI, EMA's and Parabolic SAR.

The setup to buy is when there is a switch in the parabolic SAR between 2 periods and the short ema is higher than ema medium and ema high. Once the setup to buy is met, the algo trigger an order by 10000 USD(order_value method). I use resample to convert the timeperiod from 1 minute to 1 hour. The issue is that the performace is too slow. I have readed others threads about the optimal method to work with talib but not find a way to have a better performance(with performance I mean the speed of the backtesting.

Also the algorithm made few transactions. If somenone can help with this, I really appreciate!!

Thanks
Nicolás Ferrari

4 responses

First off I noticed that the 'trading_setup' method has two loops. The second is nested in the first

for stock in context.securities.index:  
        highs_frame = data.history(stock, 'high',100*60, '1m').resample('H').last()  
        .  
        .  
        for stock in context.portfolio.positions:  
            closes_frame = data.history(stock, 'price', 100*60,'1m').resample('H').last()

I believe you want these to be two independent loops. First loop over the 'context.securities.index' then loop over 'context.portfolio.positions'? If so, remove the indent of the second loop and it runs much faster.

Dan, thanks for the response. You are rigth in the comment, I forgot to put the second loop in the same line respect the first.
I have fixed the error and the new results are in the attach. The backtest run a bit more fast, and that is a good new.

However in my opinion, this algo has two issues. The first one is the low returns that have, that is related to the few transactions. I don't if something is lacking in order to do more trades or not.

The second one is that even though I put the set_slippage(slippage.VolumeShareSlippage(volume_limit=1)) setup to trade one transaction per stock, there are more than one transaction for the same stock.

I appreciate the colaboration and help.

Thanks!!

For some visibility, in the log window this is some ordering detail with track_orders. Run this and look into the log output.
I merely did copy/paste of the code there and turned off other logging temporarily.
Typically I would copy the output when done to Notepad++ to study it. There, highlighting a symbol or order id, other instances of it also become highlighted. Some might prefer grep. Let me know if questions.

That's great!! Thanks!
I will review the output by my own , and observe the orders. Also I reduce the initial capital to 500,000 and the returns are a bit bigger (-1.7% + 1.7%).
Also I include the SimpleBeta factor in the pipeline.