예제 #1
0
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
예제 #2
0
파일: results.py 프로젝트: vishnuvr/trading
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
예제 #3
0
파일: train.py 프로젝트: vishnuvr/trading
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
예제 #4
0
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
예제 #5
0
파일: predict.py 프로젝트: vishnuvr/trading
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
예제 #6
0
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