I'm taking the intro course on equity. After lesson 10 on Liquid Value Stock Selection, I copied and pasted the code into a test project, with some small modification. When I ran backtesting, it shows:
20230224 10:38:35.927 ERROR:: Extensions.SetRuntimeError(): Extensions.SetRuntimeError(): RuntimeError at 06/01/2013 04:00:00 UTC. Context: Synchronizer Python.Runtime.PythonException: SelectCoarse() missing 1 required positional argument: 'coarse'
at Python.Runtime.PythonException.ThrowLastAsClrException()
at Python.Runtime.Dispatcher.TrueDispatch(Object[] args)
at Python.Runtime.Dispatcher.Dispatch(Object[] args)
at __System_Func`2\[\[System_Collections_Generic_IEnumerable`1\[\[QuantConnect_Data_UniverseSelection_CoarseFundamental\, QuantConnect_Common\, Version=2_5_0_0\, Culture=neutral\, PublicKeyToken=null\]\]\, System_Private_CoreLib\, Version=6_0_0_0\, Culture=neutral\, PublicKeyToken=7cec85d7bea7798e\]\,\[System_Object\, System_Private_CoreLib\,
Version=6_0_0_0\, Culture=neutral\, PublicKeyToken=7cec85d7bea7798e\]\]Dispatcher.Invoke(IEnumerable`1 )
at QuantConnect.Extensions.<>c__DisplayClass126_0`1.<ConvertToUniverseSelectionSymbolDelegate>b__0(T data) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/Extensions.cs:line 2707
at QuantConnect.Algorithm.Framework.Selection.FineFundamentalUniverseSelectionModel.SelectCoarse(QCAlgorithm algorithm, IEnumerable`1 coarse) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Algorithm.Framework/Selection/FineFundamentalUniverseSelectionModel.cs:line 75
at QuantConnect.Algorithm.Framework.Selection.FundamentalUniverseSelectionModel.<>c__DisplayClass5_0.<CreateCoarseFundamentalUniverse>b__0(IEnumerable`1 coarse) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Algorithm.Framework/Selection/FundamentalUniverseSelectionModel.cs:line 85
at QuantConnect.Data.UniverseSelection.CoarseFundamentalUniverse.SelectSymbols(DateTime utcTime, BaseDataCollection data) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/Data/UniverseSelection/CoarseFundamentalUniverse.cs:line 97
at QuantConnect.Data.UniverseSelection.SelectSymbolsUniverseDecorator.SelectSymbols(DateTime utcTime, BaseDataCollection data) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/Data/UniverseSelection/SelectSymbolsUniverseDecorator.cs:line 55
at QuantConnect.Lean.Engine.DataFeeds.UniverseSelection.ApplyUniverseSelection(Universe universe, DateTime dateTimeUtc, BaseDataCollection universeData) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/DataFeeds/UniverseSelection.cs:line 124
at QuantConnect.Lean.Engine.DataFeeds.SubscriptionSynchronizer.Sync(IEnumerable`1 subscriptions, CancellationToken cancellationToken)+MoveNext() in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/DataFeeds/SubscriptionSynchronizer.cs:line 224
at QuantConnect.Lean.Engine.DataFeeds.Synchronizer.StreamData(CancellationToken cancellationToken)+MoveNext() in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/DataFeeds/Synchronizer.cs:line 101
My code is as follows:
class LiquidValueUniverseSelectionModel(FineFundamentalUniverseSelectionModel):
def __init__(self, universe_settings: UniverseSettings = None):
super().__init__(coarseSelector=self.SelectCoarse,
fineSelector=self.SelectFine,
universeSettings=universe_settings)
self.lastMonth = -1
def SelectCoarse(self, algorithm: QCAlgorithm, coarse: List[CoarseFundamental]) -> List[Symbol]:
if self.lastMonth == algorithm.Time.month:
return Universe.Unchanged
self.lastMonth = algorithm.Time.month
sortedByDollarVolume = sorted([x for x in coarse if x.HasFundamentalData],
key=lambda x: x.DollarVolume, reverse=True)
return [x.Symbol for x in sortedByDollarVolume[:100]]
def SelectFine(self, algorithm: QCAlgorithm, fine: List[FineFundamental]) -> List[Symbol]:
sortedByYields = sorted(fine, key=lambda f: f.ValuationRatios.EarningYield, reverse=True)
universe = sortedByYields[:10] + sortedByYields[-10:]
return [f.Symbol for f in universe]
class LiquidValueStocks(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2017, 5, 15)
self.SetEndDate(2017, 7, 15)
self.SetCash(100000)
self.UniverseSettings.Resolution = Resolution.Hour
self.AddUniverseSelection(LiquidValueUniverseSelectionModel())
# 1. Create and instance of the LongShortEYAlphaModel
self.AddAlpha(LongShortEYAlphaModel())
self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
self.SetExecution(ImmediateExecutionModel())
Are you able to replicate it from your end?
Louis Szeto
Hi Bella
You may take a look at my comment here. The first point will address your issue as well.
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.
Bella Yousefi
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!