kkuette / TradzQAI

Trading environnement for RL agents, backtesting and training.
Apache License 2.0
164 stars 47 forks source link

base_env.py check_time_before_closing() idx not defined #23

Open AlconDivino opened 5 years ago

AlconDivino commented 5 years ago

I loaded a Dataset with LTCUSDT data from binance (Format: Timestamp;Open;Low,High;Close;Volume) I now got the following error:

agent not loaded
binanceData_LTCUSDT_1m.csv :   0%|                        | 0/1 [00:00<?, ?it/sException in thread Thread-3:                              | 0/1 [00:00<?, ?it/s]
Traceback (most recent call last):█████▉| 200994/200998 [54:19<00:00, 27.90it/s]
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/alcon/Desktop/TradzQAI/TradzQAI/core/worker/local_worker.py", line 23, in run
    self.step()
  File "/home/alcon/Desktop/TradzQAI/TradzQAI/core/worker/local_worker.py", line 46, in step
    state, terminal, reward = self.env.execute(action)
  File "/home/alcon/Desktop/TradzQAI/TradzQAI/core/environnement/local_env.py", line 178, in execute
    self.check_time_before_closing()
  File "/home/alcon/Desktop/TradzQAI/TradzQAI/core/environnement/base/base_env.py", line 148, in check_time_before_closing
    self.step_left = idx - self.current_step['step'] + 1
UnboundLocalError: local variable 'idx' referenced before assignment

binanceData_LTCUSDT_1m.csv : 100%|██████████████| 1/1 [54:19<00:00, 3259.48s/it]
^[[A Processing : 100%|████████████████▉| 200996/200998 [54:19<00:00, 61.67it/s]

Looking at the function i see that the runnervar idx is really not defined in the last line. I then defined the var at the begining as idx=0

    def check_time_before_closing(self):
        if self.current_step['step'] == self.len_data - 1:
            return
        for idx in range(self.current_step['step'] + 1 , self.len_data - 1):
            if self._date[idx - 1][7] != self._date[idx][7]:
                break
        self.step_left = idx - self.current_step['step'] + 1

The process ran smothly with my own data and the dax data in the repo but when running python3 run.py -m eval and checking the save logs everything is 0 like this:

2019:04:09 17:47:40 000000 Starting episode : 1
2019:04:09 17:47:56 000001 ######################################################
2019:04:09 17:47:56 000002 Total reward : 0
2019:04:09 17:47:56 000003 Average reward : 0.000
2019:04:09 17:47:56 000004 Avg reward 500 : 0.0
2019:04:09 17:47:56 000005 Avg reward 100 : 0.0
2019:04:09 17:47:56 000006 Avg reward 50 : 0.0
2019:04:09 17:47:56 000007 Avg reward 10 : 0.0
2019:04:09 17:47:56 000008 Total profit : 0
2019:04:09 17:47:56 000009 Total trade : 0
2019:04:09 17:47:56 000010 Sharp ratio : 0.000
2019:04:09 17:47:56 000011 Mean return : 0.000
2019:04:09 17:47:56 000012 Max Drawdown : 0.000
2019:04:09 17:47:56 000013 Max return : 0.000
2019:04:09 17:47:56 000014 Percent return : 0.000
2019:04:09 17:47:56 000015 Trade W/L : 0.000
2019:04:09 17:47:56 000016 Step : 18353
2019:04:09 17:47:56 000017 ######################################################

Any idea what i can do?

kkuette commented 5 years ago

Your agent is not learning, you can do some change on the network, do some fine tuning, also change preprocessing.

Also make sur that the memory size you defined in config/agent.json is large enought.

AlconDivino commented 5 years ago

Okay the change i made was okay? Also can you add a Usage file maybe explaining the basic startup and error handling steps?