Hi there,
I am testing a simple algorithm using algorithm framework. My backtesting is running and gives out a result but comes up with alerts for various stocks:
CPRT R735QTJ8XC9X: The security does not have an accurate price as it has not yet received a bar of data. Before placing a trade (or using SetHoldings) warm up your algorithm with SetWarmup, or use slice.Contains(symbol) to confirm the Slice object has price before using the data. Data does not necessarily all arrive at the same time so your algorithm should confirm the data is ready before using it. In live trading this can mean you do not have an active subscription to the asset class you're trying to trade. If using custom data make sure you've set the 'Value' property.
not sure what's wrong since i m using parameters like:
- if security.IsTradable
- if Securities[sec].HasData
Also, i m not loading any historical data or using indicators. Find code attached, also backtesting
# region imports
from AlgorithmImports import *
from datetime import timedelta, datetime
from QuantConnect.Data.UniverseSelection import *
from Selection.FundamentalUniverseSelectionModel import FundamentalUniverseSelectionModel
from Execution.ImmediateExecutionModel import ImmediateExecutionModel
from Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel
# endregion
class Third_Attempt(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 1, 1) # Set Start Date
self.SetEndDate(2022, 1, 1) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.AddUniverseSelection(Highperformance())
self.UniverseSettings.Resolution = Resolution.Daily
self.AddAlpha(BuyPerformance())
self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel(lambda time: None))
self.SetExecution(ImmediateExecutionModel())
class Highperformance (FundamentalUniverseSelectionModel):
def __init__(self):
super().__init__( True, None)
self.lastMonth = -1
self.spy = Symbol.Create('SPY', SecurityType.Equity, Market.USA)
def SelectCoarse(self, algorithm, coarse):
#run the algorithm once a month, return Universe.Unchanged in case we are looking at exactly the same month
if algorithm.Time.month == self.lastMonth:
return Universe.Unchanged
self.lastMonth = algorithm.Time.month
sortedByVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
filteredByFundamentals = [x.Symbol for x in sortedByVolume if x.HasFundamentalData]
return filteredByFundamentals
def SelectFine(self, algorithm, fine):
sorted_high = sorted([x for x in fine if x.MarketCap > 2e9
and 0.5 > x.OperationRatios.AVG5YrsROIC.FiveYears > 0.20
and 50 > x.ValuationRatios.PERatio > 20
and x.AssetClassification.MorningstarSectorCode != MorningstarSectorCode.FinancialServices
and x.AssetClassification.MorningstarSectorCode != MorningstarSectorCode.Healthcare],
key = lambda x: x.ValuationRatios.PERatio, reverse=True)
fundamental_universe = [x.Symbol for x in sorted_high[:5]] + [self.spy]
algorithm.Debug('Universe Selection:')
algorithm.Debug(str(algorithm.Time))
algorithm.Debug('/n ')
for security in fundamental_universe:
algorithm.Debug(str(security))
#return [x.Symbol for x in sorted_high[:5]] + [self.spy]
return [x.Symbol for x in sorted_high[:5]]
class BuyPerformance(AlphaModel):
def __init__(self):
self.lastMonth = -1
self.newAdds = []
#removals to be removed
self.newRemovals = []
def Update(self, algorithm, data):
insights = []
for added in self.newAdds:
if not algorithm.Securities[added].Invested and algorithm.Securities[added].HasData:
insights.append(Insight(added, timedelta(30), InsightType.Price, InsightDirection.Up))
# to be removed at a later stage
for removed in self.newRemovals:
if removed not in data.Bars:
continue
insights.append(Insight(removed, timedelta(30), InsightType.Price, InsightDirection.Flat))
return insights
def OnSecuritiesChanged(self, algorithm, changes):
#When assets are added to the universe, they will trigger OnSecuritiesChanged() event.
#From there, you can initialize any state or history required for the Alpha Model
for security in changes.AddedSecurities:
#if security.Symbol != self.spy and security.Symbol not in self.newAdds:
if security.Symbol not in self.newAdds and security.IsTradable:
self.newAdds.append(security.Symbol)
for security in changes.RemovedSecurities:
#if security.Symbol != self.spy:
if security.IsTradable:
self.newRemovals.append(security.Symbol)
Vladimir
Jose David Delgado Mosquera
Try the algorithm with my changes. It doesn't issue any of the warnings you mentioned.
If you are satisfied with my answer, please accept it and don't forget to like it
Jose David Delgado Mosquera
Hi Vladimir,
thanks for your help. The backtest is still coming up with same warnings. Also, The documentation also says: “if you have a dynamic universe of assets we recommend manually requesting historical data when required”, making allusion that perhaps is not the optimal to have warm-up in this case.
Appreciate your help, wonder if you know the root of the issue?
Cheers,
Jose
Vladimir
Jose David Delgado Mosquera
--> The backtest is still coming up with same warnings.
This is weird. Here is the full log of my backtest.
2021-01-01 00:00:00 : Launching analysis for df8476d4e14530e2fde7a10ca724b052 with LEAN Engine v2.5.0.0.13675
2021-01-01 00:00:00 : Universe Selection:
2021-01-01 00:00:00 : 2021-01-01 00:00:00
2021-01-01 00:00:00 : /n
2021-01-01 00:00:00 : POOL
2021-01-01 00:00:00 : ADBE
2021-01-01 00:00:00 : AAON
2021-01-01 00:00:00 : CPRT
2021-01-01 00:00:00 : MNST
2021-01-01 00:00:00 : Warning: all market orders sent using daily data, or market orders sent after hours are automatically converted into MarketOnOpen orders.
2021-02-02 00:00:00 : Universe Selection:
2021-02-02 00:00:00 : 2021-02-02 00:00:00
2021-02-02 00:00:00 : /n
2021-02-02 00:00:00 : INTU
2021-02-02 00:00:00 : UI
2021-02-02 00:00:00 : POOL
2021-02-02 00:00:00 : FIZZ
2021-02-02 00:00:00 : ADBE
2021-03-02 00:00:00 : Universe Selection:
2021-03-02 00:00:00 : 2021-03-02 00:00:00
2021-03-02 00:00:00 : /n
2021-03-02 00:00:00 : RACE
2021-03-02 00:00:00 : ADBE
2021-03-02 00:00:00 : UI
2021-03-02 00:00:00 : FFIV
2021-03-02 00:00:00 : NTES
2021-04-01 00:00:00 : Universe Selection:
2021-04-01 00:00:00 : 2021-04-01 00:00:00
2021-04-01 00:00:00 : /n
2021-04-01 00:00:00 : AAON
2021-04-01 00:00:00 : FFIV
2021-04-01 00:00:00 : ODFL
2021-04-01 00:00:00 : ADBE
2021-04-01 00:00:00 : JKHY
2021-05-01 00:00:00 : Universe Selection:
2021-05-01 00:00:00 : 2021-05-01 00:00:00
2021-05-01 00:00:00 : /n
2021-05-01 00:00:00 : WDFC
2021-05-01 00:00:00 : ADBE
2021-05-01 00:00:00 : AAON
2021-05-01 00:00:00 : CPRT
2021-05-01 00:00:00 : JKHY
2021-06-02 00:00:00 : Universe Selection:
2021-06-02 00:00:00 : 2021-06-02 00:00:00
2021-06-02 00:00:00 : /n
2021-06-02 00:00:00 : EA
2021-06-02 00:00:00 : RACE
2021-06-02 00:00:00 : PZZA
2021-06-02 00:00:00 : AAON
2021-06-02 00:00:00 : WDFC
2021-07-01 00:00:00 : Universe Selection:
2021-07-01 00:00:00 : 2021-07-01 00:00:00
2021-07-01 00:00:00 : /n
2021-07-01 00:00:00 : RACE
2021-07-01 00:00:00 : WDFC
2021-07-01 00:00:00 : AAON
2021-07-01 00:00:00 : NKE
2021-07-01 00:00:00 : POOL
2021-08-03 00:00:00 : Universe Selection:
2021-08-03 00:00:00 : 2021-08-03 00:00:00
2021-08-03 00:00:00 : /n
2021-08-03 00:00:00 : ROST
2021-08-03 00:00:00 : NKE
2021-08-03 00:00:00 : AAON
2021-08-03 00:00:00 : JKHY
2021-08-03 00:00:00 : ANET
2021-09-01 00:00:00 : Universe Selection:
2021-09-01 00:00:00 : 2021-09-01 00:00:00
2021-09-01 00:00:00 : /n
2021-09-01 00:00:00 : SBUX
2021-09-01 00:00:00 : IT
2021-09-01 00:00:00 : AAON
2021-09-01 00:00:00 : NKE
2021-09-01 00:00:00 : JKHY
2021-10-01 00:00:00 : Universe Selection:
2021-10-01 00:00:00 : 2021-10-01 00:00:00
2021-10-01 00:00:00 : /n
2021-10-01 00:00:00 : ADBE
2021-10-01 00:00:00 : IT
2021-10-01 00:00:00 : SBUX
2021-10-01 00:00:00 : AAON
2021-10-01 00:00:00 : BF.B
2021-11-02 00:00:00 : Universe Selection:
2021-11-02 00:00:00 : 2021-11-02 00:00:00
2021-11-02 00:00:00 : /n
2021-11-02 00:00:00 : ROL
2021-11-02 00:00:00 : RACE
2021-11-02 00:00:00 : ANET
2021-11-02 00:00:00 : WDFC
2021-11-02 00:00:00 : NKE
2021-12-01 00:00:00 : Universe Selection:
2021-12-01 00:00:00 : 2021-12-01 00:00:00
2021-12-01 00:00:00 : /n
2021-12-01 00:00:00 : RACE
2021-12-01 00:00:00 : ROL
2021-12-01 00:00:00 : CLX
2021-12-01 00:00:00 : EA
2021-12-01 00:00:00 : NKE
2022-01-01 00:00:00 : Universe Selection:
2022-01-01 00:00:00 : 2022-01-01 00:00:00
2022-01-01 00:00:00 : /n
2022-01-01 00:00:00 : CLX
2022-01-01 00:00:00 : EA
2022-01-01 00:00:00 : ROL
2022-01-01 00:00:00 : RACE
2022-01-01 00:00:00 : WDFC
2022-02-01 00:00:00 : Universe Selection:
2022-02-01 00:00:00 : 2022-02-01 00:00:00
2022-02-01 00:00:00 : /n
2022-02-01 00:00:00 : EXPO
2022-02-01 00:00:00 : EA
2022-02-01 00:00:00 : CLX
2022-02-01 00:00:00 : WDFC
2022-02-01 00:00:00 : TREX
2022-03-01 00:00:00 : Universe Selection:
2022-03-01 00:00:00 : 2022-03-01 00:00:00
2022-03-01 00:00:00 : /n
2022-03-01 00:00:00 : EXPO
2022-03-01 00:00:00 : IHG
2022-03-01 00:00:00 : LULU
2022-03-01 00:00:00 : AMD
2022-03-01 00:00:00 : ADBE
2022-03-02 00:00:00 : Algorithm Id:(df8476d4e14530e2fde7a10ca724b052) completed in 44.48 seconds at 60k data points per second. Processing total of 2,647,984 data points.
Can you share your log of the algorithm with my changes.
Jose David Delgado Mosquera
Hi @vladimir_2
I have attached a couple of pictures of the logs. Could not get the downloads since i reached my daily limit, but anyway still getting that issue with the data on the securities.
Let me know your thoughts mate - appreciate the help!
Vladimir
Jose David Delgado Mosquera
One more suggestion.
Go to My Account / Account Settings
and disable the QuantConnect Algorithm Environment 3.0 Beta
Jose David Delgado Mosquera
Vladimir
i turned off the beta environment and even my intiial algorithm didn't give any warnings. Then i turned it on again and tried and it miraculously worked too. Like IT crowd: ‘turn it on and turn it off’
any ideas as to why this is happening?
appreciate your support mate
Vladimir
Jose David Delgado Mosquera
If you are satisfied with my answer, please accept it and don't forget to like it.
Jose David Delgado Mosquera
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!