This project is a super cool machine learning-based trading strategy using the lumibot library and Alpaca's trading API. The strategy uses sentiment analysis to make smart trading decisions for the SPY symbol. 🚀
.
├── stonks.py # Main script containing the MLTrader strategy
├── README.html # Project README in HTML format
└── utils.py # Utility functions including sentiment estimation
Make sure to install these dependencies before running the project:
pip install lumibot alpaca-trade-api pandas numpy torch transformers
To get started with the MLTrader project, follow these steps to set up your environment and get your API credentials from Alpaca:
- Sign up for an account at Alpaca.
- Log in and navigate to the API section of your dashboard.
- Create a new API key. Choose paper trading to test without real money.
- Store your
API_KEYandAPI_SECRETsecurely.
It's best to use environment variables or a configuration file to store your API credentials securely. You can set your environment variables as follows:
export ALPACA_API_KEY="your_api_key_here"
export ALPACA_API_SECRET="your_api_secret_here"
Alternatively, you can create a config.py file to store these values (not recommended for production).
To run the backtesting process, execute the main script:
python stonks.py
The backtesting will use historical data to simulate trading based on the MLTrader strategy. Ensure that your utils.py file includes the necessary functions for sentiment analysis, which are essential for the strategy's decision-making process.
Below are the screenshots showing the use case of the program for SPY with an 80% annual return: