Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Fetch_CSV questions

Hi, I have some questions regarding fetch_csv() function. I'm trying to backtest some strategies for bitcoin/altcoins trading but currently I need to understand how to properly import the CSV data.

As example I'm using Bitstamp CSV and converted it to 60 minute CSV with pyalgotrade leaving me with the following file:

Date,Open,High,Low,Close,Volume,Adj Close  
2015-02-02 00:00:00,226.93,230.0,225.76,229.72,382.50652246,  
2015-02-02 01:00:00,229.85,229.97,226.0,229.46,468.38552913,  
2015-02-02 02:00:00,228.3,230.0,226.25,230.0,381.05275657,  
2015-02-02 03:00:00,230.0,232.77,227.89,229.64,446.65950468,  
2015-02-02 04:00:00,229.62,231.28,228.07,228.5,267.76584473,  
2015-02-02 05:00:00,228.15,228.62,226.03,226.63,219.22888965,  
2015-02-02 06:00:00,227.55,227.55,221.79,221.86,749.20026781,  
2015-02-02 07:00:00,222.03,227.0,222.03,225.14,236.28343467,  
2015-02-02 08:00:00,224.52,226.84,224.0,224.2,385.30815761,  
2015-02-02 09:00:00,224.24,225.45,223.92,224.8,352.475944,  
2015-02-02 10:00:00,224.4,225.35,223.81,224.96,299.04935687,  
2015-02-02 11:00:00,224.96,226.0,224.0,226.0,350.79373073,  
2015-02-02 12:00:00,226.03,229.0,225.31,228.2,922.02308712,  
2015-02-02 13:00:00,228.21,229.1,224.11,226.15,810.33476978,  
2015-02-02 14:00:00,226.56,227.8,225.71,226.11,350.48694909,  
2015-02-02 15:00:00,226.8,227.77,222.12,223.33,1169.25602631,  
2015-02-02 16:00:00,223.33,225.56,221.79,224.89,810.92373195  

Once I have this CSV I imported it to my strategy with the following code:

fetch_csv(  
        'https://dl.dropboxusercontent.com/s/91i6imabwh40iwh/30min-bitstampUSD.csv',  
        date_column='Date',  
        date_format='%Y-%m-%d %H:%M:%S',  
        symbol='BTC'  
    )  

After this I have some questions:

1- I want to backtest this data in different timeframes, as I have a 1 hour dataset I want to test for 1 hour, 2 hour, 3 hour and so on. As the handle_data function runs every minute how do I work with different timeframes? Is there any 'best practice' to do this?

2- When I try to print the Open price from handle_data() it always print the same value (Which is not in the dataset) for every day regardless the hour.

log.info(data.current('BTC', 'Open'))  

Sample Output:

2015-02-02 handle_data:14 INFO 232.88  
2015-02-02 handle_data:14 INFO 232.88  
2015-02-02 handle_data:14 INFO 232.88  
2015-02-02 handle_data:14 INFO 232.88  
[...]<- Same value for each minute of each day?
2015-02-02 handle_data:14 INFO 232.88  
2015-02-02 handle_data:14 INFO 232.88  
2015-02-02 handle_data:14 INFO 232.88  
2015-02-03 handle_data:14 INFO 229.77  
2015-02-03 handle_data:14 INFO 229.77  
2015-02-03 handle_data:14 INFO 229.77  
2015-02-03 handle_data:14 INFO 229.77  
[...]

3- When I try to print the date from the CSV data I get NaN. This is the code:

log.info(data.current('BTC', 'Date'))  

I'll post more info if needed but I feel a bit lost at the moment and I think I need some guidance with this.
Regards

1 response

The fetch_csv function doesn't state that it supports hours. It probably does not support doing things in an hourly granularity