Category: Coding

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!

 

Live Trading with Interactive Brokers

We’re very proud to announce our public release of live trading with Interactive Brokers! Now you can seamlessly design and trade your algorithm within QuantConnect.

Automated live trading is one of the most challenging engineering problems in financial technology. It involves controlling large financial resources, while pushing computational power to its limits!

Starting today, you can deploy your algorithms to your Interactive Brokers accounts, using minute, second or tick resolution data for Equities and FOREX. All powered by our open source algorithmic trading platform, LEAN.

Live Trading GUI

QuantConnect live trading comes packed with some impressive functionality to help your trading!

SMS and Email Notifications

Trigger sending emails, web hooks or SMS messages on key events with a single line of code. It is as simple as:
Notify.Sms(phone,message);
Notify.Email(email,subject,message);

Custom Live Data Sources

Using QuantConnect you can connect your algorithm to external data sources and stream updates to your algorithm events. Check out our demo using a Bitcoin REST API.

Runtime Statistics

With runtime statistics you can display custom information in the header of your live GUI to track your key indicators and asset values.

SetRuntimeStatistic("EURUSD", price);
Runtime Statistics

Mobile Control Interface

Control your algorithm on the road with our mobile friendly, HTML5 GUI. You can see full running algorithm charts and trades, or just a summary of your algorithm performance.

Live Mobile Controller

Live Options

Upgrade to Start Live Trading Today with QuantConnect

Open Source Updates

Its been an awesome month for the open-source project with contributions from people all around the world. We love working with the community and seeing LEAN used in ways we can barely imagine!

@kaffeebrauer contributed the Stochastic and OnBalance Indicators
@AlexCatarino implemented the ROC, ROCP and WILR Indicators
@QANTau started implementation of an OANDA Brokerage
@bizcad created a Weighted Moving Average Indicator
@mattmast created the Money Flow Index(MFI) Indicator
@bdilber started working on futures support

Additionally thanks to @ammachado, and @dpallone for documentation fixes, and @willniu for working out our consolidator logic 🙂 The LEAN Engine is growing more powerful by the week.

We’re Raising Capital

We’ve been experiencing some incredible growth and have bold plans for the next 12 months! We are opening an investment round and talking to investors to continue our growth plan.

Open Source Future of Algorithmic Trading

We’re proud to announce, thanks to the support of the community, the LEAN Algorithmic Trading Engine is now 100% open source. You have the freedom to connect any data source, execute through any brokerage and design any algorithm 100% locally.

Moment of our Open Sourcing, Jan 12th 2015

It’s an exciting new frontier for algorithmic trading; through open source QuantConnect is breaking open the traditionally secretive world of algorithmic trading to give you the same powerful tools as major hedge-funds.

Lean is “plug and play“. Running your first backtest takes about 23 seconds.

1. Star/Fork and Download the QuantConnect/LEAN Repo* from GitHub
2. Open Lean Project in Visual Studio (let Nuget download all dependencies)
3. Press F5 to Run Project

Presto - you’ve run your first backtest! Here is a step by step guide for building your first algorithm. You can also design custom indicators, import data for international stock markets and connect with any brokerage. We even ship some data with the repo so you can get started instantly.

Clone LEAN Today to Start Your Journey

Clone LEAN Today to Start Your Journey

We’re incredibly grateful to the QuantConnect pioneers for making this possible. With your support we can build the best algorithmic trading platform in the world. Sustainable, independent and community driven.

More Raw Power

To be profitable you need to iterate quickly. Last week we upgraded our backtest processing servers: you can now run a 10 year, event driven backtest in 33 seconds. Your algorithms are running on beautiful i7x3930’s with 6 cores/12 threads/64GB ram. We are the world’s first cloud-desktop hybrid algorithmic trading platform aiming to give you the best of both worlds; ease of local development and horse power of the cloud.

Dynamic Indicator System

Thanks to some long hours by Michael H we launched an elegant, powerful and dynamic new indicator library. It lets you implement designs quickly and avoids reinventing the wheel. Creating an indicator is only a single line of code! Get started with the sample algorithm.

var rsi = RSI("SPY", 14);
var bb = BB(_symbol, 20, 1, MovingAverageType.Simple, Resolution.Daily);
if (rsi > 80) {
    SetHoldings("SPY", 1);
} else if (rsi < 20) {
    SetHoldings("SPY", -1);
}
Plot("BB", bb.UpperBand, bb.MiddleBand, bb.LowerBand);
Clone the sample algorithm which implements 15+ indicators.

Bollinger Bands Implementation – Clone the sample algorithm which implements 15+ indicators.

 

Rotating Inversely Correlated Assets – NIFTY and USDINR

Over the last 15 years the economy of India has boomed and it has been reflected in the NIFTY index. The NIFTY has grown 7x since 1998 as the country has grown its exports. According to the UN the one of the primary exports of India are high value services which contributes 30% to their GDP.

We developed a hypothesis that as the strength of the NIFTY grew, the strength of the currency would follow as it is a primarily export economy. As the INR strengthens the ratio to USD falls making it an almost ideally inversely correlated asset.

We first tested this hypothesis treating the USDINR FX pair as a hedge against the NIFTY, but found there were periods where they were positively correlated and the hedge did not work.

Pivoting slightly we experimented with rotating the holdings of the portfolio to focus on the peak performing asset. We used a fixed rolling window to determine the peak performance and then swapped our holdings to focus on that asset.

We used the QuantConnect LEAN 2.0 backtesting engine which allowed us to import financial data from any source to run our analysis. The backtests were conducted over a 16 year period and were completed in 5-10 seconds. We saw phenomenal performance due to the strongly trending nature of the NIFTY and USDINR, achieving a Sharpe Ratio achieving 1.3 vs the NIFTY 0.7, and 42x returns vs 7x of the NIFTY.

To test the resilience of the strategy we experimented with the rolling window period to determine if this was critical to the success of the strategy. We used a rotating window from 3 days up to a 30 day window to optimize the variable for the best performance:

The resulting Sharpe Ratio is fairly robust regardless of the precise value of the rotating window period.

We believe there are many potential future improvements to the strategy to be explored; such as using a dynamically determined rolling window to avoid curve fitting. You could also experiment with different portfolios of inversely correlated assets to pick the best basket of assets.

Backtesting with a REST API

This weekend we reviewed the GIT-API and how people really wanted to use QuantConnect. We built the GIT-API enable using the powerful autocomplete features in Visual Studio. However requiring people to use GIT to submit a backtest was a step learning curve, and prone to errors when the website had traffic spikes.

As a result we made a decision to deprecate the GIT portion of QuantConnect, and replace it with a new RESTful API. It allows you to create projects and submit files for backtesting all via simple JSON commands. The REST API will allow unlimited innovation on top of QuantConnect’s backtesting engine. With just a few URL commands you can tap into our scalable cloud and backtest across terabytes of financial data. See our documentation for how to use the new interface.
Continue reading

Harnessing the Twitter API for Sentiment Strategies

In this project we will be writing an application which downloads tweets from Twitter. We are continuing our journey leaning C#, as we started with our Yahoo Finance data downloader.

Twitter has a REST API that allows us to  search for tweets, users, timelines, or even post new messages. We will use an incredible C# Twitter Library called Tweetinvi. It has everything you need to start building your own program. There are other alternatives, but we found this was the easiest and most complete. To use this program, you need to have a Twitter developer account, and use your own credentials.

Continue reading

Downloading Yahoo Finance Data with C#

The following post is the first in a series by Raul Pefaur on Learning C#. Over the last month Raul has taught himself C# with a variety of projects, tutorials and books which he will describe to help others on their journey to using C# for finance. Raul has a Master of Finance and lives in Santiago, Chile.

Yahoo has a popular API which lets you download daily financial data from its enormous library. In this blog post, I will be using this API to download financial data through a C# console application. It was created in Visual Studio and is free for you to download an use, though I recommend you try to build it yourself. If you like, use mine as a reference (I know there’s a lot of improvements in my code you could make. If you do, please share!). Continue reading

© 2017 QuantConnect Blog

Democratizing algorithmic investments Up ↑