Team-LRN Want to learn more? We hope you enjoy this McGraw-Hill eBook! If you’d like more information about this book, its author, or related books and websites, please click here. Team-LRN MODELING FINANCIAL MARKETS Using Visual Basic.NET and Databases to Create Pricing, Trading, and Risk Management Models BENJAMIN VAN VLIET ROBERT HENDRY McGraw-Hill New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul Singapore Sydney Toronto Team-LRN the United States of A merica. Except as permitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher. 0-07-144288-X The material in this eBook also appears in the print version of this title: 0-07-141772-9 All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark. Where such designations appear in this book, they have been printed with initial caps. McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training programs. For more information, please contact George Hoare, Special Sales, at george_hoare@mcgraw-hill.com or (212) 904- 4069. TERMS OF USE This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGraw-Hill”) and its licensors reserve all rights in and to the work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill’s prior consent. You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right to use the work may be terminated if you fail to comply with these terms. THE WORK IS PROVIDED “AS IS.” McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill and its licensors do not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free. Neither McGraw-Hill nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom. McGraw-Hill has no responsibility for the content of any information accessed through the work. Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possibility of such damages. This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise. DOI: 10.1036/007144288X Copyright © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Manufactured in Team-LRN CONTENTS Acknowledgments v SECTION ONE Trading System Development 1 1 Introduction 3 2 Development Methodology 11 SECTION TWO Introduction to VB.NET: Algorithm Development 31 3 Getting Started with VB.NET 33 4 Value Types and Operators 47 5 Control Structures 65 6 Procedures 81 7 Objects 109 8 Arrays 133 9 Problem Solving 151 10 .NET Type System 171 SECTION THREE Database Programming: Back Testing 185 11 Relational Databases 187 12 ADO.NET 201 13 Structured Query Language 219 14 Introduction to Data Structures 243 15 Advanced Data Structures 257 iii For more information about this title, click here. Team-LRN SECTION FOUR Advanced VB.NET: Implementation 269 16 Software Connectivity and Interoperability 271 17 Connecting to Trading Software 281 18 XML 301 19 XML Protocols in Financial Markets 323 SECTION FIVE Object-Oriented Programming: Risk Management 341 20 Unified Modeling Lanaguage 343 References 379 Acronyms 383 Index 385 iv Contents Team-LRN ACKNOWLEDGMENTS Andrew Kumiega, Nithiphong Vikitset, Anton Karadakov, David Norman, Keith Black, Pamela Reardon, Alex Deitz, Melanie Winter, Siripor n Treetanasaw at, Mulianto The, D ebbie Cernauskas , Michael Modica, Jerold Lavin, Duana Wooters, Thomas E. “Burma” Shea, Sagy Mintz, Kenneth M. Horjus, Mark McCracken, Julia Spaulding, Dave Kuipers, Rich Pombonyo, Paresh Akbari, Cliff Ensing, Brain Huyser, Mark Groenenboom, Bruce Rawlings, Gary Lahey, Hank Perrit, Jack Wing, Varsha Pitre, Michael Ubis, Jason Malkin, and Irma Baines. v Copyright © 2004 by The McGraw-Hill Companies, Inc . C lick here for terms of use. Team-LRN This page intentionally left blank. Team-LRN SECTION ONE Trading System Development I project that, [in the next ten years], the majority of mo ney managers will completely automate their trade entry decisions So, in the very near future, if you have a mouse in your hand, you will be too late. Blair Hull Copyright © 2004 by The McGraw-Hill Companies, Inc . C lick here for terms of use. Team-LRN This page intentionally left blank. Team-LRN [...]... the Kumiega–Van Vliet paradigm So this book is not just about Visual Basic. NET (VB.NET) and databases It is about modeling financial instruments in code and putting the pieces, or models, together to create an automated trading or risk management system using a programming language, which in this case is VB.NET Let’s get started Financial markets are in a constant state of evolution, from buttonwood... the financial markets, you will likely work on such a team, which will require that at some point you will be required to either write computer code yourself, manage programmers, or work and interact with programmers on projects This will necessitate an understanding of, at the least, Microsoft Excel spreadsheet and the Visual Basic for Applications (VBA) environment, but likely also Visual Basic. NET or... development from a purely technical analysis standpoint, often using a retail software package to optimize a set of trading rules based upon moving averages and oscillators In this book, however, we will focus on quantitative analysis of equities, equity indexes, and options on equities and the programming of professional, proprietary software using Visual Basic. NET Several steps are involved in creating a quantitatively... quantitative research in financial markets requires the completion of these four phases of development resulting in four models: the algorithms model, data model, implementation model, and risk management model Over the remainder of this book, each of these phases, and their subphases, will be addressed Along the way, we will learn a great deal about quantitative finance, Visual Basic. NET, ADO.NET, databases... engineers who want to use UML must be familiar with object-oriented programming and the process of abstraction and application modeling (Don’t worry If you are not familiar with these concepts, we will show you them over the course of this book.) Models written using UML will help us visualize and document the structure of a software application Program and Document the System Having proved the trading system... even some major U.S trading houses (Norman, 2001) In this book, we will show you how to use Visual Basic. NET and several quantitative tools to begin development of some trading strategies and to analyze data, and we will share some ideas about how to connect to industry software via APIs to monitor financial markets and execute trades Figure 1.1 shows graphically how to implement a trading system in... hedging device through the type of framework we described MicroHedge is a popular institutional software package with connections to the options markets And Trading Technologies’ X_Trader software is a popular front-end software system for futures trading on electronic markets Thus, we could create a system to trade the CBOE’s S&P 500 cash options, via a market connection through MicroHedge’s API, that could... trading strategy development: computer science, quantitative finance, trading strategy, and quality development This is a lot to learn We do not attempt teach you all of it Rather we bring together some important ideas from math, technology, project management, and the financial markets that are required to build a real-world automated trading system Team-LRN This page intentionally left blank Team-LRN... to understand how databases are constructed and accessed using computer code to do financial research and develop trading and risk management algorithms and systems All financial research requires data, and the efficient management and storage of data is crucial to the profitable operation of a trading system “Data is the lifeblood of electronic markets, ” as David Norman states in his book Professional... success The more complex the trading idea, the more time it takes to define and communicate it clearly The description of the trading idea should contain the answers to several basic questions: Development Methodology 17 1 What market or markets will be traded? 2 What capital will be traded? a Short term b Long term c Midterm 3 Whose capital is it? Proprietary or investor capital? 4 How will success be defined? . Arrays 13 3 9 Problem Solving 15 1 10 .NET Type System 17 1 SECTION THREE Database Programming: Back Testing 18 5 11 Relational Databases 18 7 12 ADO .NET 2 01 13 Structured Query Language 219 14 Introduction. Interoperability 2 71 17 Connecting to Trading Software 2 81 18 XML 3 01 19 XML Protocols in Financial Markets 323 SECTION FIVE Object-Oriented Programming: Risk Management 3 41 20 Unified Modeling Lanaguage. Methodology 11 SECTION TWO Introduction to VB .NET: Algorithm Development 31 3 Getting Started with VB .NET 33 4 Value Types and Operators 47 5 Control Structures 65 6 Procedures 81 7 Objects 10 9 8 Arrays