예제 #1
0
    def test_list_files(self):
        trade = Trade()

        list = trade.list_tfdata_list()
        print(list)

        print('number of files->', trade.number_of_files)
예제 #2
0
    def test_read_one_episode(self):
        trade = Trade()

        trade.new_episode()

        num_of_records = 0

        for i in range(1000):
            if trade.new_sec():
                self.assertIsNotNone(trade.boards)
                self.assertIsNotNone(trade.buy_trade_price)
                self.assertIsNotNone(trade.sell_trade_price)
                self.assertIsNotNone(trade.buy_book_price)
                self.assertIsNotNone(trade.sell_book_vol)
                self.assertIsNotNone(trade.sell_book_price)
                self.assertIsNotNone(trade.buy_book_vol)
                self.assertIsNotNone(trade.market_sell_price)
                self.assertIsNotNone(trade.buy_trade_vol)
                self.assertIsNotNone(trade.fix_buy_price)
                self.assertIsNotNone(trade.market_buy_price)
                self.assertIsNotNone(trade.time)
                num_of_records += 1
                print(trade.time)
            else:
                break

        print(num_of_records)
예제 #3
0
    def test_read_one_episode(self):
        trade = Trade()

        trade.new_episode()

        num_of_records = 0

        while trade.new_sec():
            self.assertIsNotNone(trade.board)
            self.assertIsNotNone(trade.buy_trade_price)
            self.assertIsNotNone(trade.sell_trade_price)
            self.assertIsNotNone(trade.buy_book_price)
            self.assertIsNotNone(trade.sell_book_vol)
            self.assertIsNotNone(trade.sell_book_price)
            self.assertIsNotNone(trade.buy_book_vol)
            self.assertIsNotNone(trade.market_sell_price)
            self.assertIsNotNone(trade.buy_trade_vol)
            self.assertIsNotNone(trade.fix_buy_price)
            self.assertIsNotNone(trade.market_buy_price)
            self.assertIsNotNone(trade.time)

            print(trade.time)

            num_of_records += 1

        print(num_of_records)
예제 #4
0
    def test_new_episode(self):
        trade = Trade()

        trade.new_episode()

        result = trade.new_sec()

        print(result)

        print(trade.time)
예제 #5
0
    def one_episode(self, env: Trade):
        s = env.new_episode()

        while True:
            action = self.policy(s)
            print('action->', action, end='')
            next_state, reward, done, info = env.step(action)
            print('reward->', reward)
            if done:
                break
            s = next_state

        return reward
예제 #6
0
파일: apex_test.py 프로젝트: yasstake/mmf
    def setUp(self) -> None:
        self.agent = Agent()
        self.env = Trade()

        self.trainer = Trainer(self.env, self.agent)

        self.trainer.one_episode()
예제 #7
0
    def test_buy_order_sell(self):
        trade = Trade()
        trade.new_episode()

        print(trade.time)
        trade.step(ACTION.BUY)
        print(trade.time)
        print(trade.buy_order_price)
        print(trade.margin)

        print(trade.time)
        trade.step(ACTION.SELL)
        print(trade.time)
        print(trade.margin)
예제 #8
0
    def test_env_buy(self):
        trade = Trade()
        trade.new_episode()

        print(trade.time)
        trade.step(ACTION.BUY)
        print(trade.time)
예제 #9
0
    def test_env_sell_buy(self):
        trade = Trade()
        trade.new_episode()

        print(trade.time)
        trade.step(ACTION.SELL_NOW)
        print(trade.time)
        print(trade.sell_order_price)
        print(trade.margin)

        # close transaction
        print(trade.time)
        trade.step(ACTION.BUY_NOW)
        print(trade.time)
        print(trade.margin)
예제 #10
0
            estimated[i][e.a] = reward

            if e.s.is_able_to_buy():
                estimated[i][ACTION.BUY_NOW] = e.s.get_buy_now_reward()
            else:
                estimated[i][ACTION.BUY_NOW] = 0
                estimated[i][ACTION.BUY] = 0

            if e.s.is_able_to_sell():
                estimated[i][ACTION.SELL_NOW] = e.s.get_sell_now_reward()
            else:
                estimated[i][ACTION.SELL_NOW] = 0
                estimated[i][ACTION.SELL] = 0

        loss = self.model.train_on_batch([states, rewards], estimated)

        return loss

    def update_model(self):
        self.teacher_model.set_weights(self.model.get_weights())


if __name__ == '__main__':
    trainer = Trainer()
    env = Trade()
    agent = Dqn()

    #    trainer.train(env, agent, eposode=100000, min_buffer_size=128)
    trainer.train(env, agent, eposode=500000, min_buffer_size=15000)
예제 #11
0
    def test_env_step(self):
        trade = Trade()
        trade.new_episode()

        trade.step(ACTION.NOP)
        trade.step(ACTION.BUY)
        trade.step(ACTION.BUY_NOW)
        trade.step(ACTION.SELL)
        trade.step(ACTION.SELL_NOW)
예제 #12
0
    def test_new_sec(self):
        trade = Trade()

        trade.new_episode()

        trade.new_sec()
        print(trade.time)

        trade.new_sec()
        print(trade.time)

        trade.new_sec()
        print(trade.time)

        trade.new_sec()
        print(trade.time)
예제 #13
0
    def test_skip_count(self):
        trade = Trade()

        print(trade._skip_count())
예제 #14
0
    def test_new_episode_files(self):
        trade = Trade()

        files = trade._new_episode_files()
        print(files)
예제 #15
0
    def test_actions(self):
        trade = Trade()
        trade.new_episode()

        print(trade.action_space)
예제 #16
0
    def test_tfrecords(self):
        trade = Trade()

        trade._new_episode(0, 2)

        for data in trade.dataset:
            trade.decode_dataset(data)
            print(trade.time)
            break

        for data in trade.dataset:
            trade.decode_dataset(data)
            print(trade.time)
            break

        trade._new_episode(0, 2)

        for data in trade.dataset:
            trade.decode_dataset(data)
            print(trade.time)
            break