Greetings everyone,
I tried to run the python lean backtest on Google Сolab (ubuntu 18.04) following the installation instructions from github and I failed. It seems that the installation instruction for Ubuntu isn't up to date or have bugs. Please take a look at the notebook link below and please tell me what I need to do to make the python backtest algorithm work. The error stack trace is also attached.
I appreciate any help you can provide.
=20210625 19:41:57.081 TRACE:: Config.GetValue(): debug-mode - Using default value: False
20210625 19:41:57.089 TRACE:: Config.Get(): Configuration key not found. Key: results-destination-folder - Using default value:
20210625 19:41:57.089 TRACE:: Config.Get(): Configuration key not found. Key: plugin-directory - Using default value:
20210625 19:41:57.092 TRACE:: Config.Get(): Configuration key not found. Key: composer-dll-directory - Using default value:
20210625 19:41:57.097 TRACE:: Composer(): Loading Assemblies from /content/Lean/Launcher/bin/Debug/
20210625 19:41:57.129 TRACE:: Python for .NET Assembly: Python.Runtime, Version=2.0.4.0, Culture=neutral, PublicKeyToken=5000fea6cba702dd
20210625 19:41:57.214 TRACE:: Config.Get(): Configuration key not found. Key: data-directory - Using default value: ../../../Data/
20210625 19:41:57.216 TRACE:: Config.Get(): Configuration key not found. Key: version-id - Using default value:
20210625 19:41:57.216 TRACE:: Config.Get(): Configuration key not found. Key: cache-location - Using default value: ../../../Data/
20210625 19:41:57.216 TRACE:: Engine.Main(): LEAN ALGORITHMIC TRADING ENGINE v2.5.0.0 Mode: DEBUG (64bit) Host: d7ec83e502bd
20210625 19:41:57.221 TRACE:: Engine.Main(): Started 7:41 PM
20210625 19:41:57.224 TRACE:: Config.Get(): Configuration key not found. Key: lean-manager-type - Using default value: LocalLeanManager
20210625 19:41:57.244 TRACE:: JobQueue.NextJob(): Selected ../../../Algorithm.Python/BasicTemplateAlgorithm.py
20210625 19:41:57.348 TRACE:: Config.GetValue(): scheduled-event-leaky-bucket-capacity - Using default value: 120
20210625 19:41:57.348 TRACE:: Config.GetValue(): scheduled-event-leaky-bucket-time-interval-minutes - Using default value: 1440
20210625 19:41:57.348 TRACE:: Config.GetValue(): scheduled-event-leaky-bucket-refill-amount - Using default value: 18
20210625 19:41:57.349 TRACE:: Config.Get(): Configuration key not found. Key: algorithm-id - Using default value: BasicTemplateAlgorithm
20210625 19:41:57.350 TRACE:: Config.GetValue(): job-project-id - Using default value: 0
20210625 19:41:57.351 TRACE:: Config.Get(): Configuration key not found. Key: data-permission-manager - Using default value: DataPermissionManager
20210625 19:41:57.354 TRACE:: Config.Get(): Configuration key not found. Key: results-destination-folder - Using default value: /content/Lean/Launcher/bin/Debug
20210625 19:41:57.367 TRACE:: Config.Get(): Configuration key not found. Key: object-store-root - Using default value: ./storage
20210625 19:41:57.373 TRACE:: AlgorithmManager.CreateTokenBucket(): Initializing LeakyBucket: Capacity: 120 RefillAmount: 18 TimeInterval: 1440
20210625 19:41:57.375 TRACE:: Config.GetValue(): algorithm-manager-time-loop-maximum - Using default value: 20
20210625 19:41:57.389 TRACE:: TextSubscriptionDataSourceReader.SetCacheSize(): Setting cache size to 71582788 items
20210625 19:41:57.781 TRACE:: Config.GetValue(): algorithm-creation-timeout - Using default value: 90
20210625 19:41:57.784 TRACE:: PythonInitializer.Initialize(): start...
PythonEngine.Initialize(): Runtime.Initialize()...
20210625 19:41:57.818 ERROR:: Loader.TryCreatePythonAlgorithm(): System.TypeInitializationException: The type initializer for 'Delegates' threw an exception.
---> System.MissingMethodException: Failed to load symbol PyDictProxy_New: dotnet: undefined symbol: PyDictProxy_New
at Python.Runtime.Platform.LinuxLoader.GetFunction(IntPtr dllHandle, String name)
at Python.Runtime.Runtime.Delegates.GetFunctionByName(String functionName, IntPtr libraryHandle)
at Python.Runtime.Runtime.Delegates..cctor()
--- End of inner exception stack trace ---
at Python.Runtime.Runtime.Delegates.get_Py_IsInitialized()
at Python.Runtime.Runtime.Py_IsInitialized()
at Python.Runtime.Runtime.Initialize(Boolean initSigs, ShutdownMode mode)
at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv, Boolean initSigs, ShutdownMode mode)
at Python.Runtime.PythonEngine.Initialize(Boolean setSysArgv, Boolean initSigs, ShutdownMode mode)
at Python.Runtime.PythonEngine.Initialize()
at QuantConnect.Python.PythonInitializer.Initialize() in /content/Lean/Common/Python/PythonInitializer.cs:line 45
at QuantConnect.AlgorithmFactory.Loader.TryCreatePythonAlgorithm(String assemblyPath, IAlgorithm& algorithmInstance, String& errorMessage) in /content/Lean/AlgorithmFactory/Loader.cs:line 171
20210625 19:41:57.819 ERROR:: Engine.Run(): QuantConnect.Lean.Engine.Setup.AlgorithmSetupException: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ../../../Algorithm.Python/BasicTemplateAlgorithm.py. The type initializer for 'Delegates' threw an exception.
at QuantConnect.Lean.Engine.Setup.BacktestingSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in /content/Lean/Engine/Setup/BacktestingSetupHandler.cs:line 104
at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath, WorkerThread workerThread) in /content/Lean/Engine/Engine.cs:line 119
20210625 19:41:57.819 TRACE:: JOB HANDLERS:
20210625 19:41:57.819 TRACE:: DataFeed: QuantConnect.Lean.Engine.DataFeeds.FileSystemDataFeed
20210625 19:41:57.819 TRACE:: Setup: QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler
20210625 19:41:57.819 TRACE:: RealTime: QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler
20210625 19:41:57.819 TRACE:: Results: QuantConnect.Lean.Engine.Results.BacktestingResultHandler
20210625 19:41:57.820 TRACE:: Transactions: QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler
20210625 19:41:57.820 TRACE:: Alpha: QuantConnect.Lean.Engine.Alphas.DefaultAlphaHandler
20210625 19:41:57.820 TRACE:: ObjectStore: QuantConnect.Lean.Engine.Storage.LocalObjectStore
20210625 19:41:57.820 TRACE:: DefaultAlphaHandler.Exit(): Exiting...
20210625 19:41:57.821 TRACE:: DefaultAlphaHandler.Exit(): Ended
20210625 19:41:57.822 TRACE:: BacktestingResultHandler.Exit(): starting...
20210625 19:41:57.822 TRACE:: BacktestingResultHandler.Exit(): Saving logs...
20210625 19:41:57.825 ERROR:: Algorithm.Initialize() Error: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ../../../Algorithm.Python/BasicTemplateAlgorithm.py. The type initializer for 'Delegates' threw an exception. Stack Trace: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ../../../Algorithm.Python/BasicTemplateAlgorithm.py. The type initializer for 'Delegates' threw an exception.
During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ../../../Algorithm.Python/BasicTemplateAlgorithm.py. The type initializer for 'Delegates' threw an exception.
20210625 19:41:57.825 TRACE:: Debug: Your log was successfully created and can be retrieved from: /content/Lean/Launcher/bin/Debug/BasicTemplateAlgorithm-log.txt
20210625 19:41:57.825 TRACE:: BacktestingResultHandler.Run(): Ending Thread...
20210625 19:41:57.825 TRACE:: StopSafely(): waiting for 'Result Thread' thread to stop...
20210625 19:41:57.963 TRACE:: Config.GetValue(): regression-update-statistics - Using default value: False
20210625 19:41:57.965 TRACE::
STATISTICS:: Fitness Score 0
STATISTICS:: Kelly Criterion Estimate 0
STATISTICS:: Kelly Criterion Probability Value 0
STATISTICS:: Sortino Ratio 0
STATISTICS:: Return Over Maximum Drawdown 0
STATISTICS:: Portfolio Turnover 0
STATISTICS:: Total Insights Generated 0
STATISTICS:: Total Insights Closed 0
STATISTICS:: Total Insights Analysis Completed 0
STATISTICS:: Long Insight Count 0
STATISTICS:: Short Insight Count 0
STATISTICS:: Long/Short Ratio 100%
STATISTICS:: Estimated Monthly Alpha Value $0
STATISTICS:: Total Accumulated Estimated Alpha Value $0
STATISTICS:: Mean Population Estimated Insight Value $0
STATISTICS:: Mean Population Direction 0%
STATISTICS:: Mean Population Magnitude 0%
STATISTICS:: Rolling Averaged Population Direction 0%
STATISTICS:: Rolling Averaged Population Magnitude 0%
STATISTICS:: OrderListHash d41d8cd98f00b204e9800998ecf8427e
20210625 19:41:57.965 TRACE:: BacktestingResultHandler.SendAnalysisResult(): Processed final packet
20210625 19:41:57.965 TRACE:: Engine.Run(): Disposing of setup handler...
20210625 19:41:57.965 TRACE:: Engine.Main(): Analysis Completed and Results Posted.
Engine.Main(): Analysis Complete.
20210625 19:41:57.966 TRACE:: Config.GetValue(): close-automatically - Using default value: False
Engine.Main(): Press any key to continue.
20210625 19:42:22.441 TRACE:: Engine.Main(): Packet removed from queue: BasicTemplateAlgorithm
20210625 19:42:22.441 TRACE:: LeanEngineSystemHandlers.Dispose(): start...
20210625 19:42:22.441 TRACE:: LeanEngineSystemHandlers.Dispose(): Disposed of system handlers.
20210625 19:42:22.441 TRACE:: LeanEngineAlgorithmHandlers.Dispose(): start...
20210625 19:42:22.442 TRACE:: LeanEngineAlgorithmHandlers.Dispose(): Disposed of algorithm handlers.
20210625 19:42:22.442 TRACE:: Program.Main(): Exiting Lean...
Louis Szeto
Hi Dennis ig
Sorry for the delay. You will just need to activate your self-constructed conda environment "qc_lean" by adding the code:
at the end of step 2 to allow LEAN runs in its required dependencies. We have attached a modified version of your google colab notebook for your reference.
Best,
Louis Szeto
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.
Dennis ig
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!