Quant League is evolving into Strategies, our new home for sharing, discovering, and exploring trading strategies, with improved organization and a better overall experience. Q4-2025 will be the final Quant League.
LEAN is the open-source algorithmic trading engine powering QuantConnect.
Founded in 2012 LEAN has been built by a global community of 180+ engineers and powers more than 300+ hedge funds today.
Join Our Discord Channel
Join QuantConnect's Discord server for real-time support, where a vibrant community of traders and developers awaits to help you with any of your QuantConnect needs.
This research is under review. To publish this research attract three community upvotes.
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
STAFF
,
class SquareBrownJellyfish(QCAlgorithm):
def initialize(self):
self.set_start_date(2021, 2, 11)
self.set_end_date(2021, 2, 16)
self.set_cash(100000)
self.add_universe(self.my_coarse_filter_function)
self.volume_by_symbol = {}
def my_coarse_filter_function(self, coarse):
filtered = [x for x in coarse if x.price > 20 and x.volume > 1000000]
for x in filtered:
if x.Symbol not in self.volume_by_symbol:
self.volume_by_symbol[x.Symbol] = SymbolData(x.Symbol, self)
self.volume_by_symbol[x.Symbol].update(x.end_time, x.volume)
sort_by_s_m_a_volume = sorted(
self.volume_by_symbol.items(),
key=lambda x: x[1].sma.current.value if x[1].sma.is_ready else 0,
reverse=True
)[:50]
symbols = [x[0] for x in sort_by_s_m_a_volume]
for symbol in symbols:
self.debug(symbol)
return symbols
class SymbolData:
def __init__(self, symbol, algo):
self.algo = algo
self.symbol = symbol
self.sma = SimpleMovingAverage(30)
history = algo.history(symbol, 30, Resolution.DAILY)
if not history.empty:
for time, row in history.loc[symbol].iterrows():
self.sma.update(time, row['volume'])
def update(self, time, vol):
self.sma.update(time, vol)
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.
William Chau
619
,
Really appreciate your help Mia. I am so sorry, I think I attached the wrong backtest.
# region imports
from AlgorithmImports import *
# endregion
class SquareBrownJellyfish(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2024, 9, 1)
self.SetEndDate(2024, 9, 10)
self.SetCash(100000)
self.AddUniverse(self.MyCoarseFilterFunction)
self.UniverseSettings.Resolution = Resolution.Daily
self.volumeBySymbol = {}
def MyCoarseFilterFunction(self, coarse):
filtered = [ x for x in coarse if x.price > 20 and x.volume > 1000000 ]
for x in filtered:
self.AddEquity(x.Symbol.Value, Resolution.Daily)
if x.Symbol not in self.volumeBySymbol:
self.volumeBySymbol[x.Symbol] = SymbolData(x.Symbol, self)
self.volumeBySymbol[x.Symbol].Update(x.EndTime, x.Volume)
self.volumeBySymbol[x.Symbol].UpdateMax(x.EndTime, x.price)
sortBySMAVolume = sorted(self.volumeBySymbol.items(), key=lambda x: x[1].sma.Current.Value, reverse=True)[:50]
symbols = [x[0] for x in sortBySMAVolume]
# for symbol in symbols:
# self.AddEquity(cf.Symbol.Value, Resolution.Daily)
# self.debug(symbol)
return symbols
class SymbolData:
def __init__(self,symbol,algo):
self.algo = algo
self.symbol = symbol
self.sma = SimpleMovingAverage(30)
self.max = algo.MAX(symbol, 253, Resolution.Daily, Field.High)
history = algo.History(symbol,253,Resolution.Daily)
if not history.empty:
for time,row in history.loc[symbol].iterrows():
self.sma.Update(time,row['volume'])
self.max.Update(time, row['high'])
def Update(self,time,vol):
self.sma.Update(time,vol)
def UpdateMax(self, time, high):
self.max.Update(time, high)
I got error below, but I think used “self.AddEquity(x.Symbol.Value, Resolution.Daily)" to register already
Runtime Error: Please register to receive data for symbol 'CARR XDDBUNE0QTLX' using the AddSecurity() function.
at __init__
self.max = algo.MAX(symbol, 253, Resolution.Daily, Field.High)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
in main.py: line 34
at MyCoarseFilterFunction
self.volumeBySymbol[x.Symbol] = SymbolData(x.Symbol, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^
in main.py: line 18
Also, I think can't get high in coarse? line 21 . I just use the price. Thanks
During the selection function, the symbol's data is not yet subscribed yet, so we cannot use automatic indicator. Instead, use manual-updating indicator and manually update the indicator using fundamental data.
class Algo(QCAlgorithm):
def MyCoarseFilterFunction(self, coarse):
filtered = [...]
last_bar = next(self.history[TradeBar]([x.symbol for x in filtered], 1, Resolution.DAILY))
for x in filtered:
...
self.volumeBySymbol[x.Symbol].Update(x.EndTime, x.Volume, last_bar[x.symbol])
class SymbolData:
def __init__(self, symbol, algo):
...
self.high = Maximum(253)
self.low = Minimum(253)
...
def Update(self, time, vol, bar):
...
self.high.update(bar.end_time, bar.high)
self.low.update(bar.end_time, bar.low)
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!
Allocate to this Strategy
Institutional clients can contact the author and allocate capital to this strategy.
Mia Alissi
Sources: Leveraged ETFs With Systematic Risk Management, Momentum Effect In Commodities Futures, Ema Cross Universe Selection Algorithm, Gaussian Naive Bayes Model, Daily Algorithm
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.
William Chau
Really appreciate your help Mia.
I am so sorry, I think I attached the wrong backtest.
I got error below, but I think used “self.AddEquity(x.Symbol.Value, Resolution.Daily)" to register already
Also, I think can't get high in coarse? line 21 . I just use the price.
Thanks
William Chau
giving this discussion a boost
Louis Szeto
Hi William
During the selection function, the symbol's data is not yet subscribed yet, so we cannot use automatic indicator. Instead, use manual-updating indicator and manually update the indicator using fundamental data.
Best
Louis
William Chau
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!