Hi QuantConnect Team & Community,
I'm encountering a persistent issue when trying to use QuantBook within the local research environment launched by lean research . on my Windows machine. My goal is to run several research notebooks locally (using lean-cli and Docker) that utilize QuantBook to read data/ObjectStore and save results to local files.
Problem:
When I run lean research . and attempt to execute any code that initializes QuantBook (i.e., qb = QuantBook()), the cell execution fails with a System.NullReferenceException. This happens both when trying to run notebooks programmatically via a master notebook (using nbconvert.ExecutePreprocessor) and also when running the notebooks manually cell-by-cell within the Jupyter Lab interface launched by lean research .. Even a minimal test case in a brand new notebook containing only qb = QuantBook() fails with the same error.
Error Details:
The primary error during qb = QuantBook() initialization is:
Code snippet
System.NullReferenceException: Object reference not set to an instance of an object.
at QuantConnect.Securities.SecurityDefinitionSymbolResolver..ctor(IDataProvider dataProvider, String securitiesDefinitionKey)
at QuantConnect.Securities.SecurityDefinitionSymbolResolver.GetInstance(IDataProvider dataProvider, String securitiesDefinitionKey)
at QuantConnect.Algorithm.QCAlgorithm..ctor()
at QuantConnect.Research.QuantBook..ctor()
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeConstructorWithoutAlloc(Object obj, Boolean wrapInTargetInvocationException)
Other potentially relevant log messages observed during startup/failure:
- ERROR:: Initializer.Start(): System.ArgumentException: Unable to locate any exports matching the requested typeName: CompositeLogHandler. Type: QuantConnect.Logging.ILogHandler (Parameter 'typeName')
- TRACE:: Extensions.IsDirectoryEmpty(): directory '../../../Data/symbol-properties' not found or empty
Environment:
- Operating System: Windows [Windows 11 Pro 24H2]
- lean-cli Version: [lean 1.0.217]
- Docker Desktop Version: [Docker version 27.5.1, build 9f9e405]
Troubleshooting Steps Already Taken:
- Resolved initial jupyter command not found errors by fixing the system PATH.
- Ensured target notebooks are correctly formatted .ipynb (JSON) files, not plain Python scripts.
- Confirmed Docker Desktop is installed and running correctly (tested with docker ps).
- Encountered and resolved the Error: This is an old Lean CLI root folder... by:
- Creating a completely new workspace folder (MyNewLean).
- Deleting the global configuration folders.
- Uninstalling and reinstalling lean-cli (pip install --upgrade lean).
- Running lean login successfully.
- Running lean init successfully within the new workspace folder.
- Ensured the latest research Docker image was present (docker pull quantconnect/research:latest confirmed image is up-to-date).
- Attempted downloading sample data (lean data download --dataset-name equity-usa-minute --ticker SPY ...).
- Ran the minimal test case (from QuantConnect.Research import QuantBook; qb = QuantBook()) in a new notebook within the environment launched by lean research ., which still failed with the NullReferenceException.
Despite these steps, the fundamental QuantBook() initialization fails locally. Running the same notebooks in the QuantConnect Cloud Research environment works fine.
Could you please provide guidance on why QuantBook might be failing to initialize correctly in the local lean research environment on my machine?
Thank you for your help!
Mia Alissi
Here is a comprehensive checklist and diagnostic guide for resolving the System.NullReferenceException encountered when initializing QuantBook in your local Lean research environment:
CHECKLIST & RATIONALE
Verify local
./data
directory:./data/symbol-properties
and./data/equity/usa
../data/symbol-properties
can cause a NullReferenceException because QuantConnect relies on symbol-properties data at startup.Use
lean data download
:usa-symbol-properties.csv
).Run a directory structure check:
Inspect Docker volume mounts:
data
directory is correctly mounted into the container.Remove any custom
log.config
or logging-related configs:CompositeLogHandler
, which may halt initialization.Minimal QuantBook test:
Why missing data causes NullReferenceException
QuantConnect loads symbol definitions at startup by reading files under
data/symbol-properties
. If these files or folders are missing, any reference to necessary symbol data will be null, which triggers theSystem.NullReferenceException
.DIAGNOSTIC CODE SNIPPET
Place this in a Jupyter notebook (launched with
lean research .
) to verify your data directories:Next Steps:
Go through the checklist above. If you find that your symbol-properties directory or files are missing, redownload the data using
lean data download
as described. Double-check Docker mounting and workspace structure. Only after your environment/directory is confirmed should you try runningqb = QuantBook()
again.Let me know what your diagnostic output shows and we can take it from there!
Sources: Debugging - QuantConnect.com
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.
HAL
Thank you for the diagnostic checklist regarding the NullReferenceException when initializing QuantBook() locally with lean research. I have followed the steps, and here are the results:
1. Verify Local ./data Directory (Windows File Explorer):
• Yes, the C:\Users\My User\Desktop\MyNewLean\data folder exists locally.
• Yes, it contains a symbol-properties subfolder. Inside this folder, I found files named security-database.xls and symbol-properties-database.xls. (Note: These were .xls, not .csv as perhaps expected).
• Yes, it contains an equity subfolder, which contains a usa subfolder.
2. Run Recommended lean data download:
• I ran lean data download --dataset-name equity-usa --resolution daily --ticker SPY.
• The command became interactive, prompting for provider, security type, etc. I selected Interactive Brokers (1), Index (7), Trade (1), Daily (4), and provided dates.
• It then pulled the quantconnect/lean:latest image (not the research image) and discussed IBKR Mobile setup. It did not explicitly confirm downloading default QC symbol-properties. (Output can be provided if needed).
3. Run Diagnostic Code Snippet (Inside lean research . Jupyter Lab):
• This step was critical. I ran the updated diagnostic script within a new notebook using the Foundation-Py-Default kernel inside the environment started by lean research . --port 8889.
• Output:
• Current Working Directory inside container: /Lean/Launcher/bin/Debug/Notebooks/research_notebooks
• Checking standard project mount point: /Lean/Project/
• Checking data directory at: /Lean/Project/data
•
• Standard project mount point '/Lean/Project/' not found.
•
• FAILURE: The 'data' directory was NOT FOUND at the expected path '/Lean/Project/data' inside the container.
• This confirms a Docker volume mount or internal path issue with 'lean research'.
4. Remove Custom Logging Configs:
• Confirmed no custom logging files (like log.config) were created or present.
5. Retry Minimal QuantBook Test:
• After running the diagnostic script (which confirmed the data path wasn't found inside the container), I ran the minimal test case (qb = QuantBook()) again in a new notebook within the same lean research . session.
• It still failed with the same error.
• Output:
• Attempting QuantBook initialization...
• 20250505 18:17:44.600 TRACE:: QuantBook started; Is Python: True
• 20250505 18:17:44.707 TRACE:: Config.GetValue(): downloader-data-update-period - Using default value: 7
• 20250505 18:17:44.715 TRACE:: Extensions.IsDirectoryEmpty(): directory '../../../Data/symbol-properties' not found or empty
• ERROR during QuantBook initialization:
• Minimal test finished.
•
• Traceback (most recent call last):
• File "/tmp/ipykernel_143/3144568556.py", line 4, in <module>
• qb = QuantBook()
• ^^^^^^^^^^^
• System.NullReferenceException: Object reference not set to an instance of an object.
• at QuantConnect.Securities.SecurityDefinitionSymbolResolver..ctor(IDataProvider dataProvider, String securitiesDefinitionKey)
• at QuantConnect.Securities.SecurityDefinitionSymbolResolver.GetInstance(IDataProvider dataProvider, String securitiesDefinitionKey)
• at QuantConnect.Algorithm.QCAlgorithm..ctor()
• at QuantConnect.Research.QuantBook..ctor()
• at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
• at System.Reflection.MethodBaseInvoker.InvokeConstructorWithoutAlloc(Object obj, Boolean wrapInTargetInvocationException)
Conclusion:
The diagnostic script confirms that the local project directory (and specifically the crucial data subfolder containing symbol-properties) is not being correctly mounted or found at the expected /Lean/Project/ path inside the Docker container when launched via lean research .. Consequently, the /Lean/Project/data directory is inaccessible from within the container, causing the NullReferenceException during QuantBook() initialization because it cannot access essential definition files.
This appears to be an issue with Docker volume mounting or internal path resolution specific to the lean research command on my system.
Environment:
• Operating System: Windows [Windows 11 Pro 24H2]
• lean-cli Version: [lean 1.0.217]
• Docker Desktop Version: [Docker version 27.5.1, build 9f9e405]
Could you please provide further guidance on resolving this volume mounting/path issue within the lean research environment?
HAL
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!