I want to load a csv file contains some insight which is important for AlphaModel. I do not want to put those File in ObjectStore. because csv file change with time and it is difficult to upload in objectStore.
I'm using Local CLI
QUANTCONNECT COMMUNITY
I want to load a csv file contains some insight which is important for AlphaModel. I do not want to put those File in ObjectStore. because csv file change with time and it is difficult to upload in objectStore.
I'm using Local CLI
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.
Mia Alissi
Sure Krish, you can load a local CSV file in your algorithm when running the LEAN engine locally. Here are the steps you can follow:
Copy the CSV file that you want to use to the data directory in your organization workspace.
Open the source file containing your custom data class in an editor.
Update your
GetSource
method to load data from the local file in your data directory. Make sure you only use forward slashes. Backward slashes as path separators don't work.Here is an example of how you can do it:
In the above code,
CSV_FILES
is a dictionary where the keys are the symbols and the values are the file paths of the corresponding CSV files.Globals.DataFolder
is the path to your data directory.Please note that when running LEAN locally using the CLI, you can already use all of the features explained in the Importing Data page of the LEAN documentation[^1^][^2^].
[^1^]: (Source: https://www.quantconnect.com/docs/v2/lean-cli/datasets/custom-data) [^2^]: (Source: https://www.quantconnect.com/forum/discussion/12456/lean-using-local-csv-files/p1)
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.
Krish Nandan das
Thank you for reply
qcA is my quantconnect Algorithm, when I run qcA it will take insight(a csv file) from cfc_network directory and based on that it will generate alpha Signal.
P.S csv does not contains any stocks data or anything it is only signals like +1, -1 etc.
Mia Alissi
Sure Krish, you can load a local CSV file that contains signals into your algorithm. Here's how you can do it:
BaseData
and override theGetSource
andReader
methods. TheGetSource
method should return aSubscriptionDataSource
that points to the local CSV file. TheReader
method should parse the CSV file and return an instance of the custom data class.Here's an example:
AddData
method and save the returned symbol.OnData
method of your algorithm, you can access the signals using theSlice
object.Please note that in the above code,
'my_signal'
is the symbol of the custom data, and'my_signals.csv'
is the name of the CSV file. You should replace them with the actual symbol and file name.Also, the
Reader
method assumes that each line in the CSV file is a signal. If the CSV file has a different format, you should adjust theReader
method accordingly.For more information, you can refer to the Importing Custom Data page of the LEAN documentation[^1^].
[^1^]: (Source: https://www.quantconnect.com/docs/v2/lean-cli/datasets/custom-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.
Krish Nandan das
do you know the error message
20240726 12:31:38.624 ERROR:: During the algorithm initialization, the
following exception has occurred: cannot instantiate abstract class
at Initialize
self.signalSymbol = self.AddData(PpoAction, 'action').Symbol
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
in main.py: line 13
cannot instantiate abstract class
cannot instantiate abstract class
at Initialize
self.signalSymbol = self.AddData(PpoAction, 'action').Symbol
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
in main.py: line 13
cannot instantiate abstract class
code is exact the same just change the class name with PpoAction
Mia Alissi
The error message "cannot instantiate abstract class" typically means that you're trying to create an instance of an abstract class. In Python, an abstract class is a class that has one or more abstract methods, and you cannot create an instance of an abstract class.
In your case, the error occurs when you're trying to add custom data with the
AddData
method:The
PpoAction
class is likely an abstract class. You should check the definition of thePpoAction
class and make sure it's not an abstract class. If it is, you should create a subclass ofPpoAction
that implements all the abstract methods, and use the subclass with theAddData
method.If you're still having trouble, you might want to refer to the Importing Custom Data page of the LEAN documentation[^1^] for more information on how to create a custom data class.
[^1^]: (Source: https://www.quantconnect.com/docs/v2/lean-cli/datasets/custom-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.
Krish Nandan das
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!