Blackbox Trade
This project demonstrates the concept of blackbox trading, which involves using machine learning models for automated trading strategies.
The repository for this project is currently unavailable as the project is still in development. Video link (opens in a new tab)
Environment
The environment for AI learning is implemented using a Python class. This class aims to simulate an environment similar to futures commodity trading. For each incoming price feed, three actions are available:
- Buy: Increases the inventory by 1 and closes all short positions, if any.
- Sell: Decreases the inventory by 1 and closes all long positions, if any.
- Wait: No action taken.
Parameters
Each position uses margin trading, and leverage is adjustable in the configuration.
The environment settings are as follows:
Parameter | Value |
---|---|
Initial Balance | 1000 USD |
Leverage | 3x |
Long only | False |
Max drawdown | 50% |
Funding Fee (per 8h) | 0.01% |
Commission (per trade) | 0.03% |
Slippage | 0% |
Price Data
Two types of data are used to train the model:
- Real market data (OHLC)
- Random walk data
Random data is necessary to prevent overfitting to market data. Random walk data is generated using a script for each training episode. Here's a sample:
Observation Variables and Outputs
The model input consists of four indicators:
- Short-term delta EMA
- Long-term delta EMA
- RSI
- Inventory
The output activation function is sigmoid, resulting in a value between 0 and 1:
- If the value is below 0.2, it opens short positions.
- If the value is above 0.8, it opens long positions.
- Otherwise, it waits.
Episode
For each episode, the environment receives new OHLC data, which is used to update the environment state and observation variables. The observations are then passed through the neural network to produce an output value.
Training
The model is trained continuously to achieve the highest possible fitness level.
After multiple runs, the following results were obtained:
It appears that after 50 generations, the model begins to understand the environment but is unable to produce high-quality trades. The results remain divergent due to factors that require further investigation.
Testing
Once training is complete, the best-performing model is selected for additional testing across multiple scenarios. It was found that after 1000 steps, all episodes concluded.
Conclusion
This project successfully produced a model that understands the core concepts of trading. However, the quality of the model is not yet suitable for production use. Further research into fitness settings and observation variables is necessary to improve performance.