Professional Documents
Culture Documents
RG Quant
RG Quant
net/publication/325807627
CITATIONS READS
0 8,500
1 author:
Ji-Hai Xu
drxudotnet.com
43 PUBLICATIONS 735 CITATIONS
SEE PROFILE
All content following this page was uploaded by Ji-Hai Xu on 17 June 2018.
UniCAD Publishing
Practical C# and WPF for Financial Markets
Copyright © 2016 by Jack Xu, PhD
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1UC
Editor: Tyler Xu
All rights reserved. No part of the contents of this book and corresponding example source code may be
reproduced or transmitted in any form or by any means without the written permission of the author.
The author has made every effort in the preparation of this book to ensure the accuracy of the information;
however, this book is sold without warranty, either express or implied. No liability is assumed for incidental or
consequential damages in connection with or arising out of the use of the information or programs contained in
the book.
Xu, Jack
Practical C# and WPF for Financial Markets – Advanced C#, WPF, and MVVM Programming for Quant
Developers/Analysts and Individual Traders/ Jack Xu
– 1st ed.
p.cm.
ISBN 978-0-9793725-5-1
Overview
Welcome to Practical C# and WPF for Financial Markets. This book will provide all the tools you need
to develop professional financial applications using the C#, the Windows Presentation Foundation
(WPF), and the Model-View-View Model (MVVM) pattern based on the .NET Framework. I hope that
this book will be useful for quant developers, quant analysts, individual traders, .NET programmers, and
students of all skill levels.
In recent years, quantitative finance has been an attractive field due to the intellectual challenge and high
remuneration. Many scientists, engineers, and students wish to change their careers to become a quant
developer/analyst in investment banks or hedge fund firms. Most of them have solid background in
mathematics, statistical analysis, physics modeling, and programming, but lack knowledge and
experience in quantitative finance. A question that they constantly ask is “what do I need to prepare
myself to become a quant developer and analyst?” This book will provide answer to this question and
prepare you with solid technical skills in quantitative analysis and development.
On the other hand, more and more individuals want to become independent (“retail”) quantitative traders
who are looking to start their own quantitative or algorithmic trading business. The most common issue
they are facing is what kind of background do they need in order to be success in quantitative trading?
Most of those individuals received their advanced degrees in physics, math, engineering, or computer
science. This kind of training in hard sciences will give them an edge in quantitative analysis and pricing
complex derivative instruments. However, the capability to convert trading ideas into trading strategies
and the programming skill in implementing the automatic trading system are equally important. This
book will prepare you with all the necessary analysis and programming techniques to become a well-
equipped individual quant trader.
So what programming languages are most commonly used in quantitative finance? No doubt about it,
C++ is traditionally associated with finance applications for pricing complex derivative securities, and
much of the older financial infrastructure is also based on C++. C# and .NET Framework are a relatively
new technology comparing to C++. This book will choose C# and WPF as our programming framework
in developing various business applications in financial markets.
The reason for using C# in this book is that C# is relatively easy to learn comparing to C++. Scientists,
engineers, students, quants, and traders can learn C# and use it to develop financial applications quickly.
xiv | Introduction
People with a background in VBA, R, Python, Matlab, or Java will find the transition to C# much easier
than the transition to C++. Furthermore, in many cases developers’ productivity levels are much higher
than those achieved with C++. It is also possible to create interoperable .NET applications that contains
different technologies such as C++ and VBA legacy code.
The two key features in WPF, data binding and MVVM pattern, can further enhance developers’
productivity. The data binding provides a simple and consistent way for .NET applications to present
and interact with data. It has several advantages over traditional models, including a broad range of
properties that inherently support data binding, flexible UI (user interface) representation of data, and
clean separation of business logic from UI. The MVVM pattern is the most used architecture for WPF
applications. MVVM introduces three layers of separation of application code, namely, Model, View,
and ViewModel. View holds the actual UI; ViewModel holds the collection of properties, commands, and
property changed notifications; while Model holds business data, business logic, and business rule. You
will gain several advantages of using MVVM pattern, including 1) proper separation of the view and the
data. The data is not stored in view and the view is just for presenting the data; 2) clean testable and
manageable code; and 3) no code-behind so the presentation layer and the logic are loosely coupled.
I write this book with the intention of providing a complete and comprehensive explanation of C# and
WPF programming in quantitative finance. This book pays special attention to creating various business
applications and reusable .NET libraries that can be used directly in real-world finance applications.
Much of this book contains the original work based on my own programming experience when I was
developing business applications for quantitative analysis in financial field.
Practical C# and WPF for Financial Markets provides everything you need to create your own advanced
applications in quantitative finance and reusable packages using C# and WPF based on MVVM pattern.
It shows you how to use C# and WPF to create a variety of financial applications that range from simple
database, market data API, data visualization, quantitative analysis to pricing equity options and
complex fixed income instruments, machine learning, and trading strategy development. I will try my
best to introduce you to C# and WPF programming in quantitative finance in a simple way – simple
enough to be easily followed by a quant or .NET developer who has basic prior experience in developing
business applications using .NET technology.
and the other useful utility classes. You can extract these classes and plug them into your own
business applications.
most of the sample code with few modifications. Please remember, however, that this book is intended
for Visual Studio 2013, .NET 4.5, and SQL Server Express 2014, and that all of the example programs
were created and tested on this platform, so it is best to run the sample code on the same platform.
predict market direction. I will show you how to use the FinancialFormula object in the MSChart control
to display different indicators on your screen and how to extract the output results from the indicators.
Chapter 8, Machine Learning
This chapter discusses the advanced quantitative analysis techniques: machine learning. Machine-
learning technique has become one of the most promising fields in quantitative finance. It is widely used
in quantitative finance for predicting the future stock prices. This chapter will concentrate on the
supervised learning and covers several commonly used machine-learning algorithms in finance,
including the K-nearest neighbors, support vector machines, and neural networks.
Chapter 9, Options Pricing
This chapter covers the Black-Scholes formula used for options pricing. It shows several different
implementations for calculating the price and Greeks of the European and American options. It also
discusses how to use the open source quant libraries, such as QuantLib, to price various options,
including barrier options, Bermudan options, and other exotic options.
Chapter 10, Pricing Fixed-Income Instruments
This chapter demonstrates how to price the fixed-income instruments, including interest rates, bonds,
and credit default swaps. It also discusses various related topics, such as cash flows, term structures,
yield curves, discount factors, and zero-coupon bonds. I will provide the detailed procedures on how to
use the open-source QuantLib library to price these complex financial instruments.
Chapter 11, Trading Strategies and Backtesting
This chapter presents several trading strategies using the simple quantitative analysis techniques,
including the moving average and linear regression, as well as the commonly used technical indicators.
I will also present a long-short based backtesting framework, which allows you to examine the historical
performance of your trading strategies for single stock trading and stock pairs trading.
Customer Support
I am always interested in hearing from readers, and enjoy learning of your thoughts on this book. You
can send me comments by e-mail to jxu@DrXuDotNet.com. I also provide updates, bug fixes, and
ongoing support via my website:
www.DrXuDotNet.com
You can also obtain the complete source code for all of examples in this book from the foregoing website.