ml-autotrade
This is a set of Python scripts that provide a framework for training neural networks to predict stock prices, developing trading strategies that use these predictions, and applying these strategies on the real stock market through Alpaca. It is based on PyTorch.
Usage/Explanation
All dependencies can by retrieved by calling pip install -r requirements.txt
or pip3 install -r requirements.txt
.
All functionality comes from executing four scripts:
main_training.py
: Trains the neural network.main_eval.py
: Evaluates the neural network by plotting the known change in price against the predicted change.main_backtest.py
: Evaluates strategies using the neural network by backtesting against a given stock universe.main_trading.py
: Executes one strategy using the neural network on the real stock market.
There are also five configurable files, where a working example is already configured:
config.json
: Global constants, including augmentation (using technical analysis indicators), training, and model parameters along with the Alpaca API key.strategies.py
: Abstracted Python functions that outlines strategies based on neural network predictions, portfolio holdings, and portfolio cash-on-hand. Raw "latest" market data can also be accessed.stock_lists/training_tickers.txt
: Tickers whose histories will be trained on by the neural network.stock_lists/trading_tickers.txt
: Tickers that all of the example strategies will trade.stock_lists/stock_universe.txt
: Tickers whose historiesstrategies.py
can access. All traded tickers must be in this list, and all tickers in this list must have a history that extend past the backtesting start date.
In addition, there are four other functional files:
database.py
: Functions that retrieve, access, and modify price history databases.technicals.py
: Functions that calculate and attach technical analysis indicators. These can also be called instrategies.py
to make ordinary trading decisions.moredata.py
: Functions that retrieve and attach additional data.neural.py
: Definition of the neural network and the PyTorchDataset
.