Back

Example tick futures.

is there any exmaple of how to use tick futures data? im trying this but its not working:

class UncoupledMultidimensionalSplitter(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2017, 3, 1) # Set Start Date
self.SetEndDate(2017,3,2) #Set End Date
self.SetCash(50000)

# self.AddEquity("SPY", Resolution.Minute)
self.AddFuture("ES", Resolution.Tick)

def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data
'''
current = data['ES'][-1]

self.Log(f"Last price: {data['ES'][-1].LastPrice}")
self.Log(f"Last price: {data['ES'][-1].Quantity}")

 

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.


Hi Lorrrr,

Please use self.AddFuture(Futures.Indices.SP500EMini, Resolution.Tick) rather than self.AddFuture("ES", Resolution.Tick) to add the data of E-mini S&P 500 futures. Also, please use the following code snippet to obtain the LastPrice attribute of FutureContract.

# Explore the future contract chain
def OnData(self, slice):
for chain in slice.FutureChains.Values:
contracts = chain.Contracts
for contract in contracts:
pass

I've attached a backtest about how to add future data and obtain the LastPrice of future contracts. Hope it helps!

Please note that saving price locally would be against the data usage policy in QC. 

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.


thanks.

i saw that the data explorer uses ES and not Futures.Indices.SP500EMini.

https://www.quantconnect.com/data/tree/future/usa/tick/es

is there a place in which i can find all the other futures contract available?

to plot the price i caan just use plot ("price", contract[0].LastPrice) ?

0

Hi Lorrrr,

"ES" works fine - Futures.Indices.SP500EMini gets translated into the "ES" string in the engine anyway. As such, you can find all future contracts available in the data explorer, as you expected.

To plot, you can indeed do what you suggested. Assuming you're inside the for chain in data.FutureChains: scope, you can do this:

self.Plot("Price", contracts[0].LastPrice)

 

0

thanks, i hope this will be my last question. im trying to add an indicator but it always return 0:

class DynamicCalibratedContainmentField(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2017, 3, 1) # Set Start Date
self.SetEndDate(2017,3,25) #Set End Date
self.SetCash(50000)

futureES = self.AddFuture("ES", Resolution.Minute)

self.ESSMA = self.SMA(futureES.Symbol, 2)

def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data
'''
ESSMA = self.ESSMA.Current.Value
self.Log(f" ESMA: {str(ESSMA)}")

 

0

Hi Lorrrr,

As we've discussed before, using futures is a little more complicated since you actually have to select a particular contract. This also goes for when you set up an indicator: you can't set up an indicator onto the "future" itself, you have to actually select a contract first.

Here's one way to do it - might not be the most efficient and clean way but it works.

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