Quantitative Investment: Research and Implementation in MATLAB

Similar documents
New Developments in MATLAB for Computational Finance Kevin Shea, CFA Principal Software Developer MathWorks

Financial Computing with Python

Part 1 Back Testing Quantitative Trading Strategies

TCA what s it for? Darren Toulson, head of research, LiquidMetrix. TCA Across Asset Classes

Model Calibration in MATLAB. Sam Bailey, PRUDENTIAL

Calibration and Simulation of Interest Rate Models in MATLAB Kevin Shea, CFA Principal Software Engineer MathWorks

AlgorithmicTrading Session 3 Trade Signal Generation I FindingTrading Ideas and Common Pitfalls. Oliver Steinki, CFA, FRM

Using AI and Factor Testing to Find Multiple Sources of Alpha

Key Features Asset allocation, cash flow analysis, object-oriented portfolio optimization, and risk analysis

The Financial Platform Built for now DESKTOP WEB MOBILE

Portfolio Management and Optimal Execution via Convex Optimization

Multi-Period Trading via Convex Optimization

5 th Annual CARISMA Conference MWB, Canada Square, Canary Wharf 2 nd February ialm. M A H Dempster & E A Medova. & Cambridge Systems Associates

XSG. Economic Scenario Generator. Risk-neutral and real-world Monte Carlo modelling solutions for insurers

The Optimization Process: An example of portfolio optimization

Introduction to Computational Finance and Financial Econometrics Introduction to Portfolio Theory

WESTERNPIPS TRADER 3.9

Legend expert advisor

Algorithmic Trading Session 4 Trade Signal Generation II Backtesting. Oliver Steinki, CFA, FRM

Markit Exchange Traded Product

bitarisk. BITA Vision a product from corfinancial. london boston new york BETTER INTELLIGENCE THROUGH ANALYSIS better intelligence through analysis

Economics 2010c: Lecture 4 Precautionary Savings and Liquidity Constraints

Introducing PAIRS TRADER $ C. Reactive control for automated trading

Modelling for the Financial Markets with Excel

Expected Return Methodologies in Morningstar Direct Asset Allocation

Risk Control Detail. RCM Alternatives TradingMotion platform:

A passive liquidity providing algorithm that will never cross the mid-price

CSCI 1951-G Optimization Methods in Finance Part 00: Course Logistics Introduction to Finance Optimization Problems

Optimal routing and placement of orders in limit order markets

Paul Ormerod Volterra Partners LLP, London and Centre for the Study of Decision-Making Uncertainty, UCL

Working Paper #1. Optimizing New York s Reforming the Energy Vision

DaxTrader RSI Expert Advisor 3.1 for MetaTrader Manual

Arbitrage-Free Option Pricing by Convex Optimization

The Yield Envelope: Price Ranges for Fixed Income Products

BROKERS: YOU BETTER WATCH OUT, YOU BETTER NOT CRY, FINRA IS COMING TO

36106 Managerial Decision Modeling Sensitivity Analysis

1 Introduction. Term Paper: The Hall and Taylor Model in Duali 1. Yumin Li 5/8/2012

Lecture outline W.B. Powell 1

BlitzTrader. Next Generation Algorithmic Trading Platform

Review consumer theory and the theory of the firm in Varian. Review questions. Answering these questions will hone your optimization skills.

High-Frequency Trading in the Foreign Exchange Market: New Evil or Technological Progress? Ryan Perrin

Leveraging Minimum Variance to Enhance Portfolio Returns Ruben Falk, Capital IQ Quantitative Research December 2010

First Steps To Become a Self-Directed Quantitative Investor. Course for New Portfolio123 Users. Fred Piard. version: May 2018

Getting Started with CGE Modeling

Lecture 3: Factor models in modern portfolio choice

How isystems works. Choose your broker. Explore trading strategies. Activate strategy

MiFID II Solutions. IHS Markit s comprehensive set of solutions to meet MiFID II requirements

Spotlight: Robotic Process Automation (RPA) What Tax needs to know now

Agile Capital Modelling. Contents

PROBLEM SET 7 ANSWERS: Answers to Exercises in Jean Tirole s Theory of Industrial Organization

Portfolio Analysis with Random Portfolios

Basel 2.5 Model Approval in Germany

We Provide the Insights. You Invest in the Right Opportunities. Solutions for Private Equity

Applications of Linear Programming

DALTON STRATEGIC PARTNERSHIP LLP ORDER EXECUTION POLICY DECEMBER 2017

We are not saying it s easy, we are just trying to make it simpler than before. An Online Platform for backtesting quantitative trading strategies.

Running Money. McGraw-Hill Irwin. Professional Portfolio Management. Scott D. Stewart, PhD, CFA. Christopher D. Piros, PhD, CFA

The Duration Derby: A Comparison of Duration Based Strategies in Asset Liability Management

Quantitative Trading System For The E-mini S&P

FINANCIAL MARKETS. Products. Providing a comprehensive view of the global ETP market to support the needs of all participants

GREATLINK GLOBAL EQUITY FUND (FUND DETAILS)

Real-Time, Comprehensive Risk Management, Analysis and Control. FTEN processes up to 1/3 of the daily US equities volume through its risk system >>

SciBeta CoreShares South-Africa Multi-Beta Multi-Strategy Six-Factor EW

Optimal Portfolio Liquidation and Macro Hedging

DataWise Limited. Introduction to Budgeting with DataWise Pro-active Report Writer. Copyright DataWise Limited 2009 Page 1

SYLLABUS. Market Microstructure Theory, Maureen O Hara, Blackwell Publishing 1995

BondEdge Next Generation

ARM. A commodity risk management system.

The duration derby : a comparison of duration based strategies in asset liability management

Relative and absolute equity performance prediction via supervised learning

Chapter 5 Portfolio. O. Afonso, P. B. Vasconcelos. Computational Economics: a concise introduction

TCA metric #4. TCA and fair execution. The metrics that the FX industry must use.

The Liquidity-Augmented Model of Macroeconomic Aggregates FREQUENTLY ASKED QUESTIONS

and, we have z=1.5x. Substituting in the constraint leads to, x=7.38 and z=11.07.

Economic Capital. Implementing an Internal Model for. Economic Capital ACTUARIAL SERVICES

Credit Portfolio Simulation with MATLAB

STOCK PRICE PREDICTION: KOHONEN VERSUS BACKPROPAGATION

36106 Managerial Decision Modeling Monte Carlo Simulation in Excel: Part IV

The effects of transaction costs on depth and spread*

Solving the MiFID II Research Unbundling Challenge

Applying the Principles of Quantitative Finance to the Construction of Model-Free Volatility Indices

The Case for Growth. Investment Research

Bernanke and Gertler [1989]

Machine Learning in High Frequency Algorithmic Trading

CDS-Implied EDF TM Measures and Fair Value CDS Spreads At a Glance

Unit-of-Risk Ratios A New Way to Assess Alpha

G604 Midterm, March 301, 2003 ANSWERS

Allocation of Risk Capital via Intra-Firm Trading

Master s in Financial Engineering Foundations of Buy-Side Finance: Quantitative Risk and Portfolio Management. > Teaching > Courses

EM Country Rotation Based On A Stock Factor Model

USER GUIDE

Macroeconomics. Lecture 5: Consumption. Hernán D. Seoane. Spring, 2016 MEDEG, UC3M UC3M

Lecture 17: More on Markov Decision Processes. Reinforcement learning

Much of what appears here comes from ideas presented in the book:

Integer Programming Models

Are Alternatives Right for Your Portfolio?

DUALITY AND SENSITIVITY ANALYSIS

for Finance Python Yves Hilpisch Koln Sebastopol Tokyo O'REILLY Farnham Cambridge Beijing

The OMS as an Algorithmic Trading Platform: Five Critical Business and Technical Considerations

Portfolio selection with multiple risk measures

Transcription:

Quantitative Investment: Research and Implementation in MATLAB Edward Hoyle Fulcrum Asset Management 6 Chesterfield Gardens London, W1J 5BQ ed.hoyle@fulcrumasset.com 24 June 2014 MATLAB Computational Finance Conference 2014 Etc Venues, St Paul s, London Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 1 / 25

Trading Strategy Workflow 1 Research Identification of returns source and robust modelling Robust testing of trading signals Possibly multiple data sources MATLAB: Scripting, charting, reporting 2 Code Optimisation Speed improvements Identification and removal of unnecessary processing or data querying MATLAB: Documentation, practice/experience 3 Production Set of guidelines for production code Central data source MATLAB: Functions, OO Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 2 / 25

Generic Trading Strategy 1 Data Historical and real-time Financial, economic, sentiment, etc. 2 Model Simplification of reality which captures certain important features E.g. use inflation and growth to forecast bond yields E.g. high-yielding currencies appreciate against low-yielding currencies E.g. asset-price trends are persistent 3 Trading signal Convert model outputs into trading positions Which assets to buy and sell, and in what quantities Position sizing may be dependent on risk or regulatory constraints Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 3 / 25

Research Starting a Project 1 Idea generation In house From literature (broker or academic research) Anecdotal evidence Buy/sell Bund futures following declines/rises in the flash manufacturing PMI Some technical analysis (e.g. support/resistance levels) 2 Model specification What are the required outputs? What should be input? Can the model be simplified without compromising on its most important features? 3 Data gathering Central banks Financial data providers Websites Brokers Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 4 / 25

Personal Modelling Philosophy A Digression I learnt this the hard way: If a simple trading model can be shown to work, a complicated model may improve results. If no simple trading model can be shown to work, no complicated model will improve results. This does not mean that building successful trading models is easy. As is typical in research, 90% of the work is finding the right questions to ask; the other 10% is finding answers. Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 5 / 25

Research Fitting Models Robustness checks Sensitivity of model output to parameters Stability of parameters Do different fitting methods produce similar results? How sensitive are parameters to the data sample? Are we sure there is no peek-ahead bias? This is particular concern for models using macroeconomic variables Have historical data been adjusted retrospectively? Have data release delays been accounted for? Have differing market trading hours (S&P versus Nikkei) been accounted for? Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 6 / 25

Research Identifying Trading Signals Demonstrate that a trading signal has predictive power This is often quite hard! A successful backtest alone does not usually convince me Charts can be very useful here Robustness checks Do the signals have a directional bias? Should they? Are signals effective after accounting for market trends? Are both the long and short signals profitable? Does a stronger signal have stronger forecasting power? Should it? Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 7 / 25

Research Trading Strategy Backtesting Drawdowns Performance metrics Persistence (across markets, across subsamples) Dependencies Correlations with other strategies Robustness Sensitivity to parameters Regime analysis rising/falling interest rates economic growth/recession bull/bear market Adding to a broader portfolio Effect on the portfolio s leverage? Effect on the portfolio s risk allocation to assets and asset classes? Effect on the portfolio s volatility/var/expected shortfall? Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 8 / 25

Code Optimisation Code optimisation by example A real-world code-optimisation problem The code solved a constrained minimisation problem I shall show some of the steps taken to improve the efficiency and reliability of the solver A particular concern was to ensure that the solution was not sensitive to the starting point of the minimisation Speed was an important consideration here, but was secondary to robustness Note: The Parallel Computing Toolbox was not used when producing the following results (although it would probably have sped things up) Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 9 / 25

Code Optimisation An Example This is an optimisation problem that I encountered recently: Define x 2 2 = i x 2 i and x 1 = i x i, for x R n. The Problem minimize x Ax b 2 2 + λ Cx 1, subject to Dx e 1 f, where x R n, A R ma n, b R ma, C R mc n, D R m d n, e R m d, f > 0, λ > 0. The objective function contains a quadratic term and a non-linear term. The constraint is non-linear. Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 10 / 25

Code Optimisation First Attempt Don t work harder than you need to! Use fmincon (Optimization Toolbox) Very quick to set up the problem Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 11 / 25

Code Optimisation Performance: Naive fmincon 20 dimensional problem 100 different random starting points (not necessarily satisfying constraints) Timing = 1, 144.92 seconds Objective: mean 2.1152, min 2.0951, max 2.1532 Table: Values for x 1,..., x 5. i Mean Min Max SD 1 0.2932 0.2559 0.3120 0.0125 2 1.9193 1.7683 2.2189 0.1282 3-0.7701-1.5355-0.2690 0.3528 4 4.5681 4.2161 4.8536 0.1180 5 0.5654 0.4741 0.7047 0.0464 Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 12 / 25

Code Optimisation Second Attempt We like the results from the first attempt Can we improve performance or robustness? Supply gradients for the objective and constraint using options = optimoptions('fmincon'..., 'GradObj', 'on', 'GradConstr', 'on') { Dx e 1 = D sign(dx e) { } Ax b 2 2 + λ Cx 1 = 2A Ax 2A b + λc sign(cx) Note: There are many other fmincon options that can be changed in the bid to improve performance Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 13 / 25

Code Optimisation Performance: fmincon with gradients 20 dimensional problem 100 different random starting points (not necessarily satisfying constraints) Timing = 96.04 seconds (92.1% speed up) Objective: mean 2.1153, min 2.0948, max 2.1865 Table: Values for x 1,..., x 5. i Mean Min Max SD 1 0.2939 0.2559 0.3128 0.0126 2 1.9119 1.7768 2.2191 0.1255 3-0.7636-1.7491-0.2658 0.3436 4 4.5720 4.2160 4.8536 0.1174 5 0.5659 0.4745 0.7047 0.0447 Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 14 / 25

Code Optimisation Q. How Can We Improve Further? A. Do Some Research! Boyd & Vandenberghe Cambridge University Press Also available at http://www. stanford.edu/~boyd/cvxbook/ Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 15 / 25

Code Optimisation The Problem Revisited Find an optimisation problem with the same optimal solution, but with a nicer form: Equivalent Problem minimize x,u,t where t R mc +, u Rm d +. x A Ax 2A bx + λ1 t subject to t Cx t, u Dx e u, 1 u f, The objective function is quadratic The constraints are linear We can use quadprog (Optimization Toolbox) Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 16 / 25

Code Optimisation Performance: quadprog 20 dimensional problem 100 different random starting points (not necessarily satisfying constraints) Timing = 1.34 seconds (99.9% speed up) Objective: mean 2.0041, min 2.0041, max 2.0041 Table: Values for x 1,..., x 5. i Mean Min Max SD 1 0.2917 0.2917 0.2917 0.0000 2 1.7458 1.7458 1.7458 0.0000 3 0.0141 0.0141 0.0141 0.0000 4 4.5358 4.5358 4.5358 0.0000 5 0.5095 0.5095 0.5095 0.0000 Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 17 / 25

Code Optimisation Results: Range of values output for x 1,..., x 20 after 100 optimisations. Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 18 / 25

Implementation Case Study: Challenges Faced Not always a distinction between research and production code Code difficult read and poorly commented Scripts calling scripts (variables with unclear scope) If conditions in code which are never met No centralised code library or version control Multiple data sources Various databases, spread sheets, text files and MAT-files Various update processes Strategies running on desktop computers Dependencies on user profiles Potential hardware risk (failing hard drives etc.) No API between trading strategies and trade-execution systems Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 19 / 25

Implementation Case Study: Writing Production Code Write production MATLAB code. Guidelines: Strip down research code to bare bones Remove commented-out code (unless there is a good reason otherwise) Include useful comments Use sensible variable names Do not sacrifice readability for performance unless necessary Standardise output Use centralised data source Include links to research (code and documentation) Add to source control Export to Java (MATLAB Builder JA) Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 20 / 25

Implementation Case Study: Production Code Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 21 / 25

Implementation Case Study: Production Environment Java platform for the execution of medium-frequency trades: 1 Update central database 2 Run MATLAB strategies in parallel 3 Send strategy outputs to MATLAB trade aggregation and sizing routine 4 Display trades in GUI 5 Trades approved by PM using GUI 6 High touch trades sent to the traders order manager 7 Low touch trades sent to the execution order manager Orders are validated using the pre-trade compliance engine Algorithmic execution parameters are determined Orders are routed to the best broker Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 22 / 25

Implementation Case Study: Production Environment Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 23 / 25

MATLAB Why Use MATLAB in Production? Research is done using MATLAB, so we avoid having to rewrite code Facilitates rapid deployment Avoids errors in translation Retain access to high-level functions Able to run the trading strategies on a desktop using MATLAB for rapid debugging Note that we are medium-frequency traders Low latency is not a requirement for our systems We measure run-times in seconds; we are indifferent to the milli, let alone the nano or pico! Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 24 / 25

MATLAB Likes What I like about MATLAB: Excellent user interface Thoroughly-tested high-level functionality Statistics Toolbox Optimization Toolbox Database Toolbox Datafeed Toolbox Parallel Computing Toolbox Multi-paradigm environment (supports scripting, functions, objects, etc.) Good documentation Technical support Edward Hoyle (Fulcrum) Quantitative Investment 24 June 2014, London 25 / 25