kkuette / TradzQAI

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

We cant afford any contract. Please check wallet settings. #4

Closed lamhk closed 5 years ago

lamhk commented 5 years ago

Hi, i encountered another issue using the new code. I tried to increase the capital from 200 to 20000 (for example) and it still happened the same way. Any idea? Thanks.

/TradzQAI-master$ python3.6 run.py -m train DAT_ASCII_GRXEUR_M1_201711.csv : 0%| | 0/1 [00:00<?, ?it/sException in thread Thread-4: | 0/1 [00:00<?, ?it/s] Traceback (most recent call last): | 0/18354 [00:00<?, ?it/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/lamhk/TradzQAI-master/core/worker/local_worker.py", line 45, in run self.step() File "/home/lamhk/TradzQAI-master/core/worker/local_worker.py", line 71, in step state, terminal, reward = self.env.execute(action) File "/home/lamhk/TradzQAI-master/core/environnement/local_env.py", line 184, in execute self.wallet.manage_exposure(self.contract_settings) File "/home/lamhk/TradzQAI-master/core/environnement/base/wallet.py", line 197, in manage_exposure raise ValueError('current_max_pos : {:.3f} We cant afford any contract. Please check wallet settings.'.format(self.risk_managment['current_max_pos'])) ValueError: current_max_pos : 0.000 We cant afford any contract. Please check wallet settings.

DAT_ASCII_GRXEUR_M1_201711.csv : 100%|████████████| 1/1 [00:00<00:00, 5.25it/s]

Regards, lamhk

lamhk commented 5 years ago

I found the "current_max_pos" is zero because the "contract_price" is very large like 13325. Any idea?

kkuette commented 5 years ago

The current max pos is calculated with this function. It use the current exposure (default is 10% of capital), the contract price, the contract size and the pip value (i should delete it by the way). If you are using the classic contract type, you should set values large enought to be enable to afford any contract. With 20000 capital and 13325 contract price, the exposure have to be at least at 67%.

lamhk commented 5 years ago

I tried to increase the capital to larger value using the structure below, but when I printed the self.settings['capital'] value out (explicitly), it always stay as "200" no matter how I change the structure below, any idea?

    self.settings = dict(
        capital = 200000000,
        fee = 0.3,
        used_margin = 0,
        GL_pip = 0,
        GL_profit = 0
    )

Where should I change the capital?

kkuette commented 5 years ago

In which file are you making this changes ? TradzQAI/config/ or TradzQAI/save/<agent>_<id>/config/ ?

lamhk commented 5 years ago

I change the capital inside wallet.py, l tried it in TradzQAI/config and set capital to 2000000 and seems running now. Thanks.

kkuette commented 5 years ago

The most of hard coded values are only used as default values for config directory building.

lamhk commented 5 years ago

Hi, I train and eval with the following result, is Average trade means number of trades (buy/sell pairs)? I want to check how many number of buy/sell was done.

Also, is there a variable that could be used for transaction cost in the training and eval mode so that the agent could adjust the freq of buy/sell? Thx.

2018:10:02 17:44:43 000000 Average profit : 2630.15 2018:10:02 17:44:43 000001 Average max return : 0.275 2018:10:02 17:44:43 000002 Average max drawdown : -0.138 2018:10:02 17:44:43 000003 Average trade : 666.0 2018:10:02 17:44:43 000004 Average trade W/L : 0.303 2018:10:02 17:44:43 000005 Average percent return : 0.132 2018:10:02 17:44:43 000006 Day W/L : 1.0 2018:10:02 17:44:43 000007 Total day : 1

lamhk commented 5 years ago

Also, I found it seems only one episode was done in the training stage, is this intended?

2018:10:02 17:35:14 000000 Starting episode : 1 2018:10:02 17:37:07 000000 Starting episode : 1 2018:10:02 17:38:38 000001 ###################################################### 2018:10:02 17:38:38 000002 Total reward : -29586.958 2018:10:02 17:38:38 000003 Average daily reward : -1344.862 2018:10:02 17:38:38 000004 Total profit : -29545.8 2018:10:02 17:38:38 000005 Total trade : 1810 2018:10:02 17:38:38 000006 Sharp ratio : -22.235 2018:10:02 17:38:38 000007 Mean return : -1.610 2018:10:02 17:38:38 000008 Max Drawdown : -1.494 2018:10:02 17:38:38 000009 Max return : 0.001 2018:10:02 17:38:38 000010 Percent return : -1.477 2018:10:02 17:38:38 000011 Trade W/L : 0.273 2018:10:02 17:38:38 000012 Step : 18353 2018:10:02 17:38:38 000013 ###################################################### 2018:10:02 17:40:35 000000 Starting episode : 1 2018:10:02 17:42:06 000001 ###################################################### 2018:10:02 17:42:06 000002 Total reward : -31749.517 2018:10:02 17:42:06 000003 Average daily reward : -1443.160 2018:10:02 17:42:06 000004 Total profit : -31750.45 2018:10:02 17:42:06 000005 Total trade : 1475 2018:10:02 17:42:06 000006 Sharp ratio : -23.719 2018:10:02 17:42:06 000007 Mean return : -1.730 2018:10:02 17:42:06 000008 Max Drawdown : -1.590 2018:10:02 17:42:06 000009 Max return : 0.000 2018:10:02 17:42:06 000010 Percent return : -1.588 2018:10:02 17:42:06 000011 Trade W/L : 0.188 2018:10:02 17:42:06 000012 Step : 18353 2018:10:02 17:42:06 000013 ######################################################

kkuette commented 5 years ago

The average trade is all trade done (buy/sell/draw). I guess you want to know how many of which is done, right ? No, you have to check if you change the episodes line in TradzQAI/config/environemment.json. The transaction cost is done with the fee value, also you can change the spread value.