<s> import random <EOL> import numpy as np <EOL> import pandas as pd <EOL> from zipline . finance . trading import TradingEnvironment <EOL> from zipline . data . us_equity_minutes import BcolzMinuteBarWriter <EOL> def generate_daily_test_data ( first_day , <EOL> last_day , <EOL> starting_open , <EOL> starting_volume , <EOL> multipliers_list , <EOL> path ) : <EOL> days = TradingEnvironment . instance ( ) . days_in_range ( first_day , last_day ) <EOL> days_count = len ( days ) <EOL> o = np . zeros ( days_count , dtype = np . uint32 ) <EOL> h = np . zeros ( days_count , dtype = np . uint32 ) <EOL> l = np . zeros ( days_count , dtype = np . uint32 ) <EOL> c = np . zeros ( days_count , dtype = np . uint32 ) <EOL> v = np . zeros ( days_count , dtype = np . uint32 ) <EOL> last_open = starting_open * <NUM_LIT:1000> <EOL> last_volume = starting_volume <EOL> for idx in range ( days_count ) : <EOL> new_open = last_open + round ( ( random . random ( ) * <NUM_LIT:5> ) , <NUM_LIT:2> ) <EOL> o [ idx ] = new_open <EOL> h [ idx ] = new_open + round ( ( random . random ( ) * <NUM_LIT> ) , <NUM_LIT:2> ) <EOL> l [ idx ] = new_open - round ( ( random . random ( ) * <NUM_LIT> ) , <NUM_LIT:2> ) <EOL> c [ idx ] = ( h [ idx ] + l [ idx ] ) / <NUM_LIT:2> <EOL> v [ idx ] = int ( last_volume + ( random . randrange ( - <NUM_LIT:10> , <NUM_LIT:10> ) * <NUM_LIT> ) ) <EOL> last_open = o [ idx ] <EOL> last_volume = v [ idx ] <EOL> if len ( multipliers_list ) > <NUM_LIT:0> : <EOL> range_start = <NUM_LIT:0> <EOL> for multiplier_info in multipliers_list : <EOL> range_end = days . searchsorted ( multiplier_info [ <NUM_LIT:0> ] ) <EOL> o [ range_start : range_end ] /= multiplier_info [ <NUM_LIT:1> ] <EOL> h [ range_start : range_end ] /= multiplier_info [ <NUM_LIT:1> ] <EOL> l [ range_start : range_end ] /= multiplier_info [ <NUM_LIT:1> ] <EOL> c [ range_start : range_end ] /= multiplier_info [ <NUM_LIT:1> ] <EOL> v [ range_start : range_end ] *= multiplier_info [ <NUM_LIT:1> ] <EOL> range_start = range_end <EOL> df = pd . DataFrame ( { <EOL> "<STR_LIT>" : o , <EOL> "<STR_LIT>" : h , <EOL> "<STR_LIT>" : l , <EOL> "<STR_LIT>" : c , <EOL> "<STR_LIT>" : v <EOL> } , columns = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , index = days ) <EOL> df . to_csv ( path , index_label = "<STR_LIT>" ) <EOL> def generate_minute_test_data ( first_day , <EOL> last_day , <EOL> starting_open , <EOL> starting_volume , <EOL> multipliers_list , <EOL> path ) : <EOL> """<STR_LIT>""" <EOL> full_minutes = BcolzMinuteBarWriter . full_minutes_for_days ( <EOL> first_day , last_day ) <EOL> minutes_count = len ( full_minutes ) <EOL> minutes = TradingEnvironment . instance ( ) . minutes_for_days_in_range ( <EOL> first_day , last_day ) <EOL> o = np . zeros ( minutes_count , dtype = np . uint32 ) <EOL> h = np . zeros ( minutes_count , dtype = np . uint32 ) <EOL> l = np . zeros ( minutes_count , dtype = np . uint32 ) <EOL> c = np . zeros ( minutes_count , dtype = np . uint32 ) <EOL> v = np . zeros ( minutes_count , dtype = np . uint32 ) <EOL> last_open = starting_open * <NUM_LIT:1000> <EOL> last_volume = starting_volume <EOL> for minute in minutes : <EOL> idx = full_minutes . searchsorted ( minute ) <EOL> new_open = last_open + round ( ( random . random ( ) * <NUM_LIT:5> ) , <NUM_LIT:2> ) <EOL> o [ idx ] = new_open <EOL> h [ idx ] = new_open + round ( ( random . random ( ) * <NUM_LIT> ) , <NUM_LIT:2> ) <EOL> l [ idx ] = new_open - round ( ( random . random ( ) * <NUM_LIT> ) , <NUM_LIT:2> ) <EOL> c [ idx ] = ( h [ idx ] + l [ idx ] ) / <NUM_LIT:2> <EOL> v [ idx ] = int ( last_volume + ( random . randrange ( - <NUM_LIT:10> , <NUM_LIT:10> ) * <NUM_LIT> ) ) <EOL> last_open = o [ idx ] <EOL> last_volume = v [ idx ] <EOL> if len ( multipliers_list ) > <NUM_LIT:0> : <EOL> for idx , multiplier_info in enumerate ( multipliers_list ) : <EOL> start_idx = idx * <NUM_LIT> <EOL> end_idx = start_idx + <NUM_LIT> <EOL> o [ start_idx : end_idx ] /= multiplier_info [ <NUM_LIT:1> ] <EOL> h [ start_idx : end_idx ] /= multiplier_info [ <NUM_LIT:1> ] <EOL> l [ start_idx : end_idx ] /= multiplier_info [ <NUM_LIT:1> ] <EOL> c [ start_idx : end_idx ] /= multiplier_info [ <NUM_LIT:1> ] <EOL> v [ start_idx : end_idx ] *= multiplier_info [ <NUM_LIT:1> ] <EOL> df = pd . DataFrame ( { <EOL> "<STR_LIT>" : o , <EOL> "<STR_LIT>" : h , <EOL> "<STR_LIT>" : l , <EOL> "<STR_LIT>" : c , <EOL> "<STR_LIT>" : v <EOL> } , columns = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , index = minutes ) <EOL> df . to_csv ( path , index_label = "<STR_LIT>" ) </s>
