Hi all! I'm pretty new to QuantConnect and getting a little confused! I want to use an indicator in my Universe Selection. Specifically the standard deviation of the price, over the last 300 minutes.
My universe resolution is in minutes.
I am creating the indicator in a SelectionData class:
class SelectionData(object):
def __init__(self, symbol, period):
self.symbol = symbol
self.stddev = StandardDeviation(period)
def update(self, time, price):
self.stddev.Update()
and have two questions:
1) How do I know what to pass into the Update() method? I the documentation here:
https://www.quantconnect.com/docs/algorithm-reference/indicators#indicator-standarddeviationI can't see what the Update method needs.
2) Will my universe selection have to run 300 times for this indicator to calculate, or, will it calculate the second time Universe Selection runs (1 day after start?)
Thanks for any help!
Christian Piene Gundersen
When you create create an indicator by using its constructor, as you do, you need to manually feed it with historical data ("warm it up"). This is described here in the documentation under the heading "History Request Warm-Up": https://www.quantconnect.com/docs/algorithm-reference/indicators#Indicators-Initializing-Indicators
The parameters for the Update method (and all other methods) are found in the LEAN documentation: https://www.quantconnect.com/lean/docs#topic100.html. In your case, search for StandardDeviation and look at the Update method.
I also recommend taking the Boot Camp "200-50 EMA Momentum Universe" lesson. It will teach you how to manually warm up indicators and use them in universe selections.
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.
JumboFlan
Thanks Christian! I had seen the history requests, but as I was only looking for minutes of data, was happy to have the first day of the backtest have no universe selection occur, and the data be available the second day if that would work - but I guess I need the history request warm up. Thanks for the links to lean docs, I hadn't been through those yet.
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.
JumboFlan
Ok - I've set up my history request, and it is returning securities from day 1, so I think it is working (somewhat). My next question: I have put the history request for the security in the __init__ of SelectionData, so it is only called when the SelectionData class is initialised for that symbol, and not every time the SelectionData is updated. But thinking about it, this is the wrong approach for me in this case? Every day I need to request the history for every symbol that Update() gets called because I want the last 300 minutes?
(If I was using a daily resolution, and a moving average, it might be fine to request history just once becuase each day Update() would only need to be called once to give all new data to the indicator?)
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.
Shile Wen
Hi Brian,
If we are talking about Coarse/Fine Universe Selection, then the universe function is called daily, so a minute resolution indicator won't work. I'd suggest instead to put the warm up logic or SymbolData creation and the indicator logic inside OnSecuritiesChanged and update the indicators as well as filter by indicators inside OnData.
Best,
Shile Wen
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.
Ruming Jiang
I had a similar question with JumboFlan, the search took me here. The link Christian mentioned above (https://www.quantconnect.com/lean/docs#topic100.html.) is no longer available. Where can I find it now?
A more general question is how to find right parameters for a method and right attributes/methods of an object. Copying examples works sometimes but not always. Is there any tool to find the definition of them?
Thanks
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.
Varad Kabade
Hi Ruming Jiang,
The link Christian mentioned above (https://www.quantconnect.com/lean/docs#topic100.html.) is no longer available. Where can I find it now?
Refer to the following link for complete information about the StandardDeviation indicator.
A more general question is how to find right parameters for a method and right attributes/methods of an object. Copying examples works sometimes but not always. Is there any tool to find the definition of them?
You can refer to this link to get information about different methods and there parameters. Also, when developing code at QC IDE, we can refer to different classes and methods using the API tab on the right side of the screen.
Best,
Varad Kabade
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.
Ruming Jiang
Hi Varad,
Thanks for the comment. I landed on same link by google search. It would have saved me some time if I saw your comment earlier or the link is updated in documentation.
The other similar question regarding references. The link to option security object on this page (Tutorials - API Tutorials - Using Options in QuantConnect - QuantConnect.com) seems to be missing as well. Google found the same link but the address was changed. I wasn't able to find it through the link above either.
Where to find reference to it? Thanks
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.
Varad Kabade
Hi Ruming,
To see the tutorial on using options in QC, refer to this link. To access all the tutorials, follow the following link.
Best,
Varad Kabade
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.
Spacetime
AlMoJo ,
Also, if you would like to explore more CBOE data sets, then you can use the Nasdaq Data Link provided below.
Correction in my last post: meant to say CBOE and not Quandl (Quandl was acquired by Nasdaq)
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.
Spacetime
AlMoJo , Just posting our QC CBOE Datasets link below for your reference if you need it.
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.
Vladimir
Spacetime,
There are only 6 trades for SHV in your version of the code.
Can you try changing in the code the VIX and VXV data retrieval in a way like in the attached sample.
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.
Spacetime
Hi Vladimir,
Hmm… not entirely sure why there were only 6 trades executed.
The above backtest which I have attached was taking a “bit” to complete for me and I was engaged with other work, so I ran the above model (shaerd by pangyuteng) with a start date of self.SetStartDate(2020, 11, 1) just to speed up things.
Hmm… I have extended the date range to start from self.SetStartDate(2019, 1, 1) and it does not have too many trades either. (backtest attached)
If you have noticed from the above example shared by pangyuteng , then it does not trade that often either. [ self.SetStartDate(2019, 1, 1) ]
But, the fixes which I have shared above does work as the error which was being received by AlMoJo is no longer occurring.
Hmm… maybe someone else might have a better idea on this, but I will try to look into this further. Hmm… maybe the LSTM configuration needs to be looked into or the volatility data resolution and other resolutions needs to be changed to minute time slice if possible.
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.
Vladimir
Spacetime,
I backtested cloned pangyuteng algorithm with only changes in my_custom_data
url_vix = "http://cache.quantconnect.com/alternative/cboe/vix.csv"
url_vxv = "http://cache.quantconnect.com/alternative/cboe/vix3m.csv"
It generated 13 SPY-SHY trades and metrics as your last one, but the performance is not comparable to pangyuteng's results.
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.
Spacetime
Vladimir,
Hmm… If you want to compare it with pangyuteng's results, then you have to provide an end date of self.SetEndDate(2020, 1, 1) because pangyuteng's model ends around that time. Please note, pangyuteng's post is time stamped somewhere in December 2019.
Try to run it with end date parameter and check to see if performance is comparable.
I have attached a backtest run starting from self.SetStartDate(2019, 1, 1) and ending at self.SetEndDate(2020, 1, 1) and it only traded once.
Hmm…
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.
Vladimir
Spacetime,
I definitely like the metrics from your last backtest, but my attempts to reproduce them for some reason were unsuccessful.
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.
AlMoJo
Hello everybody,
Pangyuteng this is an amazing result. Jack Simonson I also think technical indicators would help a lot.
I tested Pangyuteng version on the 2022 crash and it is not so good at dodging it. I taught maybe going hourly timeframe instead of daily could help even if I know that trading more frequently is not really good.
Anyone has an idea on how to change the timeframe? I tried to pass all the .Daily to .Hourly but obviously it wasn't that simple.
Kind Regards
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.
Varad Kabade
Hi AlMoJo,
To change the timeframe of the entire algorithm we recommend adding the following to the Initialize method:
Note that the algorithm uses higher frequency bars to create lower-frequency bars. Therefore to use indicators or consolidators at the hourly resolution we need to have the universe at the minute, seconds, or hourly resolution.
Best,
Varad Kabade
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.
Will Berger INVESTOR
Hey Guys and Sherry,
Thanks for this incredible thread. So many interesting ideas!
Will
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!