This project is a basic algorithmic trading simulator that allows you to backtest different trading strategies using historical market data. It is designed with a focus on object-oriented programming principles and a modular structure to ensure scalability and maintainability.
It currently uses yfinance
The project consists of the following modules:
data_handler.py: Fetches, stores, and provides historical market data.strategies/basic/: Contains different trading strategies.moving_average.py: Implements a moving average crossover strategy.rsi.py: Implements an RSI based strategy.bollinger_bands.py: Implements a Bollinger bands strategy.stochastic_oscillator.py: Implements a stochastic oscillator strategy.macd.py: Implements a MACD based strategy.ichimoku_cloud.py: Implements an Ichimoku cloud based strategy.adx.py: Implements an ADX based strategy.
strategies/hybrid/: Contains classes that makes it easy to combine many different strategiesstrategy.py: Defines the abstract base class for all trading strategies.broker.py: Simulates the execution of trades and manages the portfolio.backtester.py: Simulates the backtesting process.main.py: The entry point of the application.
- Install Dependencies: Make sure you have all the required packages installed, like yfinance, numpy, etc (run
pip3 install -r requirements.txt). Also make sure you have a venv. - Run
main.py: Execute themain.pyscript using pythonpython3 main.py(after activating your virtual environment). - Modify Parameters: You can change the parameters of the strategies in
main.py, by creating new instances of the strategy classes. You can also configure the data that will be backtested. - Analyze Results: After running the simulation, the output will display the backtest results, including profit, number of trades, and a transaction history.
- Moving Average Crossover: Uses short-term and long-term moving averages to generate buy/sell signals.
- RSI: Uses the Relative Strength Index to identify overbought and oversold conditions.
- Bollinger Bands: Uses Bollinger Bands to identify when a price might be overbought or oversold based on volatility.
- Stochastic Oscillator: Uses the stochastic oscillator to generate signals, based on momentum.
- MACD: Uses the Moving Average Convergence Divergence indicator to generate trading signals, based on the relationship between two moving averages.
- Ichimoku Cloud: Uses the Ichimoku Cloud indicator to generate trading signals, based on the relationship between the price and the cloud.
- ADX: Uses the Average Directional Index to generate trading signals, based on the strength of the trend.
- Implement more advanced trading strategies.
- Add more data sources.
- Include more risk management features.
- Add visualizations of backtesting results.