Back

Get Highest Momentum Indicator

QC Team and Community

from QuantConnect.Data.Market import TradeBar
from datetime import datetime
from datetime import timedelta
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *
import decimal as d
import pandas as pd

class BollingerBreakoutAlgorithm(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2015, 1, 1)
self.SetEndDate(2019, 12, 10)
self.SetCash(10000)
self.MOMP = dict()

for ticker in ["XLK", "XLF", "XLI", "XLY", "XLB", "XLP", "XLV", "XLU", "XLE"]:
symbol = self.AddEquity(ticker, Resolution.Daily).Symbol
self.MOMP[symbol] = self.MOMP(symbol, 5, Resolution.Daily)

self.SetWarmUp(26, Resolution.Daily)

self.SetBenchmark("SPY")

self.Schedule.On(self.DateRules.Every(DayOfWeek.Wednesday), self.TimeRules.At(12, 0), self.EveryWedAtNoon)

def OnData(self, data):
if not all([self.MOMP.IsReady for symbol, MOMP in self.MOMP.items()]):
return

df = self.History(MOMP[symbol], 5, Resolution.Daily)
self.log("df")

,

My strategy here (may not be the best) but is to set holdings on the highest momentum scoring symbol in the list on a weekly basis and dropping the previous if it is different or does not exist.  I assume I need a dataframe including each symbol and its indicator value to find the highest scorer.  How do I set up the dataframe and get the highest scoring symbol.  Any help would be appreciated.

Thanks

Update Backtest







0

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.


Hey Rory,

I've implemented the strategy you described. To find the symbol with the highest MOMP value in your dictionary, I sorted the dictionary by MOMP value and retrieved the first element.

Here is the backtest.

Best
Rahul

1

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.


Update Backtest





0

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.


Loading...

This discussion is closed