def main():
    coin_name = 'OMG'
    time_unit = TimeUnit.ONE_HOUR
    (train_data_info, evaluate_data_info) = get_data(coin_name=coin_name, time_unit=time_unit)
    print(train_data_info['first_datetime_krw'], train_data_info['last_datetime_krw'])
    print(evaluate_data_info['first_datetime_krw'], evaluate_data_info['last_datetime_krw'])
    train_env = UpbitEnvironment(coin_name=coin_name, time_unit=time_unit, data_info=train_data_info, environment_type=TradeEnvironmentType.TRAIN)
    evaluate_random_env = UpbitEnvironment(coin_name=coin_name, time_unit=time_unit, data_info=evaluate_data_info, environment_type=TradeEnvironmentType.TEST_RANDOM)
    net = train(coin_name, time_unit, train_env, evaluate_random_env)
    print('#### TEST SEQUENTIALLY')
    evaluate_sequential_env = UpbitEnvironment(coin_name=coin_name, time_unit=time_unit, data_info=evaluate_data_info, environment_type=TradeEnvironmentType.TEST_SEQUENTIAL)
    argmax_action_selector = ArgmaxTradeActionSelector(env=evaluate_sequential_env)
    evaluate_agent = rl_agent.DQNAgent(dqn_model=net, action_selector=argmax_action_selector, device=device)
    sequential_dqn_num_positives = []
    sequential_dqn_num_negatives = []
    sequential_dqn_num_episodes = []
    sequential_dqn_num_steps_per_episode = []
    sequential_dqn_total_profits = []
    for _ in range(10):
        (num_positive, num_negative, num_episodes, total_profit, avg_num_steps_per_episode) = evaluate_sequential_all('DQN', evaluate_sequential_env, evaluate_agent, data_size=len(evaluate_data_info['data']), verbose=False)
        sequential_dqn_num_positives.append(num_positive)
        sequential_dqn_num_negatives.append(num_negative)
        sequential_dqn_num_episodes.append(num_episodes)
        sequential_dqn_total_profits.append(total_profit)
        sequential_dqn_num_steps_per_episode.append(avg_num_steps_per_episode)
    dqn_msg = f'SEQUENTIAL: DQN - {np.mean(sequential_dqn_num_episodes):.1f} EPISODES - POSITIVE: {np.mean(sequential_dqn_num_positives):.1f}, NEGATIVE: {np.mean(sequential_dqn_num_negatives):.1f}, AVERAGE PROFIT {np.mean(sequential_dqn_total_profits):.1f}/STD {np.std(sequential_dqn_total_profits):.1f}, AVERAGE STEP {np.mean(sequential_dqn_num_steps_per_episode):.1f}'
    print(dqn_msg)
    random_action_selector = RandomTradeDQNActionSelector(env=evaluate_sequential_env)
    random_agent = rl_agent.DQNAgent(dqn_model=None, action_selector=random_action_selector, device=device)
    sequential_random_num_positives = []
    sequential_random_num_negatives = []
    sequential_random_num_episodes = []
    sequential_random_num_steps_per_episode = []
    sequential_random_total_profits = []
    for _ in range(10):
        (num_positive, num_negative, num_episodes, total_profit, avg_num_steps_per_episode) = evaluate_sequential_all('RANDOM', evaluate_sequential_env, random_agent, data_size=len(evaluate_data_info['data']), verbose=False)
        sequential_random_num_positives.append(num_positive)
        sequential_random_num_negatives.append(num_negative)
        sequential_random_num_episodes.append(num_episodes)
        sequential_random_total_profits.append(total_profit)
        sequential_random_num_steps_per_episode.append(avg_num_steps_per_episode)
    random_msg = f'SEQUENTIAL: RANDOM - {np.mean(sequential_random_num_episodes):.1f} EPISODES - POSITIVE: {np.mean(sequential_random_num_positives):.1f}, NEGATIVE: {np.mean(sequential_random_num_negatives):.1f}, AVERAGE PROFIT {np.mean(sequential_random_total_profits):.1f}/STD {np.std(sequential_random_total_profits):.1f}, AVERAGE STEP {np.mean(sequential_random_num_steps_per_episode):.1f}'
    print(random_msg)
    pusher.send_message('me', dqn_msg)
    pusher.send_message('me', random_msg)
def main():
    coin_name = 'OMG'
    time_unit = TimeUnit.ONE_HOUR
    (train_data_info, evaluate_data_info) = get_data(coin_name=coin_name, time_unit=time_unit)
    print(train_data_info['first_datetime_krw'], train_data_info['last_datetime_krw'])
    print(evaluate_data_info['first_datetime_krw'], evaluate_data_info['last_datetime_krw'])
    train_env = UpbitEnvironment(coin_name=coin_name, time_unit=time_unit, data_info=train_data_info, environment_type=TradeEnvironmentType.TRAIN)
    evaluate_random_env = UpbitEnvironment(coin_name=coin_name, time_unit=time_unit, data_info=evaluate_data_info, environment_type=TradeEnvironmentType.TEST_RANDOM)
    net = train(coin_name, time_unit, train_env, evaluate_random_env)
    print('#### TEST SEQUENTIALLY')
    evaluate_sequential_env = UpbitEnvironment(coin_name=coin_name, time_unit=time_unit, data_info=evaluate_data_info, environment_type=TradeEnvironmentType.TEST_SEQUENTIAL)
    argmax_action_selector = ArgmaxTradeActionSelector(env=evaluate_sequential_env)
    evaluate_agent = rl_agent.DQNAgent(dqn_model=net, action_selector=argmax_action_selector, device=device)
    sequential_dqn_num_positives = []
    sequential_dqn_num_negatives = []
    sequential_dqn_num_episodes = []
    sequential_dqn_num_steps_per_episode = []
    sequential_dqn_total_profits = []
    for _ in range(10):
        (num_positive, num_negative, num_episodes, total_profit, avg_num_steps_per_episode) = evaluate_sequential_all('DQN', evaluate_sequential_env, evaluate_agent, data_size=len(evaluate_data_info['data']), verbose=False)
        sequential_dqn_num_positives.append(num_positive)
        sequential_dqn_num_negatives.append(num_negative)
        sequential_dqn_num_episodes.append(num_episodes)
        sequential_dqn_total_profits.append(total_profit)
        sequential_dqn_num_steps_per_episode.append(avg_num_steps_per_episode)
    dqn_msg = f'SEQUENTIAL: DQN - {np.mean(sequential_dqn_num_episodes):.1f} EPISODES - POSITIVE: {np.mean(sequential_dqn_num_positives):.1f}, NEGATIVE: {np.mean(sequential_dqn_num_negatives):.1f}, AVERAGE PROFIT {np.mean(sequential_dqn_total_profits):.1f}/STD {np.std(sequential_dqn_total_profits):.1f}, AVERAGE STEP {np.mean(sequential_dqn_num_steps_per_episode):.1f}'
    print(dqn_msg)
    random_action_selector = RandomTradeDQNActionSelector(env=evaluate_sequential_env)
    random_agent = rl_agent.DQNAgent(dqn_model=None, action_selector=random_action_selector, device=device)
    sequential_random_num_positives = []
    sequential_random_num_negatives = []
    sequential_random_num_episodes = []
    sequential_random_num_steps_per_episode = []
    sequential_random_total_profits = []
    for _ in range(10):
        (num_positive, num_negative, num_episodes, total_profit, avg_num_steps_per_episode) = evaluate_sequential_all('RANDOM', evaluate_sequential_env, random_agent, data_size=len(evaluate_data_info['data']), verbose=False)
        sequential_random_num_positives.append(num_positive)
        sequential_random_num_negatives.append(num_negative)
        sequential_random_num_episodes.append(num_episodes)
        sequential_random_total_profits.append(total_profit)
        sequential_random_num_steps_per_episode.append(avg_num_steps_per_episode)
    random_msg = f'SEQUENTIAL: RANDOM - {np.mean(sequential_random_num_episodes):.1f} EPISODES - POSITIVE: {np.mean(sequential_random_num_positives):.1f}, NEGATIVE: {np.mean(sequential_random_num_negatives):.1f}, AVERAGE PROFIT {np.mean(sequential_random_total_profits):.1f}/STD {np.std(sequential_random_total_profits):.1f}, AVERAGE STEP {np.mean(sequential_random_num_steps_per_episode):.1f}'
    print(random_msg)
    pusher.send_message('me', dqn_msg)
    pusher.send_message('me', random_msg)