Back

No futures history

I cloned existing template to test future history, I commented some of unimportan part of the code and add a log in OnSecuritiesChanged. As I understand history for selected future should be loged but it looks like there is no history. I tried some other things and I didn't get any history. 

Update Backtest








Hi Borut,

The available resolution for futures are tick, second and minute. Daily is not available.

https://www.quantconnect.com/docs/algorithm-reference/asset-class-specifics#Asset-Class-Specifics-Futures
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.


Thank you for the answer. If I change now to Resolution.Minute it works but when I try to do it in onData event, I still don't get any history data. 

First I tried like this:

dfh = self.History(self.futureSymbol, 24, Resolution.Minute)

and then I tried like this:

chain = slice.FuturesChains[self.futureSymbol]
underlying = chain.Underlying
contracts = chain.Contracts.Value
for contract in contracts:
      dfh = self.History(contract.Symbol, 24, Resolution.Minute)
      self.Log(str(len(dfh)))

In the second case I got error: TypeError : unindexable object in believe in first line.

The code was copied for your documentaiton, there is still some C# code in python examples.

0

slice.FutureChains is a FuturesChains class instead of a python dictionary. You can not use symbol index here. 

# get a list of contracts
for chain in slice.FutureChains:
     contracts = [i for i in chain.Value]
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.


I finally figured out how history for future works. The proper code is here (you have to use Values instead of Value and 3th value in index (not 2nd or 1st) represents datetime of history element)

for chain in slice.FuturesChains.Values:
            contracts = chain.Contracts.Values
            #contract = sorted(contracts, key = lambda x: x.Expiry, reverse=True)[0]  #current contract
            for contract in contracts:
                history = self.History(contract.Symbol, 100, Resolution.Minute)
                self.Log(contract.Symbol)
                for i in range(len(history)):
                    self.Log("History: " + str(history.iloc[i].name[1])
                        + ": " + str(history.iloc[i].name[2].strftime("%m/%d/%Y %I:%M:%S %p"))
                        + " > " + str(history.iloc[i]['close']))

 

I have still one question. Contract is somehow a qutoebar so I can get bid, ask last price, Can I get in onData event also a tradebar for futures (high, low, close price) in minute resolution?

0

The difference between QuoteBar and TradeBar is the bid/ask. You could get the Open, High, Low and Close for both bid and ask price.

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.


I still don't understand how to get high and low price for minute candle in onData event for Futures. Do you have an example?

0

So, this is not possible then?

0

these example shows some properties of a tradebar.

Line 180

https://github.com/QuantConnect/Lean/blob/6edd64919a8f7479c8e6bc1c737f2b30200428cf/Algorithm.Python/IndicatorSuiteAlgorithm.py

also check some other examples in the above library

https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/FuturesMomentumAlgorithm.pyhttps://github.com/QuantConnect/Lean/tree/master/Algorithm.Python
0

I know properties of tradebar, I don't know how to get tradebar for futures. I already cheked all this examples before and no one uses tradebar for futures. I wouldn't ask you this question. So again how can I get tradebar (high, low prices) for futures (example please) in onData event for minute bar? I would appreciate if you answer my question.

0

Hi Borut,

You could use

# open price
self.Securites[symbol].Open 
# low price
self.Securites[symbol].Low 

Same thing for the closing price and high price. The symbol here is a futures contract symbol object.

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.


Thank you, This I was looking for. Just additional comment for symbol you have to use contract.Symbol from the code above. 

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