I am trying to run an algorithm locally using Quandl (which is now Nasdaq's) data:
from AlgorithmImports import *
# Quandl often doesn't use close columns so need to tell LEAN which is the "value" column.
class QuandlCustomColumns(PythonQuandl):
'''Custom quandl data type for setting customized value column name. Value column is used
for the primary trading calculations and charting.'''
def __init__(self):
# Define ValueColumnName: cannot be None, Empty or non-existant column name
self.ValueColumnName = "adj. close"
class VirtualFluorescentYellowJackal(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 8, 15) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.tqqq = self.AddEquity("TQQQ", Resolution.Daily)
Quandl.SetAuthCode("my_api_key")
self.AddData(QuandlCustomColumns,"EOD/TQQQ", Resolution.Daily, TimeZones.NewYork)
self.AddEquity("TQQQ", Resolution.Daily)
# create 21 day EMA of TQQQ
self.ema = self.EMA("TQQQ", 21, Resolution.Daily)
self.SetWarmUp(21)
# Defaults to Equity market
self.SetBenchmark("TQQQ")
def OnData(self, data):
self.Debug("OnData")
if not data.ContainsKey("TQQQ"):
self.Debug("no TQQQ")
self.Debug("ema: " + str(self.ema.Current.Value))
However, in the output debug terminal it doesn't seem like
20220217 16:08:46.714 TRACE:: Composer(): Loading Assemblies from /Lean/Launcher/bin/Debug
20220217 16:08:46.817 TRACE:: Python for .NET Assembly: Python.Runtime, Version=2.0.11.0, Culture=neutral, PublicKeyToken=5000fea6cba702dd
20220217 16:08:46.856 TRACE:: Config.Get(): Configuration key not found. Key: data-directory - Using default value: ../../../Data/
20220217 16:08:46.866 TRACE:: Config.Get(): Configuration key not found. Key: version-id - Using default value:
20220217 16:08:46.867 TRACE:: Config.Get(): Configuration key not found. Key: cache-location - Using default value: /Lean/Data
20220217 16:08:46.869 TRACE:: Engine.Main(): LEAN ALGORITHMIC TRADING ENGINE v2.5.0.0 Mode: DEBUG (64bit) Host: Etays-MacBook-Pro
20220217 16:08:46.877 TRACE:: Engine.Main(): Started 4:08 PM
20220217 16:08:46.881 TRACE:: Config.Get(): Configuration key not found. Key: lean-manager-type - Using default value: LocalLeanManager
20220217 16:08:46.901 TRACE:: JobQueue.NextJob(): Selected /LeanCLI/main.py
20220217 16:08:46.985 TRACE:: Config.GetValue(): scheduled-event-leaky-bucket-capacity - Using default value: 120
20220217 16:08:46.987 TRACE:: Config.GetValue(): scheduled-event-leaky-bucket-time-interval-minutes - Using default value: 1440
20220217 16:08:46.988 TRACE:: Config.GetValue(): scheduled-event-leaky-bucket-refill-amount - Using default value: 18
20220217 16:08:46.998 TRACE:: Config.Get(): Configuration key not found. Key: job-organization-id - Using default value:
20220217 16:08:47.000 TRACE:: Config.Get(): Configuration key not found. Key: data-permission-manager - Using default value: DataPermissionManager
20220217 16:08:47.015 TRACE:: AlgorithmManager.CreateTokenBucket(): Initializing LeakyBucket: Capacity: 120 RefillAmount: 18 TimeInterval: 1440
20220217 16:08:47.017 TRACE:: Config.GetValue(): algorithm-manager-time-loop-maximum - Using default value: 20
20220217 16:08:47.032 TRACE:: TextSubscriptionDataSourceReader.SetCacheSize(): Setting cache size to 71582788 items
20220217 16:08:47.343 TRACE:: Config.GetValue(): algorithm-creation-timeout - Using default value: 90
20220217 16:08:47.350 TRACE:: PythonInitializer.Initialize(): start...
PythonEngine.Initialize(): Runtime.Initialize()...
Runtime.Initialize(): Py_Initialize...
Runtime.Initialize(): PyEval_InitThreads...
Runtime.Initialize(): Initialize types...
Runtime.Initialize(): Initialize types end.
Runtime.Initialize(): AssemblyManager.Initialize()...
Runtime.Initialize(): AssemblyManager.UpdatePath()...
PythonEngine.Initialize(): GetCLRModule()...
PythonEngine.Initialize(): clr GetManifestResourceStream...
20220217 16:08:48.791 TRACE:: PythonInitializer.Initialize(): ended
20220217 16:08:48.796 TRACE:: AlgorithmPythonWrapper(): Python version 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:25:33)
[GCC 7.3.0]: Importing python module main
20220217 16:08:51.128 TRACE:: AlgorithmPythonWrapper(): main successfully imported.
20220217 16:08:51.142 TRACE:: AlgorithmPythonWrapper(): Creating IAlgorithm instance.
20220217 16:08:51.153 TRACE:: Config.GetValue(): api-data-update-period - Using default value: 1
20220217 16:08:51.289 TRACE:: Config.GetValue(): mute-python-library-logging - Using default value: True
20220217 16:08:51.315 TRACE:: LocalObjectStore.Initialize(): Storage Root: /Storage/QCAlgorithm. StorageFileCount 100. StorageLimitMB 5
20220217 16:08:51.335 TRACE:: BacktestingSetupHandler.Setup(): Setting up job: UID: 183852, PID: 795637783, Version: 2.5.0.0, Source: WebIDE
20220217 16:08:51.342 TRACE:: Config.Get(): Configuration key not found. Key: security-data-feeds - Using default value:
20220217 16:08:51.418 TRACE:: Config.Get(): Configuration key not found. Key: quandl-auth-token - Using default value:
20220217 16:08:51.495 TRACE:: BaseSetupHandler.SetupCurrencyConversions():
Symbol Quantity Conversion = Value in USD
USD: $ 100000.00 @ 1.00 = $100000.0
-------------------------------------------------
CashBook Total Value: $100000.0
20220217 16:08:51.500 TRACE:: SetUp Backtesting: User: 183852 ProjectId: 795637783 AlgoId: 1672027341
20220217 16:08:51.502 TRACE:: Dates: Start: 08/15/2021 End: 02/16/2022 Cash: ¤100,000.00 MaximumRuntime: 100.00:00:00 MaxOrders: 2147483647
20220217 16:08:51.505 TRACE:: BacktestingResultHandler(): Sample Period Set: 66.84
20220217 16:08:51.508 TRACE:: Time.TradeableDates(): Security Count: 2
20220217 16:08:51.512 TRACE:: Config.GetValue(): forward-console-messages - Using default value: True
20220217 16:08:51.516 TRACE:: JOB HANDLERS:
20220217 16:08:51.518 TRACE:: DataFeed: QuantConnect.Lean.Engine.DataFeeds.FileSystemDataFeed
20220217 16:08:51.519 TRACE:: Setup: QuantConnect.Lean.Engine.Setup.BacktestingSetupHandler
20220217 16:08:51.521 TRACE:: RealTime: QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler
20220217 16:08:51.522 TRACE:: Results: QuantConnect.Lean.Engine.Results.BacktestingResultHandler
20220217 16:08:51.523 TRACE:: Transactions: QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler
20220217 16:08:51.524 TRACE:: Alpha: QuantConnect.Lean.Engine.Alphas.DefaultAlphaHandler
20220217 16:08:51.525 TRACE:: ObjectStore: QuantConnect.Lean.Engine.Storage.LocalObjectStore
20220217 16:08:51.526 TRACE:: History Provider: QuantConnect.Lean.Engine.HistoricalData.HistoryProviderManager
20220217 16:08:51.538 TRACE:: Debug: Launching analysis for 1672027341 with LEAN Engine v2.5.0.0
20220217 16:08:51.563 TRACE:: Event Name "Daily Sampling", scheduled to run at 8/15/2021 4:00:00 AM (UTC)...
20220217 16:08:51.564 TRACE:: AlgorithmManager.Run(): Begin DataStream - Start: 8/15/2021 12:00:00 AM Stop: 2/16/2022 4:08:51 PM
20220217 16:08:51.589 TRACE:: AlgorithmManager.Stream(): WarmupHistoryRequest: EOD/TQQQ.QuandlCustomColumns: Start: 7/25/2021 4:00:00 AM End: 8/15/2021 4:00:00 AM
Resolution: Daily
20220217 16:08:51.591 TRACE:: AlgorithmManager.Stream(): WarmupHistoryRequest: TQQQ: Start: 7/16/2021 4:00:00 AM End: 8/15/2021 4:00:00 AM Resolution: Daily
20220217 16:08:51.600 TRACE:: Config.GetValue(): data-feed-max-work-weight - Using default value: 400
20220217 16:08:51.601 TRACE:: Config.GetValue(): data-feed-workers-count - Using default value: 4
20220217 16:08:51.603 TRACE:: WeightedWorkScheduler(): will use 4 workers and MaxWorkWeight is 400
20220217 16:08:51.629 TRACE:: Config.GetValue(): show-missing-data-logs - Using default value: False
20220217 16:08:53.123 TRACE:: AlgorithmManager.Stream(): Finished warmup
20220217 16:08:53.149 TRACE:: Debug: Algorithm warming up...
OnData
no TQQQ
ema: 0.0
20220217 16:08:53.151 TRACE:: Debug: OnData
no TQQQ
ema: 0.0
20220217 16:08:53.278 TRACE:: UniverseSelection.AddPendingInternalDataFeeds(): Adding internal benchmark data feed
TQQQ,#0,TQQQ,Hour,TradeBar,Trade,Adjusted,OpenInterest,Internal
20220217 16:08:53.303 TRACE:: Debug: Algorithm finished warming up.
20220217 16:08:53.305 TRACE:: Debug: OnData
no TQQQ
ema: 0.0
20220217 16:08:53.322 TRACE:: Synchronizer.GetEnumerator(): Exited thread.
20220217 16:08:53.323 TRACE:: AlgorithmManager.Run(): Firing On End Of Algorithm...
20220217 16:08:53.326 TRACE:: Engine.Run(): Exiting Algorithm Manager
20220217 16:08:53.330 TRACE:: FileSystemDataFeed.Exit(): Start. Setting cancellation token...
20220217 16:08:53.332 TRACE:: FileSystemDataFeed.Exit(): Exit Finished.
20220217 16:08:53.334 TRACE:: DefaultAlphaHandler.Exit(): Exiting...
20220217 16:08:53.344 TRACE:: DefaultAlphaHandler.Exit(): Ended
20220217 16:08:53.346 TRACE:: BacktestingResultHandler.Exit(): starting...
20220217 16:08:53.347 TRACE:: BacktestingResultHandler.Exit(): Saving logs...
20220217 16:08:53.355 TRACE:: Debug: OnData
no TQQQ
ema: 0.0
20220217 16:08:53.356 TRACE:: StopSafely(): waiting for 'Result Thread' thread to stop...
20220217 16:08:53.357 TRACE:: Debug: Algorithm Id:(1672027341) completed in 1.80 seconds at 0k data points per second. Processing total of 86 data points.
20220217 16:08:53.360 TRACE:: Debug: Your log was successfully created and can be retrieved from: /Results/1672027341-log.txt
20220217 16:08:53.361 TRACE:: BacktestingResultHandler.Run(): Ending Thread...
20220217 16:08:53.516 TRACE:: Config.GetValue(): regression-update-statistics - Using default value: False
20220217 16:08:53.518 TRACE::
STATISTICS:: Total Trades 0
STATISTICS:: Average Win 0%
STATISTICS:: Average Loss 0%
STATISTICS:: Compounding Annual Return 0%
STATISTICS:: Drawdown 0%
STATISTICS:: Expectancy 0
STATISTICS:: Net Profit 0%
STATISTICS:: Sharpe Ratio 0
STATISTICS:: Probabilistic Sharpe Ratio 0%
STATISTICS:: Loss Rate 0%
STATISTICS:: Win Rate 0%
STATISTICS:: Profit-Loss Ratio 0
STATISTICS:: Alpha 0
STATISTICS:: Beta 0
STATISTICS:: Annual Standard Deviation 0
STATISTICS:: Annual Variance 0
STATISTICS:: Information Ratio 0
STATISTICS:: Tracking Error 0
STATISTICS:: Treynor Ratio 0
STATISTICS:: Total Fees $0.00
STATISTICS:: Estimated Strategy Capacity $0
STATISTICS:: Lowest Capacity Asset
STATISTICS:: Fitness Score 0
STATISTICS:: Kelly Criterion Estimate 0
STATISTICS:: Kelly Criterion Probability Value 0
STATISTICS:: Sortino Ratio 79228162514264337593543950335
STATISTICS:: Return Over Maximum Drawdown 79228162514264337593543950335
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
20220217 16:08:53.520 TRACE:: BacktestingResultHandler.SendAnalysisResult(): Processed final packet
20220217 16:08:53.523 TRACE:: Engine.Run(): Disconnecting from brokerage...
20220217 16:08:53.525 TRACE:: Engine.Run(): Disposing of setup handler...
20220217 16:08:53.528 TRACE:: Engine.Main(): Analysis Completed and Results Posted.
Engine.Main(): Analysis Complete.
20220217 16:08:53.550 TRACE:: Engine.Main(): Packet removed from queue: 1672027341
20220217 16:08:53.552 TRACE:: LeanEngineSystemHandlers.Dispose(): start...
20220217 16:08:53.554 TRACE:: LeanEngineSystemHandlers.Dispose(): Disposed of system handlers.
20220217 16:08:53.557 TRACE:: LeanEngineAlgorithmHandlers.Dispose(): start...
20220217 16:08:53.565 TRACE:: LeanEngineAlgorithmHandlers.Dispose(): Disposed of algorithm handlers.
20220217 16:08:53.568 TRACE:: Program.Main(): Exiting Lean...
Successfully ran 'Virtual Fluorescent Yellow Jackal' in the 'backtesting' environment and stored the output in 'Virtual Fluorescent Yellow
Jackal/backtests/2022-02-17_11-08-44'
Any idea why the data coming from Quandl is apparently incorrect?
Where is the Qunadl ticker data stored in the directory? How can I verify that it is withdrawn correctly?
Etay Luz
Why is it that the data from Quandl is not avaiable in OnData?
Also, when working locally - is it necessary to call AddEquity after calling AddData?
Fred Painchaud
Hi Etay,
When running locally, you do not have access to the data in the cloud. You need to pay for QC's data or you need to get your data feed from elsewhere and integrate it into LEAN.
So, are you subscribed to Nasdaq's?
Since your algo does not trade, it looks like it does not have the data (either because you don't have it or the connection to it is not working).
To answer the other question, no, you do not have to call AddEquity after AddData.
Fred
Etay Luz
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!