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 %.

Clone Algorithm
3
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 597ec146a98d254f1d93814e
There was a runtime error.
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