Developing Algo Trading Applications with SmartQuant Framework The Getting Started Guide. 24.02.2014 SmartQuant Ltd Dr. Anton B.



Similar documents
IBrokers - Interactive Brokers and R

DEVELOPING DATA PROVIDERS FOR NEEDFORTRADE STUDIO PLATFORM DATA PROVIDER TYPES

EXAM PRO:Design & Develop Windows Apps Using MS.NET Frmwk 4. Buy Full Product.

Getting Started with Telerik Data Access. Contents

BUILDER 3.0 Installation Guide with Microsoft SQL Server 2005 Express Edition January 2008

How To Install An Aneka Cloud On A Windows 7 Computer (For Free)

TRADERS WORkSTATION (IB) HALIFAX OpTIONS TRADER (HOT) DEALBOOk 360 (GFT) GAIN CApITAL FXCM IkON STRATEGy RuNNER NINjA TRADER THINk OR SWIM FXDD

1. Contents 1. Introduction Installation Preparing for the installation Installing the Pre-Requisites Components... 2.

Agentry SAP Framework. SAP Mobile Platform 3.0

PROJECTIONS SUITE. Database Setup Utility (and Prerequisites) Installation and General Instructions. v0.9 draft prepared by David Weinstein

Ability to trade using two platforms: the Soft-FX Traders Platform and MT4;

HalifaxOnline Platform and Account Setup Guide

Web Services API Developer Guide

Demo: Controlling.NET Windows Forms from a Java Application. Version 7.3

Authoring for System Center 2012 Operations Manager

CONFIGURATION AND APPLICATIONS DEPLOYMENT IN WEBSPHERE 6.1

Microsoft Dynamics CRM 2013/2015 Event Pipeline

Course 10978A Introduction to Azure for Developers

Add-on. Payment Method. a product for

Unicenter NSM Integration for Remedy (v 1.0.5)

Kokii BatteryDAQ. BMS Software Manual. Battery Analyzer Battery DAS

Automating Business Processes Using SharePoint Designer

MS 10978A Introduction to Azure for Developers

Installation Manual v2.0.0

Dell AppAssure Local Mount Utility

PIRAEUS SECURITIES S.A. Online Trading. Demo. Member of Piraeus Bank Group

Juris Installation / Upgrade Guide

TIGERPAW EXCHANGE INTEGRATOR SETUP GUIDE V3.6.0 August 26, 2015

Microsoft Dynamics CRM Adapter for Microsoft Dynamics GP

Ocean Data Systems Ltd. The Art of Industrial Intelligence. Dream Report GETTING STARTED. User- Friendly Programming-Free Reporting for Automation

PrivateWire Gateway Load Balancing and High Availability using Microsoft SQL Server Replication

REDIPlus Quick Start Guide

How to Backtest Expert Advisors in MT4 Strategy Tester to Reach Every Tick Modelling Quality of 99% and Have Real Variable Spread Incorporated

User Guide for Android OS

How To Use An Action Replay Dsi On A Datel Dsi On A Pc Or Dsii On A Playstation 2 On A Ds 2 On Pc Or Playstation 3 On A Ipad Or Playboy Ds (D

Release Notes LS Retail Data Director August 2011

MS Enterprise Library 5.0 (Logging Application Block)

Kofax Export Connector for Microsoft SharePoint

Administration Guide for the System Center Cloud Services Process Pack

Intellect Platform - Tables and Templates Basic Document Management System - A101

Microsoft Dynamics GP econnect Installation and Administration Guide

The Nuts and Bolts of Autodesk Vault Replication Setup

Installing, Uninstalling, and Upgrading Service Monitor

Extensibility. vcloud Automation Center 6.0 EN

Spotlight on Messaging. Evaluator s Guide

CA Spectrum. Microsoft MOM and SCOM Integration Guide. Release 9.4

safend a w a v e s y s t e m s c o m p a n y

MT4 Multiterminal USER MANUAL

SQL Server 2008 R2 Express Edition Installation Guide

PI Cloud Connect Overview

Understanding Portfolios. Enter a Trade

KIM ENG SECURITIES KE TRADE (FOREIGN STOCKS) INTERNET TRADING PLATFORM

LEVEL 3 SM XPRESSMEET SOLUTIONS

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

Desktop Surveillance Help

CA Data Protection. Content Provider Development Guide. Release 15.0

FioranoMQ 9. High Availability Guide

Contents Overview... 5 Configuring Project Management Bridge after Installation... 9 The Project Management Bridge Menu... 14

1. System Requirements

Visual Basic. murach's TRAINING & REFERENCE

SonicWALL CDP 5.0 Microsoft Exchange InfoStore Backup and Restore

Real-time trading in MATLAB

Application Power Management for Mobility

Known Issues and Work Around

SirixWeb 3.0. User guide

USER GUIDE GPS Forex Robot

mobiletws for ipad Users' Guide September Interactive Brokers LLC. All rights reserved.

User Guide for ios. 14 November Copyright GMO-Z.com Bullion HK Limited. All rights reserved.

Metalogix SharePoint Backup. Advanced Installation Guide. Publication Date: August 24, 2015

Rational Rational ClearQuest

10978A: Introduction to Azure for Developers

NETASQ SSO Agent Installation and deployment

INSTALL AND CONFIGURATION GUIDE. Atlas 5.1 for Microsoft Dynamics AX

Understanding Portfolios. Enter a Trade

EntroWatch - Software Installation Troubleshooting Guide

CentreWare for Microsoft Operations Manager. User Guide

MarkLogic Server. Connector for SharePoint Administrator s Guide. MarkLogic 8 February, 2015

Windows Scheduled Tasks Management Pack Guide for System Center Operations Manager. Published: 07 March 2013

Virtual CD v10. Network Management Server Manual. H+H Software GmbH

R i o L i n x s u p p o r r i o l i n x. c o m 1 / 3 0 /

Tutorial. Patch Management

Pharos Control User Guide

1. System Requirements

q for Gods Whitepaper Series (Edition 7) Common Design Principles for kdb+ Gateways

2012 Nolio Ltd. All rights reserved

EMC Documentum Repository Services for Microsoft SharePoint

Introduction To The SmartQuant System Architecture

Any symbols displayed within these pages are for illustrative purposes only, and are not intended to portray any recommendation.

Getting Started User Guide International trading platform NetExchange

SQL Server 2005 Express Installation guide

Compute Cluster Server Lab 3: Debugging the parallel MPI programs in Microsoft Visual Studio 2005

What is a workflow? Workflows are a series of actions that correspond to a work process

This three-day instructor-led course provides students with the tools to extend Microsoft Dynamics CRM 4.0.

Set up My Sites (SharePoint Server

Contents. Platform Compatibility. Directory Connector SonicWALL Directory Services Connector 3.1.7

Windows clustering glossary

Any symbols displayed within these pages are for illustrative purposes only, and are not intended to portray any recommendation.

Error: "Object reference not set to an instance of an object" When Opening Any Database

Sophos for Microsoft SharePoint startup guide

Database Studio is the new tool to administrate SAP MaxDB database instances as of version 7.5.

Transcription:

Developing Algo Trading Applications with SmartQuant Framework The Getting Started Guide 24.02.2014 SmartQuant Ltd Dr. Anton B. Fokin

Introduction... 3 Prerequisites... 3 Installing SmartQuant Framework... 3 Reinstalling SmartQuant Framework... 3 Understanding SmartQuant Framework... 4 The SmartQuant dll... 5 Creating Your First Project... 5 SmartQuant Namespace... 7 The Framework Class... 8 Framework.Current... 11 Framework Mode... 11 Framework Clock... 12 Clock Resolution... 14 Instrument Management... 14 Creating Instruments... 16 Instrument Manager... 16 Changing Instrument Properties... 18 Saving Instrument Properties... 18 Understanding Providers... 19 Market Data Providers... 19 Execution Providers... 19 History Providers... 19 Instrument Providers... 19 Account Providers... 20 Provider Manager... 20 Provider Event Model... 21 Connecting Providers... 24 Subscribing to Market Data... 25

Introduction You can develop stand alone financial applications with SmartQuant Framework. Such applications can range from market data analysis applications to trading front ends and order execution servers. You can also develop automated trading strategies as standalone applications right in MS Visual Studio. This was not possible before. Prerequisites Application development with SmartQuant Framework requires Microsoft.NET 4.5.1 and Microsoft Visual Studio 2012 or 2013. If you have Visual Studio 2012, most likely you need to install.net Framework 4.5.1 Developer Pack from http://www.visualstudio.com/downloads/download-visualstudio-vs Installing SmartQuant Framework The SmartQuant Framework is usually installed together with OpenQuant application. OpenQuant applications installs in the standard Program Files\SmartQuant Ltd\OpenQuant 2014 folder. The data files (data.quant and instruments.quant) can be found in your AppData\Roaming\SmartQuant Ltd\OpenQuant 2014\data folder, configuration files are in the corresponding folders in the AppData\Roaming\SmartQuant Ltd\OpenQuant 2014, and the demo solutions can be found in your Documents\OpenQuant 2014\Solutions folder. Reinstalling SmartQuant Framework It s always a good idea to perform clean uninstall before installing a new version. OpenQuant installer doesn t override user files such as data files, configuration files or strategy files. Thus you may miss important changes in those files if you don t remove them manually. In order to perform clean uninstall, you should uninstall OpenQuant selecting Uninstall in windows start menu,

and then manually remove files from your AppData\Roaming\SmartQuant Ltd\OpenQuant 2014\ and your Documents\OpenQuant 2014\Solutions\ folders. Indeed you can leave or backup files that you need. For example you don t need to delete your own strategies if you need them, but if you want to update demo strategies, you need to delete corresponding files. Then you can install a new version of OpenQuant 2014 as discussed in the previous chapter. Understanding SmartQuant Framework Wikipedia: A software framework is a universal, reusable software platform to develop applications, products and solutions. The designers of software frameworks aim to facilitate software development by allowing designers and programmers to devote their time to meeting software requirements rather than dealing with the more standard low-level details of providing a working system, thereby reducing overall development time once a framework is learned, future projects can be faster and easier to complete.

Provider Manager Clock Instrument Manager Instrument Server Provider Provider Event Bus Data Manager Data Server Provider Order Manager Order Server Data Simulator Portfolio Manager Execution Simulator Event Manager Event Dispatcher Event Logger Strategy Manager Scenario Strategy Strategy Strategy The SmartQuant dll The SmartQuant.dll is the core of SmartQuant framework. Usually all you need to do to start developing an algo trading application with SmartQuant framework is referencing this dll in your Visual Studio project. The SmartQuant.dll is installed in the GAC (Global Assembly Cache) and in Program Files\SmartQuant Ltd\OpenQuant 2014\ folder. Creating Your First Project

We assume that you have Microsoft Visual Studio 2012 (2013) and SmartQuant Framework installed on your computer (the latter means that you have downloaded and installed OpenQuant application). Launch Visual Studio and create a Console Application project. Let s call it MyApplication. Next, add reference to SmartQuant dll. Navigate to project references folder in the Solution Explorer, right click and select Add reference in the pop-up menu

Reference SmartQuant dll from Program Files\SmartQuant Ltd\OpenQuant 2014\ folder. SmartQuant Namespace All classes in SmartQuant Framework belong to SmartQuant namespace. Add using SmartQuant; to you program code to use classes from SmartQuant namespace.

The Framework Class The Framework class is the root element of the framework. It initializes and provides access to the core building blocks of the framework such as Provider, Instrument, Data, Order, Portfolio, Strategy and other Managers. Your program should create at least one object of the Framework class to initialize and use the SmartQuant framework. A generic application that uses the SmartQuant Framework usually has the following structure Here we create a new framework object named MyFramework and dispose this object at the end of the application. Although you can omit Framework name in the constructor, it s a good idea to give unique names to framework instances, especially if you are planning to create several framework instances in your application. Unique framework name should help to distinguish debugging output from different frameworks. Note that we explicitly call Framework.Dispose() at the end of the program. It s a good and required practice to do so if you want to keep your data safe and uncorrupted. Framework.Dispose() method forces Instrument and Data Managers and Servers to flush and close database files, as well as clean up other resources. If you suddenly notice that you have exported historical data or captured real time data and you don t see this data in the Data Manager next time you run your application, check that you have Framework.Dispose() in place in your application code.

Indeed to manage you program workflow in the most correct way you should use try-catch-finally blocks to dispose framework in case of possible exception in the application code: Once you have created an object of the Framework class, you are ready to use this object to access other core objects of the framework. Let s see how you can use Framework.InstrumentManager to list instruments available in the framework. If you run this program using standard installation of the SmartQuant framework, you should see the following output in the Console Window

Let s try to add a new instrument into framework Now if we run our first program that lists instruments available in the framework, we should see that GOOG instrument is actually stored in the instrument database and becomes available in the InstrumentManager.Instruments list

Framework.Current Framework.Current is a static property of the Framework class that is set to the current instance of the framework. A new instance of the framework is created if you call this property and there has been no framework instance created yet. This way you can use the same program code in the OpenQuant IDE, where a framework instance is created when the OpenQuant application starts, or in your standalone code, where a new instance of the Framework class is created when you call Framework.Current. Framework Mode The world of quantitative finance, quantitative analysts, strategy developers and traders essentially work with two types of data on-line and off-line date. Consequently SmartQuant Framework can operate in one of two modes, real time mode and simulation mode. You can use Framework.Mode property to check what mode the framework is currently running in. The fundamental difference

between these two modes will become clear when we understand the Framework.Clock in the next chapter. Note that Framework.Mode is set to FrameworkMode.Realtime when you create Framework object and changed to FrameworkMode.Simulation when you backtest or optimize a strategy. Framework Clock Framework Clock object is the heart of SmartQuant framework. It gives you the current time of the framework that is used for setting event timestamps and for performing time measurements in the framework. You can get the current time of the framework using Clock.DateTime property. The clock can also operate in either ClockMode.Simulation or ClockMode.RealTime. You can get the current clock mode using Clock.Mode property. The main difference between these two modes is that Clock.DateTime returns DateTime.Now in the Realtime mode, which is expected, but in the Simulation mode it returns datetime stamp of the last simulated event. Realtime mode Real-time data provider Event Event.DateTime = Clock.DateTime Simulation mode Data simulator Event Clock.DateTime = Event.DateTime The Framework Clock also provides so-called Reminder facility. SmartQuant Framework Reminders are somewhat similar to.net timers but there are two significant differences. Firstly, Reminders can work in both Realtime and Simulation modes, and, secondly, Reminder Callbacks are called from the main framework thread (the same thread which calls Strategy.OnBar() and other strategy event handlers).

If you run this program and wait enough time, you should get the following results You can also pass an object with a reminder to distinguish between different reminders in case they use the same callback method.

The output should look similar to the following Indeed you can pass any object with a reminder, not necessarily a string as shown in the example above. Clock Resolution Instrument Management Financial instruments package financial capital into readily tradable forms - they do not exist outside the context of the financial markets. Their diversity of forms mirrors the diversity of risk that they manage.

Financial Instruments can be categorized according to whether they are securities, derivatives of other instruments, or so called cash securities. If they are a derivative, they can be further categorized depending on whether they are traded as standard derivatives or traded over the counter (OTC). Alternatively they can be categorized by 'asset class' depending on whether they are equity based (reflecting ownership of an asset) or debt based (reflecting a loan the investor has made to the owner of an asset). If it is a debt security, it can be further categorized into short term (less than one year) or long term. Foreign Exchange instruments and transactions are neither debt nor equity based and belong in their own category. Combining the above methods for categorization, the main instruments can be organized into a matrix as follows: ASSET CLASS Debt (Long Term) Debt (Short Term) Equity Foreign Exchange Bond Floating rate note INSTRUMENT TYPE Cash Standard Derivative OTC Derivative Deposit/loan Bill CD (Certificate of deposit) CP (Commercial paper) Stock (Equity index) Foreign exchange spot Bond future option Bond future Futures Stock options Equity futures Foreign exchange futures Interest rate swap Interest rate cap & Interest rate floors Cross currency swap Interest rate option Exotic instruments Forward rate agreement Foreign exchange swap Stock Options Exotic instruments Foreign exchange options Foreign exchange forwards Currency Future Most of the standard derivatives, like Futures and Stock Options are exchange traded. This means that actual execution of a trade takes place at an exchange either via a physical Broker or an Electronic Communications Network (ECN). OTC derivatives however, are traded directly between parties and not through an exchange. At any given point in time, an instrument, whether a.net class or a real world financial instrument can be described by a combination of static and dynamic properties: Static Properties: Instrument type (e.g. common stock) Ticker name (e.g. MSFT) Description (e.g. Microsoft Corporation) Exchange (e.g. NASDAQ)

Currency (e.g. USD) etc. Thus, a static property is everything that is included in the issuer note and usually doesn't change during the lifetime of an instrument. Dynamic Properties: Last price (e.g. 25.80) Closing price (e.g. 25.60) Traded volume (e.g. 64,000,000) Dynamic properties change throughout the lifetime of a security. Thus, every property that is exposed to the market and can be influenced by it can be considered a dynamic property. In SmartQuant Framework a financial instrument is represented by the Instrument class. Creating Instruments Create an instrument object with Instrument class constructor. Instrument Manager The InstrumentManager provides access to the list of known instruments in the SmartQuant framework. An Instrument is uniquely identified in the framework by its numeric id, Instrument.Id, as well as by its symbol, Instrument.Symbol.

You can use InstrumentManager to find an instrument by its Id Instrument instrument = InstrumentManager.GetById(1); and by its symbol Instrument instrument = InstrumentManager.Get( MSFT ); or Instrument instrument = InstrumentManager[ MSFT ]; You can also use Instruments property of the InstrumentManager to get access to the list of available instruments and find an instrument with specific id or symbol in this list Instrument instrument = InstrumentManager.Instruments.GetById(1); and Instrument instrument = InstrumentManager.Instruments.Get( MSFT ); or Instrument instrument = InstrumentManager.Instruments[ MSFT ]. When a new instrument is created, it s unknown to the rest of the framework. You should add Instrument to the InstrumentManager to make it available to strategies and other components of the framework. InstrumentManager.Add(instrument); Since there cannot be two instruments with the same symbol, it s a good practice to check that instrument with the same symbol is not present in the framework when you add a new instrument If you want to use an instrument with a specific symbol and need to create it if there is no such instrument in the framework, the standard code usually looks like

An exception will be thrown if you try to add instrument with the symbol that is already present in the framework. Changing Instrument Properties Instrument.TickSize = 0.1; Note that you cannot change instrument symbol and instrument id since these two properties uniquely identify instruments in the framework. You have to delete instrument with the symbol you want to change and create a new instrument with a new symbol. Note that instrument properties are not persistent. This means that instrument properties are not saved in the database automatically when you change proper ties of instrument object in memory. You should call DataManager.Save(instrument) method when you want to save instrument properties in the instrument database. Saving Instrument Properties

Use DataManager.Save(instrument) method to save instrument in the instrument server database. Understanding Providers In SmartQuant Framework, providers request services from third party data and execution services. All providers support two way communication processes. So, if you place an order, you can get a fill response back in the Framework or you will receive market data once you request it for a specific symbol. There are several different kinds of providers supported in SmartQuant: Market Data Providers Market data providers can request real time streaming data from 3rd party services. The following forms of real time data are supported: Quote Trade Level II Bar Execution Providers Execution providers can implement the following methods and thus offer this kind of functionality from within SmartQuant Framework Send orders Cancel orders Replace orders Receive order status reports Receive execution reports History Providers History providers can request historical data from 3rd party services. The following forms of historical data are supported: Quote Trade Bar Daily Instrument Providers

Instrument providers can request instrument definitions. Account Providers Account providers can request open orders, positions and current account information, such as buying power. Provider Manager Usually all available in the SmartQuant framework providers are registered in the Provider Manager. You can get access to the provider manager using Framework.ProviderManager property. The following code lists providers registered in the provider manager using ProviderManager.Providers property. Note that there are always two default providers registered in the provider manager default market data simulator and default order execution simulator.

Other providers can either be added to the provider manager via framework configuration file or added in the program code using ProviderManager.AddProvider method. Let s create Interactive Brokers TWS API provider and register this provider in the provider manager. Provider Event Model SmartQuant Framework doesn t use.net events internally. SmartQuant has its own event processing architecture that is build around the Event Bus concept. SmartQuant events are objects of classes derived from the base Event class. The Event class has two properties, which uniquely identify an event - even Type and event DateTime. The Event Bus consists of several Event Pipes, such as the Data Pipe, the Execution Pipe, and the Service Pipe. An Event Pipe consists of one or more Event Queues. Event pipes have different priorities. Obviously, the execution pipe has the highest priority.

Event Bus Provider Provider Provider Data Pipe Execution Pipe Service Pipe Event Manager Event Dispatcher.NET Events User Application

Connecting Providers Usually the Provider.Connect() method is used to connect a provider to a broker. The result of this call is provider specific and depends on internal provider implementation - this call can be synchronous or asynchronous, blocking or non-blocking. You can get into troubles if a provider implements non-blocking connect logic (i.e. as a result of this call a connect request is sent to a broker, program execution returns from the connect method but response from the broker is not received and provider is not connected). It s quite easy to send an order or a market data request to a disconnected provider this way, which is not good indeed. A much better idea is to call blocking Provider.Connect(timeout) method and check that provider is actually connected. Provider.Connect(timeout) method calls Provider.Connect() method and waits timeout milliseconds in a Thread.Sleep(1) loop until Provider.IsConnected or timeout is expired.

Provider.Connect(timeout) method returns true if provider is connected and false if timeout is expired, so that you can simplify connection code As we saw in the Provider Event Model chapter, we can use EventDispatcher ProviderConnected and ProviderDisconnected events to notify our application when a provider becomes connected or disconnected. Note that you can use generic ProviderStatusChanged event instead of ProviderConnected and ProviderDisconnected event combo. Note that you can use ProviderError event to notify your application when an error occurs in a provider. For example if you try to connect to IB TWS that is not running, you should get the following error Subscribing to Market Data Provider.Subscribe(Instrument) and Provider.Subscribe(InstrumentList) can be used for market data subscriptions.