Author: Jared Broad (page 1 of 5)

Collaborating in QuantConnect

Collaborating is a powerful feature of QuantConnect which allows up to 10 team members to work on a project at the same time. This can be useful when a team of specialists collaborates to build a great strategy.

The project creator holds the master copy of the project and can add team members and control the project permissions. To add a team member you just click the “Share” button in the project tab and search for the user by name or email address. Once the user is added you can control their permissions or remove them from the project.

Collaboration allows setting permissions on user by user level

Changes to shared projects are instantly shared between the collaborators and can be see by the colorful cursor representing the other team members.

Consolidating Data to Build Bars

Consolidators are used to combine data together from finer resolutions into larger ones. This can be useful for indicators with specific data requirements or to perform long term analysis in conjunction with short term signals.

Consolidators should be constructed and setup in your Initialize() method; this ensures they are only initialized once. There are three key steps to create and register a consolidator:

  1. Create the consolidator object.
  2. Bind an event handler to handle the new bars.
  3. Register it with the subscription manager to start receiving data.
public class ConsolidatorDemoAlgorithm : QCAlgorithm
{
	public override void Initialize() 
	{
		// backtest parameters
		SetStartDate(2016, 1, 1);         
		SetEndDate(DateTime.Now);
		
		// cash allocation
		SetCash(25000);
		
		//assets or universe selection
		AddEquity("SPY", Resolution.Minute);
		
		//create a consolidator object; for tradebars; for a timespan of 30 minutes
		var thirtyMinutes = new TradeBarConsolidator(TimeSpan.FromMinutes(30));

		//bind event handler to data consolidated event.
		thirtyMinutes.DataConsolidated += OnHalfHour;
		
		//register the consolidator for data.
		SubscriptionManager.AddConsolidator("SPY", thirtyMinutes);
	}
	
	//event handler for data!
	public void OnHalfHour(object sender, TradeBar bar) {
		Debug(Time.ToString("u") + " " + bar);
	}
	
	public override void OnData(Slice data) 
	{ }
}

The LEAN API also has other consolidator types to handle working with Ticks and RenkoBars:

// From tick data sources            
var tickConsolidator = new TickConsolidator(TimeSpan.FromMinutes(30)); 

//from renko bars
var renkoConsolidator = new RenkoConsolidator(TimeSpan.FromMinutes(30)); 

There are two key points to remember:

  1. Request a smaller resolution than what you want to produce.
  2. In backtesting we only know the bar is ready on the next data point; so it may appear like daily bars are triggered at odd times. In live trading they are scanned to be triggered every second at a minimum.

The raw data of QuantConnect is provided in Tick, Minute, Second, Hour or Daily bars. Using these building blocks you can combine data together to get any other resolution of data required.

Introducing The Co-Pilot: Your Coding Companion

We’re happy to announce the release of the Co-Pilot; a rich automated documentation generator built to give you relevant hints while you’re building your strategy. With deep API’s it is impossible to memorize all the methods available; and time consuming to constantly search the documentation. As a coding companion, the co-pilot can inspect the types you’re working on and provide the properties that are available.

The methods of the API are shown by the tables of code blocks, and detailed properties of the working variables are also available. We generate documentation from the reference text but also from the code API. These different documentation types are noted by the icons next to the results.

There are multiple documentation result types; text and code results.

How do I use the API File Provider?

Ensuring a high data quality is one of the hardest parts of setting reliable backtesting. There are many challenges to ensuring your data is in the right format, free of errors or omissions and historically accurate. We’ve tried to address this for you by opening the LEAN Data Library and letting you download our data. LEAN data is organized into millions of tiny files which can be difficult to put into place manually; but using the API File Provider we provide a way for you to automatically install this into your LEAN project.

Currently we provide forex and cfd data for each of the major vendors we support in tick, second, minute, hour and daily resolution. To request data; go to your data library and specify what you’d like to download.

Data library collection for FXCM EURUSD data

Each data file has a unique URL to download thedata for the day which will get a LEAN formatted CSV zip. By using the API File Downloader we check if you have the filein your data-folder; and if not we attempt to download it from the API. This assumes you have already added the data to your repository through the web interface.

This requires 2 key changes to the config.json file in the QuantConnect.Lean.Launcher Project:

  1. Insert your job-user-id and api-access-token into the relevant config fields. You can find these on your Account page.
  2. Update the data-provider configuration to refer to the APIDataProvider class. This is called QuantConnect.Lean.Engine.DataFeeds.ApiDataProvider.

Check out the video below where we guide you step by step through how to use the API Data Provider.

Free Streaming Live Data with IEX – LEAN Release Notes v2.3.0.3

This releaseadds the IEXDataQueueHandler allowing LEAN users to stream free US equity trades to their strategy; along with numerous bug fixes to the OANDA and FXCM brokerage implementations. Additional regression algorithms were added to automate testing of daily data algorithms. The Interactive Brokersconnection logic was also made more intelligent to fail quickly when thereis an existing TWS connection open.There were no breaking changes in regression tests or the API of LEAN.

Download this release from GitHub.

Features

  • Added IEX IDataQueueHandler for a free live US equity datafeed.
  • Added DailyBasicTemplate regression test algorithm.
  • Dramatically speed up Interactive Brokers connection speed.
  • Scan IBController logs for connection failures and handle them in LEAN.
  • Added FilteredIdentity indicator to filter tick trades and quotes.
  • Created Lean.TryParsePath() to create symbols from a file path.
  • Added ApiFileProvider to download data directly from the API.
  • Upgrade Oanda HistoryProvider to return QuoteBars instead of TradeBars.

Bug Fixes

  • Fix duplicate sampling bug in daily data backtesting.
  • Remove time from daily sample points in backtesting.
  • Properly load existing short positions when launching Interactive Brokers algorithm.
  • Fix issue with indicators that require a quote subscription.
  • Check for valid symbols when getting OANDA or FXCM history request.
  • Ensure logs are only savedonce.

Notes

  • We upgraded LEAN to use JSON.NET v9.0.1. This library is used extensively through LEAN.

Thank you to the community contributors in this release buybackoff andJay-Jay-D!

About LEAN

LEAN aims to empower investors to invest with confidence by using cutting edge algorithmic trading technology. Through the power of open source we are building the world’s best algorithmic trading platform, capable of accurately modeling global markets to give you insight into your strategy. Your trading algorithms can be seamlessly deployed from backtesting into production with no changes or even moved between brokerages. The LEAN user community reaches over 29,000 quants from all over the world.

LEAN supports C#, F#, VB, Java and Python programming languages and can be used in Equity, Forex, CFD, Options and Futures markets. It currently supports live paper trading, or execution by Interactive Brokers, FXCM and Oanda Brokerage.

For more information join the LEAN Community on GitHub.

Generic Data Sourcing and Caching – Release Notes v2.3.0.2

This release adds a generic data sourcing feature along with abstraction of the data caching. This allows different configurations to be setup independent of physical files. In addition there were dozens ofbugs fixes in LEAN to improve its stability and consistency across backtesting and live trading. There were no breaking changes in regression tests or the API of LEAN.

Features

  • Added IDataProvider and IDataCacheProvider – a redesign of the bottom of the LEAN enumerator stack so the data sourcing and caching is pluggable. This helps track memory issues and abstract away the concept of data files.
  • Local desktop charting now supports custom charts.
  • Apply backtest control limits in backtest initialization.
  • Added handling for “INF” factor files where splits make adjusted pricing impossible.
  • Backtestingodd-hour scheduled events now behaves closerto live trading.
  • Added SystemDebug packet to distiguish between user debug and system debug messages.
  • Add start-date parameter to CoarseUniverseGenerator

Bug Fixes

  • Fixed issue double sampling and sampling when no data for daily data.
  • Fixed Linux log corruption from unicode characters.
  • Set IDataConsolidator period to fixing issueconsolidating ticks.
  • Changed GUI UserInterface project path to Debug from Release.
  • Fixed Forex and CFD assets not receiving ticks because they were added as tradedata.
  • Fixed issue where equity sampling timezone dependent on the host computer.
  • Fixed different timezones between custom and equity charts.
  • Fixed bug in finefundamental data selection not annoucingselected securities if they already existed.
  • Removed APIDataProvider temporarily as it doesn’t fit new IDataProvider pattern.
  • Fixed incorrectsecurity type when seeding a security.
  • Fixed incorrect bar type in Forex history requests (QuoteBar required).
  • Fixed bug in Interactive Brokers caching”No security definition found for this request”.
  • Added additional data file to fixdata not found error messages.
  • Fix crash in backtesting after an out of memoryerror.
  • Remove rate limiting on debug messaging in local LEAN.
  • Fix Interactive Brokers Brokerage “Pacing violation” error.
  • Ensured logs would be uploaded in the event of an initialization failure.
  • Fixed issue with CFD and OANDAdata where portfolio was always $0.
  • Remove hacky Environment.Exit solution to a temporary threading issue.

Notes

  • We have disabled options and futures price seeding to reduce logging noise.
  • History() methods without a T-type specified are not recommended as the return type is ambigous.

Thank you to the community contributors in this release –mushketyk, mchandschuh!

About LEAN

LEAN aims to empower investors to invest with confidence by using cutting edge algorithmic trading technology. Through the power of open source we are building the world’s best algorithmic trading platform, capable of accurately modeling global markets to give you insight into your strategy. Trading algorithms can be seamlessly deployed from backtesting into production with no changes or moved between brokerages. The LEAN user community reaches over 28,000 quants from all over the world.

LEAN supports C#, F#, VB, Java and Python programming languages and can be used in Equity, Forex, CFD, Options and Futures markets. It currently supports live paper trading, or execution by Interactive Brokers, FXCM and Oanda Brokerage.

For more information join the LEAN Community on GitHub.

Release Notes – LEAN v2.3.0.1

This release fixed minor bugs in LEAN to improve its stability and consistency across backtesting and live trading. There were no breaking changes in regression tests or the API of LEAN.

Features

  • Update AlgoSeek data converter to accept input file mask to only convert specific source files.
  • Added IsAssignable to detect assignment orders in backtesting*.
  • Added demonstration algorithm for consolidating futures data.
  • Simplified the basic template options algorithm to demonstrate other tickers.

Bug Fixes

  • Fixed race condition creating fill-forward subscriptions incorrectly resulting in different statistics.
  • Fixed bug in AlgoSeek options data converter when processing massive files.
  • Fixed issue where Interactive Brokers was not connected before making history requests.
  • Updated default history provider for OANDA and FXCM configurations to be the brokerage.
  • Fixed issue where CFD datatype defaulted to Quote; preventing algorithms from receiving data.
  • Fix issue in live trading where multiple threads accessing cashbook killed algorithms.
  • Upgraded FXCM account holdings logic to handle multiple positions of the same ticker.
  • Additional logging in scheduled event manager to help debugging time issues.
  • Refactored options exercise logic.

 

Thank you for the continuing bug reports and assistance from the community! A special shout out to h2o, Denny Caldwell and James Reily for helping us work through some issues!

* Note: Assignment events are not generated by IB in live trading. We are looking into heuristic ways to detect this but currently assignments are not handled in live trading.

About LEAN

LEAN aims to empower investors to invest with confidence by using cutting edge algorithmic trading technology. Through the power of open source we are building the world’s best algorithmic trading platform, capable of accurately modeling global markets to give you insight into your strategy. Trading algorithms can be seamlessly deployed from backtesting into production with no changes or moved between brokerages. The LEAN user community reaches over 28,000 quants from all over the world.

LEAN supports C#, F#, VB, Java and Python programming languages and can be used in Equity, Forex, CFD, Options and Futures markets. It currently supports live paper trading, or execution by Interactive Brokers, FXCM and Oanda Brokerage.

For more information join the LEAN Community on GitHub.

Release Notes – LEAN v2.3.0.0

This release made significant changes to the core of LEAN. Options and futures asset classes were added, and the datafeed extended to support their datatype. Hundreds of bugs were fixed and additional converter tools were added to help port the raw data provider files into LEAN format. MorningStar fundamental analysis was also added.

This release had breaking changes. Algorithms dependent on the items below should be reviewed carefully.

Features

  • Beta: Added options and futures asset class support for backtesting and live trading.
  • Added fine fundamental to filter stock universe by MorningStar corporate fundamentals.
  • Added IQFeed, FXCM and OANDA history provider implementations.
  • Implemented IQFeed option datafeed source.
  • Upgraded Forex and CFD modeling to use quotes for accurate spread accounting.
  • Added AlgoSeek futures and options data converter.
  • Added LEAN Docker file for Ubuntu.
  • Added data file provider. Source data files from the QC API.
  • Asset datafeed type (trade or quote) now configurable.
  • Implemented API v2 capable of building, backtesting and deploying live algorithms.
  • Create factor files from Yahoo finance API.
  • Streaming backtest and live desktop charting support.
  • Dozens of new indicators added.

Bug Fixes

  • Rolling window of n-samples now ready after n-samples.
  • Fixed consolidator issue live mode;also fixes indicators who depend on consolidators.
  • Seed securities on initializing algorithm to prevent margin calls on launching algorithm.
  • Disable margin call modeling by default in live trading and rely on the brokerage.
  • Fixed issue where requesting multiple resolutions updated consolidators incorrectly.
  • Fixed Interactive Brokers start up script issues.
  • Cloud log link no longer displayed for local backtests.
  • Fix indeterminate order cancellation status in backtesting.
  • Fixed incorrect market-open status during half trading days.
  • Ensure symbol limits removed in local trading.
  • Fixed numerous bugs by refactoring IB implementation to use IB open-source implementation.
  • Fixed rounding bugs by configurable order rounding, lot-size and pip-size by symbol.
  • Refactor live and file-system datafeed to be powered by enumerators.
  • Fix numerous errors in FXCM brokerage implementation.

Thank you to all the community contributors since the last release! jameschch, kaffeebrauer, naicigam, devalkeralia, mattmast, espirulina, Phoenix1271, bryanwang107, richardcurteis, AnObfuscator, mblouin02, Cylindrix, robcodes and QANTau!

About LEAN

LEAN aims to empower investors to invest with confidence by using cutting edge algorithmic trading technology. Through the power of open source we are building the world’s best algorithmic trading platform, capable of accurately modeling global markets to give you insight into your strategy. Trading algorithms can be seamlessly deployed from backtesting into production with no changes or moved between brokerages. The LEAN user community reaches over 28,000 quants from all over the world.

LEAN supports C#, F#, VB, Java and Python programming languages and can be used in Equity, Forex, CFD, Options and Futures markets. It currently supports live paper trading, or execution by Interactive Brokers, FXCM and Oanda Brokerage.

For more information join the LEAN Community on GitHub.

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.

Our Answer to NYSE Eliminating Stop Orders

From February 26th investors will no longer be able to use Stop or Good Till Cancelled order types on the NYSE, according to a recent press release from Reuters.

Typically Stop Market orders are used to place a market order when the stock exceeds a trigger price. On August 24th, 2015 many investors had their positions stopped out far below the stop prices they had entered. This is a known behavior of stop orders which cannot guarantee a certain execution price.

The difference between the market price, and the fill price is called slippage. In QuantConnect you can model slippage using our TransactionModel class. It would be wise to create a fill model which predicts a greater slippage in volatile market conditions. Most of the time this slippage is assumed to be negative (you execute at a price worse than expected), but occasionally you can even receive positive slippage (a better price than you expected).

To set a custom slippage model in QuantConnect you can use the code below:

 //$2 per trade transaction model, with custom slippage.
Securities["AAPL"].TransactionModel = new MyTransactionModel(2.00m);
public class MyTransactionModel : ConstantFeeTransactionModel { 
    public override decimal GetSlippageApproximation(Security security, Order order) {
        // If volatile, return high value for slippage.
    }
}

To prevent negative slippage with Stop orders investors should use a Stop Limit order which places a limit order when the market exceeds the trigger price. Stop Limit orders are not guaranteed to be filled but they do ensure you get your expected fill price or better.

To submit a Stop Limit order with QuantConnect you can use the code below:

var newStopLimitOrderTicket = StopLimitOrder("IBM", 10, stopPrice, limitPrice);

At QuantConnect we will continue supporting Stop, Stop Limit and GTC Orders across all our supported brokerages using software techniques. This will ensure your algorithm can continue as expected with no interruptions. We believe you are sophisticated enough to harnesspowerful types and we won’t artificially restrict the tools in your arsenal!

Happy Coding!

 

Older posts

© 2017 QuantConnect Blog

Democratizing algorithmic investments Up ↑