Hi everyone, Got a quick question: The OnData() override that is required for importing Quandl data has me a bit confused. I have an algo that uses the standard "Tradebar" OnData method. This is invoked on a daily resolution, and uses standard pricing data from QC's dataset. On top of this, I'd like to query that-day's price for another asset through Quandl data. I'd then like to compare the two. I'd very much appreciate a brief explanation on how that might be accomplished. Currently I have what looks like two OnData methods, and each fire upon reception of data from the two disparate streams of information. Is there an intelligent way for me to put these two data sources together so that I can query both in the same line of logic? I feel like I'm not thinking this through correctly. :-) Thanks! -Stephen
JP B
Your question was already asked once: How to refer to multiple Quandl symbols? Also see this question. If you want to create some sort of inverse strategy based on Quandl data of VIX, I've created a small algorithm to show you how you can do that:
Michael Handschuh
Stephen, you may also find the OnData(Slice data) method useful. The Slice is an object designed to give your algorithm access to all the data for a given 'time-slice' and includes data from all resolutions and even custom data.
Stephen Oehler
This is fantastic, guys. Thanks :-)
Stephen Oehler
Michael, I'd like to use this slice method, and I've checked out the threads that JPB has shown, as well as perused through the QCU examples. I'm still thoroughly confused as to when the data slice gets called. Is it like the following example, where tradebars are daily? (Warmup) -OnData(Slice) is called: slice of all available days in the quandl csv file are permanently preloaded for all time. (Day 1) -OnData(Tradebar) is called: tradebar is passed in (Day 2) -OnData(Tradebar) is called: tradebar is passed in
Stephen Oehler
I guess I should amend my question: Is OnData(slice) or OnData(quandl) always called before OnData(tradebar) to ensure you have everything you need before conducting your logic and placing your order in the tradebar method?
JP B
Stephen Oehler
Oh, that's perfect then. Slice is exactly what I need. I'll do some digging to figure out how to use it properly.
Stephen Oehler
Ah, this is exactly what I was looking for. For anyone else who comes here looking for a way to combine custom and standard data sources, JPB,MichaelH, and Jianwei have already discussed this here: https://www.quantconnect.com/forum/discussion/comment/2442#Comment_2442 Many thanks.
Stephen Oehler
Man I'm having a hard time wrapping my head around the Slice concept. Ok so my goal is to put together an algorithm that will do the following: 1.) Import Quandl data 2.) Merge Quandl data with standard data (SPY) through the use of composable indicators 3.) Assess the composed indicator and take action once every day I've put together a brief test algo that uses Tadas Talaikis (thanks!) consolidator code to update a standard deviation indicator in a different way. My intent is to test out points #1 and #2 on my list above, but my slice is returning nothing. The problem seems to be originating from line 120 in Main.cs. The error it returns is:
Runtime Error: 'SPY' wasn't found in the TradeBars object, likely because there was no-data at this moment in time and it wasn't possible to fillforward historical data. Please check the data exists before accessing it with data.ContainsKey("SPY") (Open Stacktrace)
What I'm doing is passing in the Slice.Bars property as TradeBars to the method, but I don't think it contains anything. Any help would be greatly appreciated. Thanks!Michael Handschuh
TradeBars is a dictionary object keyed by symbol. The error you're getting is because the current slice doesn't have any SPY data. You should first check to verify that the key exists:
if (data.ContainsKey("SPY")) { // do something with data["SPY"] }
Stephen Oehler
Hi Michael, Thanks for the reply. I've applied the check, and this time it doesn't report an error, but it still returns nothing. Or more specifically, the UpdateLNStd() method internal logic is being skipped because SPY is simply not in the data slice. Am I missing some particular step in registering the SPY data with the slice?
Stephen Oehler
Ah wait I apologize. I was just being stupid with my IsEvaluationTime() method. I think I set my hour to a time that is not achievable on the servers somehow. It's operating as expected :-) Thanks for your help Michael!
Stephen Oehler
Ugh. I feel like I'm still not getting a core concept here. Although, I feel like I've made it a bit further, I still feel like I'm completely screwing up how this is supposed to work. Attached is my project as-is. Essentially, I'm trying a Trading-the-Odds VRP strategy, where the general gist of is the following: When EMA5(vix - (astd)) > 1, you go long XIV. Else, you long VXX. Pretty simple. In the equation above, "vix" is the 30 day constant maturity price of Vix, which is achieved with the quandl code I have installed in the algo. The variable "astd" is the annualized standard deviation of SPY of the past two days, which is calculated as
standard deviation((LN(todaysclose/yesterdaysclose), LN(yesterdaysclose/twodaysagoclose)) * 100 * sqrt(252))
I've broken it down to the following: 1.) Custom indicator to calculate the two day standard deviation of the messy equation above. It uses a custom consolidator. 2.) Standard SMA(1 day) indicator of the VIX contract price from quandl to indicate today's closing price of VIX 30 day contract 3.) Custom indicator to calculate the five day exponential moving average of the difference of SMA(1) and the astd. So, all told, this project uses: 1.) A custom quandl data source with custom column name 2.) Two custom indicators (I'm not even sure if I'm using that correctly) 3.) Two different data types: standard SPY and QuandlVixContract (of base type Quandl) I think I've just about incorporated every complicated aspect of the LEAN engine I possibly can! Maybe I bit off more than I could chew? That said, if I get this running, I'd be happy to explain it and share it with the community. The problem I'm encountering is that my UpdateEMADiff(data) method is putting up an error that says it is expecting a data type "QuandlVixContract" but is instead receiving "Quandl". Not sure what that means. On top of that, I don't really know how to access the data from Quandl and use it properly. I've put comments in the UpdateEMADiff(data) method for what I know I WANT to do, but don't know how to do it. Any help is appreciated, and free points for those who do. Thanks everyone.Jared Broad
Try this one Stephen -- I'm not sure of the signal but following the logs and it looks like its doing what is expected. I err on the side of simplicity when implementing this sort of stuff. You don't need to use indicators for most things.
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.
JP B
@Jared I was thinking the same thing: just calculating the input on every OnData() event and update the indicator with it. Nice and clean code.
Stephen Oehler
Wow, I am in awe of how you were able to condense the algorithm into such a simple code! Thanks very much, Jared. This is amazing. So I made one change: I changed the standard SPY data to GSPC (S&P 500 index) quandl data, because apparently I misread the strategy. Attached is the updated script. We're almost there! However I noticed that the closing price for GSPC data as of "today" is actually from the day before. I looked at the strategy and it looks like this strat is ideally supposed to run after the close when all the data from that day has been updated. So, for example, at 8pm that night, you would calculate the standard deviation as STD[(closing price today / closing price yesterday), (closing price yesterday / closing price two days ago)]. Instead, the algo currently is doing STD[(closing price yesterday / closing price two days ago), (closing price two days ago / closing price three days ago)]. Same for the vix data (we actually need to be querying closing vix price of that day). Is there a way to force the slice to wait until a certain time of the day, when all the data has been updated on Quandl for the day? Also to JP: I wanted to thank you again for the Quandl datasource for the constant maturity contract price for VIX. I am a bit puzzled as to its values, however, and was wondering if you might know what is going on? The datasource for SPDJ/SPVIXSTR is as follows: https://www.quandl.com/data/SPDJ/SPVIXSTR-S-P-500-VIX-Short-Term-Futures-Index-Index The values for these contracts seem to be in the high hundreds, when the linearly interpolated contracts should be in the range of VIX as it currently is today (~20). When I read the datasource's summary, it sounds like it should be outputting the linearly interpolated values between month1 and month2, but that clearly isn't the case. Have you worked with this source before? Thanks again guys!!
Travis Teichelmann
That's a pretty cool strategy. I went through this whole thread and don't really understand very much of it, but still, thank you for sharing Stephen.
Stephen Oehler
Stephen Oehler
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!