Well, first of let me apologize in advance if this question has been asked and I was unable to find the answer by myself.
I came across some (not so) old post, claiming that it was possible to use Lean standalone, without even evoking lean init and logging into QuantConnect via CLI.
However, I am not sure if this is still the case.
Can you please tell me if I can indeed use Lean without QuantConnect and, if so, could you point me to a minimal example, that uses CSV OHLCV data?
Mia Alissi
Yes, you can use the LEAN engine standalone without logging into QuantConnect via the CLI. Here's a minimal guide to using LEAN with CSV OHLCV data:
Steps to Use LEAN Standalone with CSV Data
Install LEAN Locally: Download and set up the LEAN engine from its GitHub repository on your local machine.
Prepare Your CSV Data: Ensure your CSV file is formatted correctly with columns like Date, Open, High, Low, Close, and Volume, and place it in a directory accessible to your algorithm.
Create a Custom Data Class: Inherit from the
PythonData
class and override theget_source
andreader
methods to specify the path to your CSV file and parse the data.Define Your Algorithm: Create a subclass of
QCAlgorithm
, and in theinitialize
method, useself.add_data
to add your custom data type.Implement the
on_data
Method: Write logic in theon_data
method to handle the data as it is streamed into your algorithm.Run the Algorithm: Use the LEAN engine to execute your algorithm locally, ensuring it points to the directory containing your CSV data.
Review Results: Analyze the output and logs to verify that your algorithm processes the CSV data as expected.
Example Code
Here's an example of how you might set up a custom data class and algorithm:
This example demonstrates how to set up a custom data class to read from a CSV file and integrate it into a QuantConnect algorithm. Adjust the file path and data parsing logic to fit your specific CSV format.
Sources: Custom Data - QuantConnect.com, Algorithm Engine - QuantConnect.com, CSV Format Example - QuantConnect.com, CSV Format Example - QuantConnect.com, Custom Data Bitcoin Algorithm
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.
Jose Filipe
Thank you very much for your detailed reply! However, I am still facing some issues, specially on how to use Lean to backtest. I am going to outline what I did:
Error: The working organization for this Lean CLI folder could not be determined.
Make sure you run `lean init` on an empty folder for each organization you are a member of
So, what am I doing wrong? Can you show me what is the minimal Lean CLI workflow to test the script you gave me, with a minimal config.json?
Louis Szeto
Hi Jose
You just need to open a new empty folder to install the CLI.
Otherwise, follow the below steps to install Lean locally:
You can actually find these in the readme.md of the Lean repo.
Best
Louis
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.
Jose Filipe
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!