releat215 / releat

REinforcement LEarning for Algorithmic Trading is a python framework for medium frequency trading algorithms for MetaTrader 5
https://releat215.github.io/releat/
MIT License
22 stars 9 forks source link

Fixes and enhancements, signal generation issues #28

Closed migueltg closed 8 months ago

migueltg commented 9 months ago

Hi @releat215 , first of all, congratulations for the great project that you've developed. I think it's very promising, and i wish i can help as much as I can with the development.

I've been working on it for a few weeks to get it running, and I've managed to reach the model training stage. However, I'm encountering some "Gym" errors in the signal generation part, and I haven't been able to proceed to the final live trading stage.

These are the parts that are working for me in this PR:

releat start
releat launch-mt5-api metaquotes general
releat build-train-data t00001
releat train t00001

And these are the ones that are not working:

releat generate-signal t00001
releat launch-trader (Not tried because there is no signal)

The error in generate-signal process is:

ValueError: The two structures don't have the same nested structure.

First structure: type=dict str={'0': array([[ 0.41382062,  0.6613428 , -0.5980679 , -0.44695556,  1.224896  ],
       [ 0.1496507 , -0.06490325,  0.9810117 ,  0.36554584,  1.2243716 ],
       [-0.0201654 , -0.41932714,  1.1325057 , -0.61578804,  1.2256708 ],
       [-0.02438621,  0.5618342 , -0.17309374, -0.222305  ,  1.2228763 ],
       [-0.01785176,  0.6199935 ,  0.3672471 , -0.19477406,  1.2079923 ]],
      dtype=float32), '1': array([[ 0.29294565,  0.00904829, -0.26750928, -0.02923426],
       [ 0.33121577,  0.03064447, -0.3552831 , -0.56974304],
       [ 0.3695962 , -0.56929165, -0.04010372, -0.3275149 ]],
      dtype=float32), 'date_arr': array([0.      , 0.389831, 0.898305], dtype=float32), 'pos_val': [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], 
[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 
0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]], 'mask': array([1., 1., 0., 1., 0., 1., 0., 1., 0.], dtype=float32)}

Second structure: type=OrderedDict str=OrderedDict([('0', array([[-0.8313553 , -0.6148043 , -1.445629  , -1.095264  ,  0.98522633],
       [ 1.5269808 ,  1.227685  ,  0.13030356,  0.3399699 ,  0.28008455],
       [-1.9573393 , -1.0584642 , -1.3062755 , -1.8902744 , -1.0142106 ],
       [ 0.9865173 , -1.9711063 ,  1.1182383 , -1.199996  ,  0.9127852 ],
       [-1.7190394 , -0.7357767 , -1.1618776 , -2.098176  ,  1.758041  ]],
      dtype=float32)), ('1', array([[ 1.5319328 ,  0.6643868 ,  1.0975807 , -2.0182831 ],
       [-1.664262  ,  1.6312706 , -1.1108449 , -2.0048463 ],
       [-0.14825644, -0.6725378 , -0.38296336, -0.91874874]],
      dtype=float32)), ('date_arr', array([-0.19489728,  2.0140011 , -0.09583851], dtype=float32)), ('mask', array([ 1.7731682 ,  1.0181539
, -1.0604019 , -0.40392604, -0.8638771 ,
       -0.09041827,  2.032676  , -0.77559274,  0.05405173], dtype=float32)), ('pos_val', array([[0.5785334 , 0.77050054]], 
dtype=float32))])

More specifically: Substructure "type=list str=[[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 
0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], 
[0.0, 0.0]]" is a sequence, while substructure "type=ndarray str=[[0.5785334  0.77050054]]" is not
Entire first structure:
{'0': ., '1': ., 'date_arr': ., 'pos_val': [[., .], [., .], [., .], [., .], [., .], [., .], [., .], [., .], [., .], [., .], [., .], [., .],
[., .], [., .], [., .], [., .], [., .], [., .], [., .], [., .]], 'mask': .}
Entire second structure:
OrderedDict([('0', .), ('1', .), ('date_arr', .), ('mask', .), ('pos_val', .)])
Captura de Pantalla 2023-12-20 a las 23 26 54

I'm sharing here a small contribution with various bug fixes and some improvements I've made in the process to get it working. Some are syntax errors, while others required changes to move forward.

If you could help me get the signal generator working, i would be very grateful as I've been trying for a few days but haven't had success yet.

Thank you very much, and congratulations again.

releat215 commented 8 months ago

@migueltg Thanks for having a look at this library and taking the time to merge these fixes, I'll have a look at this issue and push a fix shortly

migueltg commented 8 months ago

@releat215 Thank you very much! Thanks for taking the time to merge these fixes. I look forward to your commit as I'm stuck due to this issue, and I find this project very interesting.