Is there any function available to get AdanceDeclineRatio for all tradable US stocks ? If function is not available, Is below method is correct implementation ?
# Selecting the universe. This example uses CoarseSelectionFunction for simplicity
self.UniverseSettings.Resolution = Resolution.Daily
self.AddUniverse(self.CoarseSelectionFunction)
self.yesterdayPrices = {}
def CoarseSelectionFunction(self, coarse):
# Filtering criteria can be adjusted as needed
filtered = [c.Symbol for c in coarse if c.Price > 10 and c.DollarVolume > 10000000]
return filtered
def OnData(self, data):
advancers = 0
decliners = 0
for symbol in self.yesterdayPrices:
if symbol in data and data[symbol] is not None:
today_price = data[symbol].Close
yesterday_price = self.yesterdayPrices[symbol]
if today_price > yesterday_price:
advancers += 1
elif today_price < yesterday_price:
decliners += 1
# Calculate and log the difference
difference = advancers - decliners
self.Log(f"Advance-Decline Difference: {difference}")
# Update yesterday's prices
for symbol in data.Keys:
self.yesterdayPrices[symbol] = data[symbol].Close
Mia Alissi
The method you've provided seems to be a correct implementation for calculating the Advance-Decline Difference for the selected universe of stocks. However, it's important to note that this method calculates the Advance-Decline Difference, not the Advance-Decline Ratio.
The Advance-Decline Ratio is typically calculated as the number of advancing stocks divided by the number of declining stocks. If you want to calculate the Advance-Decline Ratio, you can modify your code as follows:
This code will calculate the Advance-Decline Ratio for the universe of stocks you've selected in your
CoarseSelectionFunction
. Please note that this ratio can be quite volatile and is typically used as a broad market sentiment indicator, rather than for making decisions on individual stocks.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.
Dharmesh Khalasi
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!