stefan-jansen / machine-learning-for-trading

Code for Machine Learning for Algorithmic Trading, 2nd edition.
https://ml4trading.io
13.22k stars 4.18k forks source link

Understanding trading env #232

Closed davide97l closed 2 years ago

davide97l commented 2 years ago

Hi, I couldn't understand why here: https://github.com/stefan-jansen/machine-learning-for-trading/blob/main/22_deep_reinforcement_learning/trading_env.py#L171, n_trades is computed as n_trades = end_position - start_position. I would really appreciate it if you can clarify. Thank you in advance!

stefan-jansen commented 2 years ago

Both start_position and end_position are in [-1, 0, 1]. The idea is that if you go from long to short or vice versa, there are 2 trades, if no change then no trades, else 1 trade. You may be concerned about the sign but the cost is based on abs(n_trades). Does this make sense?

stefan-jansen commented 2 years ago

Closing for now, please let me know if you have further questions.