Page 2 of 5

Using the QuantConnect Charting API

We’re pleased to announce the release of a new charting API which lets you create flexible, dynamic charts from your backtest. The charts stream to your browser as the backtest is running and can be configured in many different ways. It is a very simple API, allowing you to create custom charts with just 1 line of code. The minimal usage plots a second line on your strategy’s equity chart. It can be accessed like this:

//Minimum code required for custom plotting:
Plot(string seriesName, decimal/int/float value);
//Example using the 'Strategy Equity' chart by default.
Plot("Portfolio", Portfolio.TotalPortfolioValue);
Custom line plot stacked with your strategy equity.

Custom line plot stacked with your strategy equity.

With just one extra parameter, the chart name, you can also create your own chart and place any series onto it you wish:

//Create your own charts by specifying a chart name:
Plot(string chartName, string seriesName, decimal/int/float value);

Underneath the Plot() function are two key classes: Chart and Series. The Chart class is the canvas you’d like to draw on, it can be set so the Series are Stacked or Overlayed. The Series classes are the data on the chart, they default to Line plots but can be set to be Candles or Scatter. Below is an example of creating a customized chart and plotting our trades on top of the asset price:

Plot prices with trades to see where your algorithm is working.

Plot prices with trades to see where your algorithm is working.

//Our custom chart, id: "Currency Plotter", Overlay the series.
Chart plotter = new Chart("Currency Plotter", ChartType.Overlay);
//Line series for our EURUSD pricing.
plotter.AddSeries(new Series("EURUSD", SeriesType.Line));
//Scatter-series for our BUY-orders.
plotter.AddSeries(new Series("Buy", SeriesType.Scatter));
//Scatter-series for our SELL-orders
plotter.AddSeries(new Series("Sell", SeriesType.Scatter));   
AddChart(plotter); //Add the Chart to our algorithm

Once you’ve setup your custom chart you can access it with the Plot() function.

Plot("Currency Plotter", "EURUSD", price);      // Save End of Day prices.
Plot("Currency Plotter", "Buy", purchasePrice); // Plot purchasing prices.
Plot("Currency Plotter", "Sell", salePrice);    // Plot sale prices.

The SeriesType enum controls the style of a series. Data passed into candle plots gets automatically converted into Daily or Weekly candles depending on the quantity of data. Because of technical limitations of working in a browser all series are capped at 4000 samples. If you find your browser slowing down try sampling less!

Class Chart(string chartName, ChartType type);
Class Series(string seriesName, SeriesType type);
Enum ChartType { Overlay, Stacked }
Enum SeriesType { Line, Scatter, Candle }

Putting it all together the results are fairly exciting, we hope you’ll enjoy! To get you started we’ve made a demonstration algorithm which generates the charts below. Clone it and copy the bits you like into your algorithm.

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

RSI Indicator with Martingale Position Sizing

Martingale is a bet sizing technique for increasing odds of winning at the expense of increased risk. The classic example is a coin flipping game where the gambler doubles his bet if he loses, in the hopes of making back any losses to break even. He will continue doubling his bet through subsequent losses until the bet breaks even. Once he returns to whole he continues betting with a unit bet. In theory with infinite capital and exactly 50-50 probability martingale can ensure the gambler will always return a profit.

Martingale portfolios typically display near perfect equity curves with dramatic, short term drawdowns.

Martingale portfolios typically display near perfect equity curves with dramatic, short term drawdowns.

Martingale position sizing is sometimes used in trading strategies without knowing its true risks. Continue reading

The Importance of Benchmarking

There are two different techniques for measuring your strategy performance; relative and absolute performance. Before you design your strategy its important to define your metrics for success. As you iterate through strategy ideas this will help you know where you need to improve.

An absolute return strategy aims to make a consistent steady return independent of market conditions. It might rely on assets which are not affected by the market volatility such as bonds. Strategies which trade long and short are easier to be designed for an absolute return. Continue reading

Three Common Implementation Mistakes

In our work at QuantConnect we have helped with thousands of budding quants over the years. Our algorithm development terminal is a powerful backtesting platform that allows members to design strategies on 15 years of past equities data.

We see several very common mistakes in even the most basic strategies. For our latest free video tutorial – Coding the Exponential Moving Average Strategy – we wanted to start by helping users avoid these common mistakes and show how they could avoid them. These common mistakes are… Continue reading

New HTML5 IDE and Community Discussion Feed

Over the last 12 months we’ve been working day and night, silently and constantly pushing feature updates to make QuantConnect better. It is a very humbling experience looking back on the earlier, cluttered and buggy coding environment.

We decided to do a review, and revisit your needs from scratch to focus on what you really want. We reimagined the coding environment with fresh eyes and after taking a pause, we made the leap deciding to scrap the entire v1.0 interface and rebuild it from scratch. The lessons we’d learned, and changes required were not iterative, they were revolutionary… so we set to work. Continue reading

QuantConnect Backtesting now with ChartIQ

In our constant push to provide the best user experience and back-testing platform possible we’re happy to announce the integration of ChartIQ charting to the QuantConnect backtester! ChartIQ have created a beautiful HTML5 charting package and analysis tools that allow you to intuitively navigate historical equity patterns. ChartIQ

We hope with our new improved charting you can continue designing the best strategies possible!You can now just use the basic candle charts, but over the coming weeks we’ll enable the built in ChartIQ JavaScript indicators, stock price plotting and custom data plotting. Continue reading

Algorithm Sharing, Private Groups and DLL Upload Support

Dear QuantConnect Members,

Jared here from QuantConnect, apologies for not getting in touch sooner its been a busy few months. In addition to constant feature upgrades we’ve been arranging funding for many of our users. Its very rewarding pairing a talented engineer with capital and seeing a dream become reality.

You all constantly amaze me and its a privilege to work with so many intelligent people. If you have a strategy with greater than 3 sharpe ratio, and less than 5% drawdown we can now arrange millions in investment capitalfor your strategies thanks to partner hedge funds.

We are driven to serve you and create the best possible algorithmic trading platform. We’re still the only ones in the world to serve free tick resolution data, and we’ve done it entirely bootstrapping with angel investment. We are very proud to have come this far but we need your support – if you want to support the QuantConnect mission to break open algorithmic trading please get in touch –, or upgrade your account.

Here are three new features for you to make life easier! Algorithm Code Cloning, Private Discussions (“Groups”) and DLL Upload Support. Continue reading

7 Tips For Fixing Your Strategy Backtesting a Q&A With Top Quants

Strategy backtesting is a mix of art and science. Quants who rely too much on science will fall victim to the infamous Curve Fitting phenomenon. While some quants who overcompensate on their artistic balance will create disillusioned theories that back their models. We created this post to compile leading quants’ perspectives on strategy backtesting covering tools, tips and how to avoid common mistakes made while strategy backtesting.

1. Have A Common Sense Idea of Your Model

“If you can’t come up with a pretty common sense explanation that you can describe to your 12-year-old niece or nephew. Then chances are, you’re simply data mining. Coming up with something that won’t exist in the future.”said Mebane Faber (@mebfaber), Portfolio Manager at Cambria Investments.

When Mebane first started in quant trading he thought he had found the “holy grail” model by analyzing its historical returns. Mebane says extrapolating historical returns to the present is a common mistake made by new quants which can be fixed if you know why your model works. “Most traders that are older have a lot of battle scars either from real money or paper trading portfolios that performed differently than the historical model showed.” says the experienced Mr. Faber.

So what is Mebane’s advice to new quants looking to perfect their backtesting strategy: “come up with a system, or multiple systems (which I think is more important) that fits your personality but is also robust over time“. Wise words from a King of quantitative trading.

2. Use Blind Data to Improve Your Strategy

Optimizing a strategy is for some a process that is ongoing and for some a process that produces such low results that it is abandoned. Deepak Shenoy(@deepakshenoy), Co-Founder of Capital Mind a big data analysis company, says it is a combination of both groups “I don’t like curve fitting so I tend to avoid over-optimization“. Instead he adds unrelated factors “like volume, open interest or options price sensitivity (vega) – or simply by using the knowledge of near term events to augment a system“.

Additionally, an important step for Deepak after he’s optimized, is to test on a blind data set for validation. “I test an optimized strategy on either different sets of stock data or different timeframe data… or both. To see how the system does in other timeframes.” This is before he moves the system to a lengthy paper trading schedule to further validate the model. Deepak’s perspective seems to be a focus on perfection, validation from multiple sources and comprehensive market regime testing. A worthy lesson for quants, be a perfectionist!

3. Decide Your Most Important Metrics Before

When you get to the performance evaluation segment of your strategy backtesting process, historical data is plentiful. “While it is pretty standard to look at popular performance statistics like the Calmar Ratio, Sharpe Ratio, CAGR, or MaxDD, they only reveal a small picture of how the model performed” says Michael Guan, an Associate with Macquarie Group. Michael says he focuses on additional measures like Positive Rolling 12 month periods, average drawdown, Annual Returns, average profit per trade which all provide a “more multi-dimensional view through time“.

Michael is a true believer in a multi-dimensional backtesting process. He explained his viewpoint eloquently: “backtesting is an integral part of trading model development. Making as few assumptions as possible and testing on a wide variety of assets ensures statistical robustness“. Many quants run a backtest with no preconceived notion of the data they want and this creates an issue in determining what data is valuable. Follow Michael’s tip and make a list of the variables that matter to you. And data has more value to you, is the Sharpe Ratio worth more to you than the P:L ratio? You should know this before you start backtesting.

4. Make Sure You Are Looking At The Right Data

Continue reading

« Older posts Newer posts »

© 2017 QuantConnect Blog

Democratizing algorithmic investments Up ↑