I'm working on a local backtesting project using LEAN CLI (v2.5.0.0) and Python, and I'm running into a persistent issue loading custom data from a CSV file. I'm trying to integrate weekly Global M2 data (global_m2-weekly.csv) into my algorithm, but it's not being processed.
Problem: My custom GlobalM2Data is not loading. The backtest runs, but the logs show no DEBUG_SOURCE: messages (from GetSource) or GLOBAL M2: messages (from OnData), indicating LEAN isn't even attempting to load the custom CSV file. Consequently, my algorithm's logic, which relies on this data, doesn't execute any trades.
My Setup: OS: Windows. Environment: Anaconda (dedicated qclean_env active), Docker Desktop running, .NET SDK 9.0.303 installed. LEAN CLI: Installed and successfully logged in. LEAN Root Folder: [My LEAN Root Folder Path, e.g., C:\Users\MyUser\QuantConnect]. Strategy Folder: [My LEAN Root Folder Path]\BitcoinHalvingStrategy (contains Python/ and data/custom/ subfolder). Custom Data File: global_m2-weekly.csv located in [My LEAN Root Folder Path]\BitcoinHalvingStrategy\data\custom\ (file confirmed to exist here).
global_m2-weekly.csv Format (First few lines): observation_date,WM2NS 2015-07-06,12091.4 2015-07-13,12045.8 2015-07-20,12010.7
What I'm Trying to Achieve (Simplified Strategy): Subscribe to standard Coinbase BTCUSD Hourly data and use my custom GlobalM2Data (from global_m2-weekly.csv).
Steps Taken to Troubleshoot (and current state):
Basic LEAN Setup & Standard Data Check: Successfully installed all LEAN CLI prerequisites. Successfully ran backtests using standard downloaded hourly BTC/ETH data (confirming basic LEAN functionality and standard data loading).
PythonData Class Definition: Defined GlobalM2Data (inherits PythonData) in main.py (BitcoinHalvingStrategy/Python/main.py). GetSource returns SubscriptionDataSource("data/custom/global_m2-weekly.csv", SubscriptionTransportMedium.LOCAL_FILE). It includes print() statements for DEBUG_SOURCE: and os.path.exists checks. Reader parses observation_date,WM2NS format.
Algorithm Subscription: self.AddData(GlobalM2Data, "GLOBALM2", Resolution.Daily) is used in initialize(). GlobalM2Trend indicator is created and RegisterIndicator is used.
Backtest Command: Run from [My LEAN Root Folder Path]\BitcoinHalvingStrategy: lean backtest "Python/main.py".
Actual Behavior: The backtest runs (processes ~100k data points for BTCUSD hourly), but the custom M2 data is not processed. No DEBUG_SOURCE: or ERROR_PARSING: messages appear for GlobalM2Data in the console output. The FINAL PORTFOLIO VALUE remains at initial cash ($100,000 USD).
Question for the Community: Given that GetSource isn't even being called, what common pitfalls or specific lean.json configurations for custom PythonData from a sub-project might I be missing? Or, are there any other common pitfalls for loading custom PythonData from a sub-project that I might be missing?
Mia Alissi
Here’s a focused diagnostic checklist and code example to help you debug why your custom GlobalM2Data class is not being loaded by QuantConnect LEAN CLI. These steps show exactly where things typically go wrong and how to catch issues early:
1. Class Location & Import
Issue: If GlobalM2Data isn’t defined in the same file—or isn’t properly imported—Python can’t find it.
main.py), or that you are importing it:2. Path Formatting in get_source
Issue: LEAN requires forward slashes (
/) and the path should be relative to project root.3. Is get_source Triggering?
Issue: If get_source is never called, AddData is wrong, or LEAN can’t find the class.
4. AddData Usage & Typo Checks
Issue: Wrong class reference (e.g., typo) or placed outside initialize.
5. File Placement & File Check
Issue: File is in the wrong folder or not visible to Docker/LEAN.
[LEAN Root]/YourProject/data/custom/global_m2-weekly.csv6. CSV File Format/Encoding
Check that:
7. lean.json Conflicts
Check that
data-folderis not set to an unexpected path. It should be./for local data if using relative paths.8. Use Both print and self.Debug
Recommended Diagnostic Code
lean.json (if present, in project root):
Summary of Common Pitfalls:
\not/.Double-check each section above! If you follow this pattern and still see no
print/Debugmessages from your custom data class, the root cause is almost always an import/scope, AddData, or path issue. If you do see those messages, but nothing inon_data, then it’s a parsing/timing/data issue.Let me know which debug statements you see (or not) after trying this!
Sources: Custom Data - QuantConnect.com, Key Concepts - QuantConnect.com, Key Concepts - QuantConnect.com, CSV Format Example - QuantConnect.com, docs writing algorithms securities requesting data
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.
AldenStout
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!