I created a scanner.py file with a method for scanning QuantConnect historical data, but my project already has a main.py file. QuantConnect's backtest button defaults to running main.py. How can I configure the platform to run backtesting on scanner.py instead of main.py?"
Mia Alissi
Hi Dharmesh,
QuantConnect always runs main.py as the entry point for backtests and does not allow you to select another file (like scanner.py) to run directly. However, you can easily use your scanning logic defined in scanner.py by following one of these approaches:
1. Copy into main.py:
Copy the relevant class, function, or logic directly from scanner.py into main.py.
2. Import in main.py:
import scanner.scanner.DataScanner(self).scan_data()within your QCAlgorithm subclass.Note: Your main.py must contain the subclass of QCAlgorithm and its initialize method—QuantConnect requires this.
Example (option 2: importing from scanner.py):
If scanner.py contains:
Then, in main.py:
You can also schedule or trigger the scan from within main.py as needed.
Summary: QuantConnect will always run main.py first, but you can re-use and modularize your code by importing your scanner functions or classes into main.py.
Let me know if you want to see more detailed examples or need help adapting your code!
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Dharmesh Khalasi
I have so much logic so perhaps I want to short circuit all other initialization in main.py and only run scanner method ?
Dharmesh Khalasi
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!