def test_code():
# this is a helper function you can use to test your code
# note that during autograding his function will not be called.
# Define input parameters
verbose = False
# # initializating by reading data from files
data_start = '2007-12-01'
data_end = '2011-12-31'
data = get_data(['IBM'], pd.date_range(data_start, data_end))
data, data['SMA'], data['StDev'] = add_bband(data,N=20)
data = add_mmt(data)
data = add_MACD(data)
# generate the daily return
data['DRet'] = data.iloc[:,1].slice_shift(-1)/data.iloc[:,1] - 1
# for testing of bollinger band only
plt.plot(data.iloc[:,1][20:300])
plt.plot(data.SMA[20:300]+2*data.StDev[20:300])
plt.plot(data.SMA[20:300]-2*data.StDev[20:300])
plt.plot(data.SMA[20:300])
plt.show()
# mmt_div = bin_divider(data.mmt)
# bbp_div = bin_divider(data.bbp)
# MACD_div = bin_divider(data.MACD)
#
# sd = dt.datetime(2008, 1, 1); ed = dt.datetime(2009, 1, 1)
# temp = data.index[data.index > sd]
# print temp[0]
if verbose:
print 'mmt_div:', mmt_div
print 'bbp_div:', bbp_div
print 'MACD_div:', MACD_div
test = [data.mmt[500],data.bbp[500],data.MACD[500]]
print test
s = get_state(test,[mmt_div,bbp_div,MACD_div],1)
print s
# # start and end date the learner concerns
# start_date = '2007-12-31'
# end_date = '2009-12-31'
# # generate training data
# trainX = data[['bband','mmt','MACD']][start_date:end_date].values
# trainY = data.Y[start_date:end_date].values
#
# plt.plot(data.iloc[:,1]['2007-12-31':'2009-12-31'],'r')
# # adjust prediction Y to scale up with price
# enlarge = (data.iloc[:,1].max()-data.iloc[:,1].min())/(trainY.max()-trainY.min())
# plt.plot(data.Y[start_date:end_date]*enlarge+(data.iloc[:,1].min()+data.iloc[:,1].max())/2,'g')
# plt.show()
#
# # orders = generate_order(ana_data)
评论列表
文章目录