Hello All,
First of all, I'd like to appologize for being an absolute noob. I am trying my best to learn by doing the Bootcamp and manipulating existing algorithms. A promising idea I have involves winnowing the universe down to only those equities that have increased over 4% from previous day's close to current day's open.
In order to do this AND keep the universe small and not time out with "OnData," I need to call prev close and current open as indicators run through SelectionData, correct? Is there anyway to do this? I'd like to select for these gappers in the coarse filter if at all possible.
I've combined two of the BootCamp algos, but obviously I'm missing the mark. Any help would be appreciated.
Thanks!!
## EMA ALGO, modified
class EMAMomentumUniverse(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 1, 7)
self.SetEndDate(2019, 1, 9)
self.SetCash(100000)
self.UniverseSettings.Resolution = Resolution.Minute
self.AddUniverse(self.CoarseSelectionFunction)
#1. Create our dictionary and save it to self.averages
self.averages = { }
def CoarseSelectionFunction(self, universe):
selected = []
universe = sorted(universe, key=lambda c: c.DollarVolume, reverse=True)
universe = [c for c in universe if c.Price > 1][:100]
# Create loop to use all the coarse data
for coarse in universe:
symbol = coarse.Symbol
if symbol not in self.averages:
# 1. Call history to get an array of 1 days of history data
history = self.History(symbol, 1, Resolution.Daily)
#2. Adjust SelectionData to pass in the history result
self.averages[symbol] = SelectionData() #(history)
self.averages[symbol].update(self.Time, coarse.AdjustedPrice)
if self.averages[symbol].is_ready() and self.percentgap > .04:
selected.append(symbol)
return selected[:20]
def OnSecuritiesChanged(self, changes):
for security in changes.RemovedSecurities:
self.Liquidate(security.Symbol)
for security in changes.AddedSecurities:
self.SetHoldings(security.Symbol, 0.10)
class SelectionData(object, data):
def __init__(self):
#self.slow = ExponentialMovingAverage(200)
#self.fast = ExponentialMovingAverage(50)
#HOHOHOHOHOHOHOHOHOHOHOHO
#VARIABLE IS EQUAL TO OPEN/CLOSE - 1 ...AKA THE GAP
self.openz = data[symbol].Open
self.closez = data[symbol].Close
self.percentgap = self.openz / self.closez -1
def is_ready(self):
return self.percentgap.IsReady
Thanks!!
M Cochran
I've figured this out for myself.
How do I friggin delete old and sort of obtuse questions of mine???
.ekz.
Great that you figured it out! Please consider sharing how you did this with the community.
Jared Broad
>Please consider sharing how you did this with the community.
100% MC - Please share for others following you! =)
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.
M Cochran
Well, I figured out how to pull previous close and opening price I believe. That is outlined here:
https://www.quantconnect.com/forum/discussion/1707/getting-previous-day-close-when-i-m-subscribed-to-higher-resolution-data/p1That seemed to do the trick.
...But as it turns out there's no way to use course data and fine data to search by certain criteria in the morning (e.g. gappers). Nor is there any way to combine course/fine filters with the scheduleduniverse selector, right? I just want to be clear on what I can and cannot do..
Thanks!
Derek Melchin
Hi M Cochran,
To scan for gappers, we would have to schedule coarse/fine selection after the open, then perform a history request to get the opening price. We are working on allowing users to schedule coarse/fine selection. Subscribe for updates on our progress here.
Best,
Derek Melchin
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.
M Cochran
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!