Hello all,
Iam having trouble getting my futures algo to work. I get an error with my add data line and cant figure out how to resolve it. I've removed everything not pertinent, however I believe the problem is within these lines. Iam still rather new to coding and QC. Any help or suggestions would be greatly appreciated!!
using System;
using System.Linq;
using QuantConnect.Indicators;
using QuantConnect.Models;
namespace QuantConnect.Algorithm.Examples
{
public class EMACross : QCAlgorithm
{
private string symbol2 = "CHRIS/CME_CL1";
private string symbol = "SCF/CME_CL1_ON";
string _crude = "SCF/CME_CL1_ON";
private ExponentialMovingAverage fast;
private ExponentialMovingAverage slow;
public override void Initialize()
{
// backtest span
SetStartDate(2014,07,01);
SetEndDate(2016,01,13);
// starting cashish
SetCash(20000);
// add Symbol data
AddData
Michael Handschuh
Check out the QCU How do I import futures data. I've attached it here for your convenience.
Stephen
Michael, I'm having trouble with this as well. I cloned the example for importing futures data and it works no problem. But when I add my position execution logic into the onData I'm getting the following runtime: "Runtime Error: Received type of Quandl but expected QuandlFuture Parameter name: data (Open Stacktrace)" Any ideas? Does this have to do with the QuandlFuture class? I'm not sure exactly what this class is doing to be honest. Is it just selecting the close price column? Best, SC
Jared Broad
Hi @SC - I just fixed a bug in its implementation, please see the attached project which uses the Slice event handler.
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.
Stephen
Ok - I will check it out. Thank you once again! Best, SC
Michael Handschuh
Hey Stephen! I looked into this and it looks like ya found a bug! If you switch to the latest master it should be working fine now!
Stephen
Looks like it's working perfectly now. Thanks again guys! Best, SC
Stephen
Another quick question - how can I call the Future's price? For securities I would do something like "Securities[Symbol].Price" or "Securities[Symbol].Close" I thought it would just be "QuandlFuture[_crude].Price" but that doesn't seem to be working for me. Best, SC
Stephen Oehler
Stephen, I could be wrong but I believe it is ".Value"
Stephen
Thanks Stephen - but .Value didn't work. I'm thinking it might be just "data.Price" The reason I was asking this is because I am getting the following Runtime error: "Please register to receive data for symbol ' ' using the AddSecurity() function." I noticed I still had "var currPrice = Securities[Symbol].Price;" in my onData but the Futures example didn't make use of the AddSecurity() method in the Initialize. So I've changed this to data.Price and there is no compile error at least anymore. But this same runtime error is still present. Do I need to use the AddSecurity() in my Initialize still for futures?
Stephen Oehler
Ah sorry about that; you're right, it would default to whatever you set the value column to be (see the QCU Michael posted above, where in the bottom of the code he sets the custom column value to be 'Settle'). As for the AddSecurity bit, you should be able to register by AddData(), as in the Initialize function in Michael's code above.
Stephen
I have "AddData(_crude, Resolution.Daily);" in my Initialize right now. I thought that would do the trick, which is why I'm confused on the "Please register to receive data for symbol ' ' using the AddSecurity() function." runtime and thought it had to so something with how I was updating my current price in onData.
Stephen
Sorry - I have "AddData(_crude, Resolution.Daily);" in initialize
Stephen
I'm not sure why - but it keeps taking out the QuandlFuture in that AddData line. But I have the line from the example verbatim
Stephen Oehler
Yeah that's an artifact of this forum (it always tries to match with a > or just deletes it entirely), but I get what you're saying.
Stephen Oehler
LOL see?! It did it with me too!
Travis Teichelmann
@Stephen Cialdea - I was looking through your post and found the answer to your question. If you check out my code and If you run a backtest you'll see the price in the logs for the futures symbol that you're working with. Hope this helps!
Amulya Jitendra Agarwal
Where is the documentation for this, like, how to get the price etc. ?
Rahul Chowdhury
Hey Amulya,
You learn about importing and using futures data in the data library documentation and research documentation. I also recommend completing the Buy & Hold Futures Bootcamp. It is a fantastic way to learn more about how futures work in Lean.
Best
Rahul
Timothy Comisky
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!