Back to Community
Doesn't backtest in quantopian auto-adjust split issue? Is it a bug?

Hi there,
When I am running a backtest, I found my portfolio is hurt by 'split' issue in the following example. Could someone help me with this? How to avoid this situation?

Clone Algorithm
2
Loading...
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
"""
This is a template algorithm on Quantopian for you to adapt and fill in.
"""
import quantopian.pipeline.data.psychsignal as psy

from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline import Pipeline
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import AverageDollarVolume
from quantopian.pipeline.filters import Q500US
def initialize(context):
    my_pipe = make_pipeline()
    attach_pipeline(my_pipe, 'my_pipeline')
    context.zg=symbol('ZG')
    schedule_function(trading,date_rules.every_day(),
                      time_rules.market_close(minutes=5))


def make_pipeline():    
    pricing=USEquityPricing.close.latest

    # Volatility filter (I made it sector neutral to replicate what UBS did).  Uncomment and
    # change the percentile bounds as you would like before adding to 'universe'
   

    # Liquidity filter (Uncomment and change the percentile bounds as you would like before
    # adding to 'universe'
   
    universe = (
        Q500US()
        & (pricing > 10)
        # & liquidity_filter
        # & vol_filter
    )
    
    columns={'sentiment_bull':psy.aggregated_twitter_withretweets_stocktwits.bull_scored_messages.latest,
            'sentiment_bearish':psy.aggregated_twitter_withretweets_stocktwits.bear_scored_messages.latest}


    return Pipeline(
        # columns=columns,
        screen=universe
    )

def before_trading_start(context, data):
    # Gets our pipeline output every day.
    context.output = pipeline_output('my_pipeline')
def get_prices(context, data):
    Universe500=context.output.index.tolist()
    prices = data.current(Universe500, "last_traded")
    print(prices)
    current_price =data.history(Universe500, 'close', 1, '1d').iloc[0] 
    print(current_price)
def trading(context,data):
    port = context.portfolio.positions
    if context.zg not in port:
        order_target_percent(context.zg,1.0)
    

    
    
    
    
    

There was a runtime error.