I don't know how to fix this error: "During the algorithm initialization, the following exception has occurred: Unable to locate exchange hours for Future-cmeglobex-BRRV18" The message doesn't tell me which statement causes it, but I was able to nail that down by commenting out various statements.
Have I done something wrong with the symbol, or do I just not understand how to properly use this API or what?
public class BasicTemplateAlgorithm : QCAlgorithm
{
private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
private Symbol _bct = QuantConnect.Symbol.Create("BRRV18", SecurityType.Future, Market.Globex);
..
}
public override void Initialize()
{
SetStartDate(2018, 1, 07); //Set Start Date
SetEndDate(2018, 10, 11); //Set End Date
SetCash(100000); //Set Strategy Cash
AddEquity("SPY", Resolution.Minute);
AddFutureContract(_bct,Resolution.Hour,true); //<--this guy causes the error
}
Jing Wu
Before requesting the future contract data with AddFutureContract(), you should first fetch a list of available future contracts with
var futureChains = FutureChainProvider.GetFutureContractList(symbol, Time);
Then you can choose the contract to trade from this future chains.
This symbol argument here should be the symbol object. For example S&P500 Mini futures, you can get the symbol object with
public Symbol SP500 = QuantConnect.Symbol.Create("ES", SecurityType.Future, Market.USA);
You can search for the available future string tickers like "ES" in data explorer. "BRRV18" is not an available future ticker to use. Are you looking for US dollar / Brazilian Real(USD/BRL) cash Settle Future? The ticker should be "BRL" for US dollar / Brazilian Real(USD/BRL) cash Settle Future.
Please see the attached algorithm
Instead of using the future chain provider, you can also request the futures data with AddFuture(symbol). You can find this example on Github.
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.
Franklin Antonio
I don't understand what I am supposed to do. The "data explorer" is only helpful if you already know the symbol. When I type BRR it doesn't find.
I was trying for the CME bitcoin futures contract.
I also don't understand what Market.USA means exactly. I used Market.Globex, because this contract trades on Globex. What is the distinction?
Is this stuff explained anywhere?
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.
Franklin Antonio
There is so much here that is unclear to me. When you write
public Symbol SP500 = QuantConnect.Symbol.Create("ES", SecurityType.Future, Market.USA);
I don't understand what is going on because ES is NOT the symbol for a futures contract. It is the symbol BASE for a family of futures contracts. So are you saying I have to start with the symbol base and then go from there? If so, what do I do to specify the specific futures contract?
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.
Franklin Antonio
I finally found some words in the API docs explaining that you default to the near contract. One down... many to go.
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.
Jing Wu
The string ticker here represents a family of future contracts. They are the standardized symbol ticker assigned by the exchange. You can search for them on this website.
We also mapped some of the Futures symbols in this class (as there are thousands of symbols, these are only commonly used futures):
https://github.com/QuantConnect/Lean/blob/master/Common/Securities/Future/Futures.cs
Unlike equity, the futures contract is an agreement that has the expiration. After the contract expires, it is no longer traded in the market. Therefore, you need to add the futures with the generalized string ticker and select the contract available to trade in the market at the current time. For example, you want to trade SP500 Emini futures, you get a list of all the available contract with FutureChainProvider.GetFutureContractList(SP500, Time) and then select the contract from this list. To find the specific contract, you need to use the expiration date(see the attached algorithm) or the specific symbol.
var contracts = (from symbol in futureChains
where symbol.Value == "StringTickerOfSpecificFutureContract"
select symbol);
However, using the contract string ticker to filter the contract might give zero contract when this contract expires and not available in the market.
The string ticker of Bitcoin futures is "BTC". We use Market.USA for all futures traded in the United States. There's no need to specify the exchange when adding the futures.
public Symbol btc = QuantConnect.Symbol.Create("BTC", SecurityType.Future, Market.USA);
// get a list of all available future contracts at the current time
var futureChains = FutureChainProvider.GetFutureContractList(btc, Time);
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.
Thomas O'Reilly
Hello Jing Wu!
I'd like to make use of the FutureChainProvider, but I'm struggling to get it setup. My algorithm is in Python, but I have no issue translating from C# code, if you prefer to code in C#.
After many failed attempts of translating your above code into python to use the FutureChainProvider, I cloned your algorithm to see it run in C#. To my surprise, it seems that the code provided always gets a "0" back for futureChains, and the contracts list is always blank.
I've tried to find what is going wrong, but it seems that according to the documentation found here:
https://www.quantconnect.com/lean/documentation/topic24990.html#
the code should be getting some future contracts. Has something changed since this was written? Or am I missing something?
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.
Derek Melchin
Hi Thomas,
ES is trade on CME and we have changed the Market from USA to CME since this thread was created. Therefore to resolve this, we just need to change
public Symbol SP500 = QuantConnect.Symbol.Create("ES", SecurityType.Future, Market.USA);
to
public Symbol SP500 = QuantConnect.Symbol.Create("ES", SecurityType.Future, Market.CME);
See the attache backtest and plot for reference.
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.
Thomas O'Reilly
Good to know! Thank 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.
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!