Quantopian Pipeline

by: chgchksg128, 9 years ago


hi,
I refer to your tutorial for Pipeline API. I copy your code and test run in Quantopian.
However, my result and your result was hugely different.
In your tutorial example, your algorithm run returns vs SPy is 238.2% vs 174.4%
While for my run with your code, which started from the same date until today, the returns is -39.6%
I am confuse why the same code, should have give me the same result but it doesn't.
Also, the log part was # as I run into run time error

from quantopian.pipeline import Pipeline
from quantopian.algorithm import attach_pipeline, pipeline_output
from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.factors import SimpleMovingAverage

def initialize(context):
    set_symbol_lookup_date('2007-01-04')
    pipe = Pipeline()
    attach_pipeline(pipe, 'pipeline_tutorial')
    _50ma = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=50)
    _200ma = SimpleMovingAverage(inputs=[USEquityPricing.close], window_length=200)
    pipe.add(_50ma, '_50ma')
    pipe.add(_200ma, '_200ma')
    pipe.add(_50ma/_200ma, 'ma_ratio')
    pipe.set_screen(_50ma/_200ma > 1)
    context.stocks_sold = []
    
def before_trading_start(context, data):
    output = pipeline_output('pipeline_tutorial')
    context.my_universe = output.sort('ma_ratio', ascending=False).iloc[:100]
    update_universe(context.my_universe.index)    

def handle_data(context, data):
    cash = context.portfolio.cash
    purchase_value = 1500
    for stock in context.my_universe.index:
        if stock not in context.portfolio.positions:
            if purchase_value < cash:
                try:
                    order_target_value(stock, purchase_value)
                    cash -= purchase_value
                    ####################################
                    if stock in context.stocks_sold:
                        context.stocks_sold.remove(stock)
                except:
                    pass

    for stock in context.portfolio.positions:
        if stock not in context.my_universe.index and stock not in context.stocks_sold:
            order_target_value(stock, 0)
            #################################
            context.stocks_sold.append(stock)

    record('Leverage',context.account.leverage)

    print "SHORT LIST"
    #log.info("n" + str(context.short_list.sort(['sma_rank'], ascending=True).head()))

    print "LONG LIST"
    #log.info("n" + str(context.long_list.sort(['sma_rank'], ascending=False).head()))




You must be logged in to post. Please login or register an account.