Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Selling incorrect figure for only 1 ticker?

Hi all,

I believe there is something messed up with the TVIZ historical data. When running the below code, my algo sells 70% of my initial cash on day 1. Whereas if I change this to TVIX, it sells just 10%(as it should). Am I missing something here? Thanks for the help!

def initialize(context):

    context.stock = sid(40514)

def handle_data(context, data):

    stock = context.stock  
    current_price = data.current(context.stock, 'price')  
    equity = (context.portfolio.cash + context.portfolio.positions_value)  
    TVIX_Amount = context.portfolio.positions[symbol('TVIZ')].amount*current_price  
    if context.portfolio.positions[symbol('TVIZ')].amount == 0:  
        order_target_value(stock, -.1*equity)  
3 responses

Any help here would be appreciated!

There may be liquidity problem on day 1.
Try this:

def initialize(context):  
    schedule_function(trade, date_rules.every_day(), time_rules.market_open(minutes = 65))  
def trade(context, data):  
    stock = symbol('TVIZ')  # TVIX, TVIZ  
    order_target_percent(stock, -.2)  

Thank you!

So what is the schedule_function actually doing?