Options and Futures Trading on QuantConnect

We are very excited to announce the beta launch of options and futures trading on QuantConnect! Through the open-source platform LEAN, algorithmic trading has never been so accessible to investors.

The new asset classes tie into our existing offering of Equities, FOREX and CFD products bringing us to a total of five asset classes. We can now simultaneously trade multiple asset classes when used with a supporting brokerage. You write strategies in C#, Python and F#.

Options and futures are highly requested features from the community so we are happy to be shipping this feature. Like our other asset classes, all data is event driven manner to avoid look ahead bias.

Starting today you can also live trade your options and futures strategies on Interactive Brokers! (An accompanying options data subscription from Interactive Brokers required). If you’re an options/futures wizz get in touch!

Data and Period Available

Option data is available at minute resolution from January 2014-December 2016. Because of its sheer size we’re processing dates in reverse order backwards through time. When processing is complete the library will start January 2007. The data is survivorship bias free, and delivered as trades, quotes and open interest information. We cover all symbols in the OPRA feed. You can see a full example of an option algorithm in the BasicTemplateOptionsFilterUniverseAlgorithm.cs.

//Add Option Base 
var option = AddOption("SPY");

//Filter down to what we want.
option.SetFilter(universe => 
		from symbol in universe
		      .WeeklysOnly().Expiration(TimeSpan.Zero, TimeSpan.FromDays(10))
		where symbol.ID.OptionRight != OptionRight.Put
		select symbol);

// Search option chain:
if (slice.OptionChains.TryGetValue(OptionSymbol, out chain))
{
	// find the second call strike under market price expiring today
	var contract = (
		from optionContract in chain.OrderByDescending(x => x.Strike)
		where optionContract.Right == OptionRight.Call
		where optionContract.Expiry == Time.Date
		where optionContract.Strike < chain.Underlying.Price
		select optionContract
		).Skip(2).FirstOrDefault();

	if (contract != null)
	{
		MarketOrder(contract.Symbol, 1);
	}
}

Futures trading is available in tick, second and minute resolutions from January 2009 – December 2016. Our futures library covers all symbols from CME, NYMEX, CBOT and COMEX exchanges. You can see an example of a future algorithm in the BasicTemplateFutureAlgorithm.cs.

//Add Future Contract
var futureGold = AddFuture(Futures.Metals.Gold);

// What contracts do you want?
futureGold.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182)); 

// Search future chain for specific contracts to trade.
foreach(var chain in slice.FutureChains) 
{
	// find the front contract expiring no earlier than in 90 days
	var contract = (
		from futuresContract in chain.Value.OrderBy(x => x.Expiry)
		where futuresContract.Expiry > Time.Date.AddDays(90)
		select futuresContract
		).FirstOrDefault();

	// if found, trade it
	if (contract != null)
	{
		MarketOrder(contract.Symbol, 1);
	}
}

Options and futures trading also introduces the concept of QuoteBars to QuantConnect – a representation of the quote movements over time. QuoteBars have a Bid (OHLC) and Ask (OHLC) Bar. This allows us to better model spread for low volume assets such as option contracts. QuoteBars are limited to Options and Futures now, but will be extended to FX and CFD soon.

Data Provider

We’d like to give a special thank you to our data provider AlgoSeek. AlgoSeek shares the QuantConnect vision and has generously sponsored data for the QuantConnect community. You can download more data for LEAN from https://www.algoseek.com.

AlgoSeek is a leading provider of historical intraday US market data to banks, hedge funds, academia and individuals worldwide.

Avatar

By: Jared Broad

Founder & CEO

31.01.2017
img Back to Blog

Related Articles

algorithmic trading

New Machine Learning Package: MlFinLab

By: Jared Broad • 17.10.2022 algorithmic trading

Living Our Mission 🚀

By: Jared Broad • 20.09.2022 crowdfunding

Own a Part of QuantConnect

By: Jared Broad • 08.09.2022 algorithmic trading

Docs V2 Released

By: Jared Broad • 13.07.2022

New Low-Latency FIX Integration to Atreyu

By: Carey • 26.10.2021