def test(df, q, periods, actions, pip_mul): logging.info('Testing: started...') # initial state s = getState(df, periods) # initial action a = getAction(q, s, 0, actions) # get reward r, ticks = getReward(df, a, pip_mul) # get delta d = getDelta(q, s, a, r) return q, r, d, ticks
def train(df, q, alpha, epsilon, periods, actions, pip_mul, std): logging.info('Training: started...') d = None # initial state s = getState(df, periods) # initial action a = getAction(q, s, epsilon, actions) # get reward r, ticks = getReward(df, a, pip_mul, std) # get delta d = getDelta(q, s, a, r) # update Q q = updateQ(q, s, a, d, r, alpha) return q, r, d, ticks
def predict(df, q, periods, actions, pip_mul, row): logging.info('Predict: started...') # state s = getState(df, periods) # get top actions predictions = [] for n in xrange(5): a, q_sa = getAction(q, s, 0, actions) a_trade, a_trail = a.split('-') if a_trade == 'buy': stop_loss = row['close'] - (float(a_trail) / pip_mul) else: stop_loss = row['close'] + (float(a_trail) / pip_mul) predictions.append('{0} [{1:.4f}] SL:{2:0.4f}'.format(a, q_sa, stop_loss)) logging.info('{0} action = {1}'.format(n, a)) actions.remove(a) return predictions
def predict(df, q, periods, actions, pip_mul, row): logging.info('Predict: started...') # state s = getState(df, periods) # get top actions predictions = [] for n in xrange(5): a, q_sa = getAction(q, s, 0, actions) a_trade, a_trail = a.split('-') if a_trade == 'buy': stop_loss = row['close'] - (float(a_trail) / pip_mul) else: stop_loss = row['close'] + (float(a_trail) / pip_mul) predictions.append('{0} [{1:.4f}] SL:{2:0.4f}'.format( a, q_sa, stop_loss)) logging.info('{0} action = {1}'.format(n, a)) actions.remove(a) return predictions