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

I am a newbie to quantopian but am working on some simple mean reversion.

In the backtest I need some help understanding why I'm selling shares on March 4 when I coded my bot to only sell shares when the current price is > than average price by a certain %.

3 responses

Manik,

If I would like only sell shares when the current price is > than average price by a certain %
then I would code lines 25-31 this way:

    if data.can_trade(context.security):  
        if current_price < average_price*(1.0 - percentage):  
            order_target_percent(context.security, 1.0)  
            log.info('long position')  
        elif current_price > average_price*(1.0 + cover_percentage):  
            order_target_percent(context.security, -1.0)  
            log.info('sell shares')  

That worked well, thanks but there is some more confusion after that.

If you run the backtest for 5/1/2017 to 7/28/2017 there are small transaction on June 14 and June 16 which I can't explain. These transactions are for ($45,155) and ($37,120) and I can't figure out where they're coming from

There was 0.24 Dividend payment on Jun 15, 2017