Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Placing orders on a new security whose daily prices are loaded through fetch_csv

Hello,

I am building an Fx strategy and to get acquainted with Quantopian, I have coded a simple algorithm of having 100% allocation in an FX Asset - USDTRY. I have USDTRY FX CSV historical data that I load using fetcher and run back test on. I also include a stock in the universe using contex.stock='NFLX' so that there is an asset to pass in order_target_percent. However I want prices for NFLX to be taken from my supplied CSV file and not the actual prices of NFLX in Quantopian data set . Can someone please identify where I am going wrong? If I remove the asset from context then I can only see prices in the backtest and am unable to send orders and see algorithm's performance.

Thanks
Farhan

"""
This is a template algorithm on Quantopian for you to adapt and fill in.  
"""
import pandas as pd

def pre_process(df):  
    df = df.reindex(df.index[::-1])  
    mean=df['price'].rolling(window=30,center=False).mean();  
    df['mean']=mean  
    return df


def initialize(context):  
    fetch_csv('https://docs.google.com/spreadsheets/d/1W9oFu2o3icCfdb-wKiatDlp1WaRAskMv4GzvIgRqNug/pub?gid=2104461388&single=true&output=csv',  
               date_column = 'date',  
               symbol = 'USDTRY',  
               pre_func=pre_process,  
               date_format = '%m-%d-%y')  
    context.stock = symbol('NFLX')  
    # Rebalance every day, 1 hour after market open.  
    schedule_function(my_rebalance, date_rules.every_day(), time_rules.market_open(hours=1))

def my_rebalance(context,data):  
    average_price=data.current('USDTRY','mean')  
    current_price=data.current('USDTRY','price')  
    order_target_percent(context.stock, 1)  
    record(current_price=current_price, average_price=average_price)

def handle_data(context,data):  
    for stock in data:  
        print stock.symbol