A Python implementation of the pairs trading strategy inspired by Mark Whistler, featuring backtesting capabilities and automated daily triggers for identifying profitable trading opportunities.
- ✅ Supports all NSE stocks
- ✅ Automated stock data fetching (no manual uploads required)
- ✅ Backtesting system to evaluate strategy performance
- ✅ Daily tracking of trade signals
- ✅ Database management to prevent redundant downloads
- ✅ Customizable parameters for backtesting
- Ensure you have Python installed. Install required dependencies using:
pip install -r requirements.txt- Set up MongoDB Connection
Update the CONNECTION_STRING variable in database.py with your MongoDB connection string. For example:
CONNECTION_STRING = "mongodb://localhost:27017/" # Replace with your connection string- Define stock symbols in
stock_symbol.txt(one symbol per line, in NSE format). - Run the script to fetch or update stock data:
python database.py
- If stock data does not exist, it will be downloaded automatically.
- If stock data already exists, it will be updated to the latest date.
- Modify
backtesting.pyto adjust strategy parameters (e.g., entry/exit conditions). - Run the backtesting script:
python backtesting.py
- This simulates trades based on historical data and provides performance metrics.
Below is an example of the expected console output:
100%|████████████████████████████████████████| 803/803 [02:50<00:00, 4.72it/s]
Total Trades: 27
Number stock Sells: 27
Number stock Target Sells: 25
Number stock Stoploss Sells: 2After running backtesting.py, a chart will be generated displaying buy and sell signals on the stock price movements. This visualization helps traders analyze entry and exit points effectively.
- 🔹 Automated trade execution for live trading
- 🔹 Enhanced visualization (performance graphs, trade signals)
- 🔹 Support for additional stock exchanges
- 🔹 Deploy as a Web App for better accessibility and user experience
📩 Contact: Have questions? Reach out via Email!
