Back

Having trouble importing Futures Data

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(symbol2, Resolution.Daily);

AccountValue=Portfolio.TotalPortfolioValue;
Log("Starting Account Value: " + AccountValue);

// EMA Settings
emaFast = x;
emaSlow = x;

// EMAS
fast = EMA(symbol, emaFast, Resolution.Daily);
slow = EMA(symbol, emaSlow, Resolution.Daily);

// tolerances
tolerance = 0.00024m;

// Set Warmup
int warmupPeriod = emaSlow;
var history = History("symbol2", warmupPeriod);
foreach (var tradeBar in history)
{
fast.Update(tradeBar.EndTime, tradeBar.Close);
slow.Update(tradeBar.EndTime, tradeBar.Close);
}
}
public void OnData(Quandl data)
{

Update Backtest








Check out the QCU How do I import futures data. I've attached it here for your convenience.

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.


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

0

Hi @SC - I just fixed a bug in its implementation, please see the attached project which uses the Slice event handler.

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.


Ok - I will check it out. Thank you once again!

Best,

SC

0

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!

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.


Looks like it's working perfectly now. Thanks again guys!

Best,

SC

0

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

0

Stephen, I could be wrong but I believe it is ".Value"

0

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?

0

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.

0

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.

0

Sorry - I have "AddData(_crude, Resolution.Daily);" in initialize

0

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

0

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.

0

LOL see?! It did it with me too!

0

@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!

0


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