Beispiel #1
0
def show_train_result(result, val_position, initial_offset):
    """ Displays training results. """
    if val_position == initial_offset or val_position == 0.0:
        logging.info('Episode {}/{} - Train Position: {}  Val Position: USELESS  Train Loss: {:.4f}  (~{:.4f} secs)'
                     .format(result[0], result[1], format_position(result[2]), result[3], result[4]))
    else:
        logging.info('Episode {}/{} - Train Position: {}  Val Position: {}  Train Loss: {:.4f}  (~{:.4f} secs)'
                     .format(result[0], result[1], format_position(result[2]), format_position(val_position), result[3], result[4]))
Beispiel #2
0
def show_train_result(result, val_position, initial_offset):
    if val_position == initial_offset or val_position == 0.0:
        print(
            'Episode {}/{} - Train Position: {}  Val Position: USELESS  Train Loss: {:.4f}  (~{:.4f} secs)'
            .format(result[0], result[1], format_position(result[2]),
                    result[3], result[4]))
    else:
        print(
            'Episode {}/{} - Train Position: {}  Val Position: {}  Train Loss: {:.4f}  (~{:.4f} secs)'
            .format(result[0], result[1], format_position(result[2]),
                    format_position(val_position), result[3], result[4]))
Beispiel #3
0
def evaluate_model(agent, data, window_size, debug):
    data_length = len(data) - 1
    state = get_state(data, 0, window_size + 1)
    total_profit = 0
    agent.inventory = []
    for t in range(data_length):
        action = agent.act(state, is_eval=True)
        # SIT
        next_state = get_state(data, t + 1, window_size + 1)
        reward = 0
        # BUY
        if action == 1:
            agent.inventory.append(data[t])
            if debug:
                logging.debug('Buy at: {}'.format(format_currency(data[t])))
        # SELL
        elif action == 2 and len(agent.inventory) > 0:
            bought_price = agent.inventory.pop(0)
            reward = max(data[t] - bought_price, 0)
            total_profit += data[t] - bought_price
            if debug:
                logging.debug('Sell at: {} | Position: {}'.format(
                    format_currency(data[t]),
                    format_position(data[t] - bought_price)))

        done = True if t == data_length - 1 else False
        agent.memory.append((state, action, reward, next_state, done))
        state = next_state

        if done:
            return total_profit
Beispiel #4
0
def show_eval_result(model_name, profit, initial_offset):
    if profit == initial_offset or profit == 0.0:
        logging.info('{}: USELESS\n'.format(model_name))
    else:
        logging.info('{}: {}\n'.format(model_name, format_position(profit)))