Learn Quantitative Finance without Code
About this Book
This book describes a powerful quantitative finance playground – Gincker Finance, which lets you build advanced financial applications without needing to write a single line of code. With this playground, you can access various market data APIs, create interactive stock charts, perform technical analysis using various technical indicators, backtest trading strategies, and valuate different asset types using build-in pricing engines. I hope that this book will be useful for quant developers, quant analysts, individual traders, and students of all skill levels.
Ideal for scientists, engineers, and students who would like to become more adept with quantitative finance, Learn Quantitative Finance without Code familiarizes you with:
- A complete, in-depth instruction to practical quantitative finance. You can consider this book as a walkthrough user manual for the Gincker Finance playground. After reading this book and running the example programs, you will be able to create various sophisticated business applications in quantitative finance without needing to write a single line of code.
- The walkthrough examples contained in this book allow you to explore technical analysis approaches and understand how the algorithms work in quantitative finance. You can modify the input parameters and customize the output results to form the basis of your own applications in quantitative finance. Some of the examples with different templates on the Gincker Finance playground provided in this book are already sophisticated projects in quantitative finance that you can use directly in your own real-world business applications.
- The dynamic output results from the Gincker Finance playground is a simple URL link called gincker. This gincker can be embedded in external websites, incorporated into desktop applications, or integrated into research papers or reports. You can also bookmark the gincker for later use or share it with friends, colleagues, or other users. The advantage of ginckers over the static output results from traditional software packages is that the gincker can deliver dynamic graphics content – users can use the gincker to regenerate, manipulate, modify, or customize the results to meet their requirements
Table of Contents
Introduction ............................................................. 1 Overview ............................................................. 1 Gincker Finance Playground ........................................... 1 What this Book Includes............................................... 2 Is this Book for You?................................................. 3 How this Book Is Organized ........................................... 3 Customer Support ..................................................... 4 Risk Warning and Disclaimer .......................................... 5 Market Data ...................................................... 5 No Investment Advice Provided .................................... 5 Disclaimer ....................................................... 5 1 Overview of Gincker Finance ............................................ 7 1.1 Gincker Finance and Traditional Software ......................... 8 1.1.1 Traditional Software Packages .............................. 8 1.1.2 Gincker Finance ............................................ 9 1.2 Templates in Gincker Finance ..................................... 11 1.2.1 Layout ..................................................... 11 1.2.2 Templates .................................................. 12 1.2.2.1 Market Data Category ..................................... 13 1.2.2.2 Indicators Category ...................................... 13 1.2.2.3 Strategies Category ...................................... 15 1.2.2.4 Options Category ......................................... 16 1.2.2.5 Fixed Income Category .................................... 17 1.3 Working Area ..................................................... 18 1.4 A Walkthrough Example............................................. 21 1.4.1 Default Results ............................................ 21 1.4.2 Change Input Parameters .................................... 21 1.4.3 Customize Output Chart ..................................... 23 1.4.4 Save Output Results ........................................ 24 2 Market Data ............................................................ 27 2.1 Market Data from Yahoo ........................................... 27 2.1.1 Default Results ............................................ 27 2.1.2 Stock Chart ................................................ 29 2.1.3 Change Input Parameters .................................... 29 2.1.4 Customize Stock Chart ...................................... 29 2.1.5 Stock Data in Table ........................................ 31 2.2 Market Data from Alpha Vantage ................................... 31 2.2.1 Historical Stock Data ...................................... 32 2.2.2 Intraday Stock Data ........................................ 33 2.2.3 Real-Time Stock Quote ...................................... 35 2.2.4 Historical Forex Data ...................................... 35 2.2.5 Intraday Forex Data ........................................ 38 2.2.6 Sector Performance Data .................................... 40 2.3 Market Data from Tiingo .......................................... 40 2.3.1 Default Results ............................................ 40 2.3.2 Stock Data in Table ........................................ 41 2.4 Market Data from Finnhub.......................................... 42 2.4.1 Historical Stock Data ...................................... 42 2.4.2 Intraday Stock Data ........................................ 44 2.4.3 Historical Forex Data ...................................... 45 2.4.4 Intraday Forex Data ........................................ 46 2.4.5 All Forex Rates ............................................ 48 2.5 Market Data from Stooq............................................ 48 2.5.1 Default Results ............................................ 48 2.5.2 Stock Data in Table ........................................ 49 2.6 Interest Rates from Markit ....................................... 50 2.6.1 File Structure ............................................. 50 2.6.2 ISDA Interest Rates ........................................ 51 3 Technical Indicators ................................................... 53 3.1 Overlay Indicators ............................................... 54 3.1.1 Bollinger Band Indicator ................................... 55 3.1.2 Double Exponential Moving Average .......................... 57 3.1.3 Exponential Moving Average ................................. 58 3.1.4 Kaufman Adaptive Moving Average ............................ 59 3.1.5 Mesa Adaptive Moving Average ............................... 61 3.1.6 Midpoint over Period ....................................... 63 3.1.7 Mid-Price over Period ...................................... 64 3.1.8 Parabolic Stop and Reverse Indicator ....................... 65 3.1.9 Simple Moving Average ...................................... 66 3.1.10 T3 Moving Average ......................................... 68 3.1.11 Triple Exponential Moving Average ......................... 69 3.1.12 Triangular Moving Average ................................. 70 3.1.13 Weighted Moving Average ................................... 71 3.1.14 Hilbert Transform – Instantaneous Trendline................ 72 3.2 Momentum Indicators .............................................. 73 3.2.1 Average Directional Index .................................. 75 3.2.2 Average Directional Movement Index Rating .................. 76 3.2.3 Absolute Price Oscillator .................................. 77 3.2.4 Aroon Indicator ............................................ 78 3.2.5 Aroon Oscillator ........................................... 79 3.2.6 Balance of Power ........................................... 81 3.2.7 Commodity Channel Index .................................... 82 3.2.8 Chande Momentum Oscillator ................................. 83 3.2.9 Directional Movement Index ................................. 84 3.2.10 Moving Average Convergence Divergence ..................... 86 3.2.11 Money Flow Index .......................................... 87 3.2.12 Negative Directional Indictor.............................. 89 3.2.13 Negative Directional Movement ............................. 90 3.2.14 Momentum Indicator ........................................ 91 3.2.15 Positive Directional Indicator ............................ 93 3.2.16 Positive Directional Movement ............................. 93 3.2.17 Percentage Price Oscillator ............................... 95 3.2.18 Rate of Change ............................................ 96 3.2.19 Rate of Change Percentage ................................. 97 3.2.20 Rate of Change Ratio ...................................... 98 3.2.21 Rate of Change Ratio 100 Scale ............................ 99 3.2.22 Relative Strength Index ................................... 100 3.2.23 Stochastic Indicator ...................................... 100 3.2.24 Stochastic Fast Indicator ................................. 102 3.2.25 Stochastic RSI Indicator .................................. 103 3.2.26 Rate of Change for a Triple EMA ........................... 104 3.2.27 Ultimate Oscillator ....................................... 106 3.2.28 Williams’ %R Indicator .................................... 107 3.3 Volume Indicators ................................................ 108 3.3.1 Accumulation and Distribution Indicator .................... 109 3.3.2 Accumulation and Distribution Oscillator ................... 110 3.3.3 On Balance Volume .......................................... 111 3.4 Volatility Indicators ............................................ 113 3.4.1 True Range Indicator ....................................... 113 3.4.2 Average True Range ......................................... 113 3.4.3 Normalized Average True Range .............................. 115 3.5 Cycle Indicators ................................................. 116 3.5.1 Fisher Transform ........................................... 117 3.5.2 Hilbert Transform – Dominant Cycle Period .................. 118 3.5.3 Hilbert Transform – Dominant Cycle Phase ................... 119 3.5.4 Hilbert Transform – Phasor.................................. 120 3.5.5 Hilbert Transform – Sine Wave .............................. 120 3.5.6 Hilbert Transform – Trend Mode.............................. 121 3.6 Price Transforms ................................................. 122 3.6.1 Average Price .............................................. 122 3.6.2 Median Price ............................................... 123 3.6.3 Typical Price .............................................. 123 3.6.4 Weighted Close Price ....................................... 125 4 Vanilla Options ........................................................ 127 4.1 Introduction to Options .......................................... 127 4.1.1 Option Payoffs ............................................. 128 4.1.2 Option Value ............................................... 128 4.2 Pricing European Options ......................................... 130 4.2.1 Black-Scholes Model ........................................ 130 4.2.2 Generalized Black-Scholes Model ............................ 131 4.2.3 Black-Scholes Greeks ....................................... 132 4.2.3.1 Delta ................................................ 132 4.2.3.2 Gamma ................................................ 132 4.2.3.3 Theta ................................................ 133 4.2.3.4 Rho .................................................. 133 4.2.3.5 Vega ................................................. 134 4.2.4 Implied Volatility ......................................... 134 4.2.5 Pricing Engines ............................................ 135 4.2.5.1 Integral Method ...................................... 136 4.2.5.2 Binomial Trees ....................................... 136 4.2.5.3 Finite-Difference Method ............................. 138 4.2.6 Results in 2D Plot ......................................... 141 4.2.6.1 Delta ................................................ 142 4.2.6.2 Gamma ................................................ 143 4.2.6.3 Theta ................................................ 144 4.2.6.4 Rho .................................................. 146 4.2.6.5 Vega ................................................. 146 4.2.6.6 Implied Volatility ................................... 147 4.2.7 Results in 3D Plot ......................................... 149 4.2.7.1 Delta ................................................ 151 4.2.7.2 Gramma ............................................... 152 4.2.7.3 Theta ................................................ 152 4.2.7.4 Rho .................................................. 154 4.2.7.5 Vega ................................................. 155 4.2.7.6 Implied volatility ................................... 155 4.3 Pricing American Options ......................................... 157 4.3.1 BAW Approximation .......................................... 157 4.3.2 Pricing Engines ............................................ 158 4.3.3 Results in 2D Plot ......................................... 158 4.3.3.1 Delta ................................................ 160 4.3.3.2 Gamma ................................................ 161 4.3.3.3 Theta ................................................ 163 4.3.3.4 Implied Volatility ................................... 164 4.3.4 Results in 3D Plot ......................................... 165 4.3.4.1 Delta ................................................ 166 4.3.4.2 Gamma ................................................ 167 4.3.4.3 Theta ................................................ 169 4.3.4.4 Implied Volatility ................................... 170 5 Barrier Options......................................................... 171 5.1 Standard Barrier Option Formulas ................................. 171 5.2 Pricing Engines .................................................. 174 5.3 Results in 2D Plot ............................................... 174 5.3.1 NPV for Call Options ....................................... 174 5.3.2 NPV for Put Options ........................................ 177 5.3.3 Delta for Call Options ..................................... 180 5.3.4 Delta for Put Options ...................................... 183 5.3.5 Gamma for Call Options ..................................... 185 5.3.6 Gamma for Put Options ...................................... 187 5.3.7 Theta for Call Options ..................................... 190 5.3.8 Theta for Put Options ...................................... 192 5.4 Results in 3D Plot ............................................... 195 5.4.1 NPV for Call Options ....................................... 195 5.4.2 NPV for Put Options ........................................ 198 5.4.3 Delta for Call Options ..................................... 200 5.4.4 Delta for Put Options ...................................... 203 5.4.5 Gamma for Call Options ..................................... 205 5.4.6 Gamma for Put Options ...................................... 208 5.4.7 Theta for Call Options ..................................... 210 5.4.8 Theta for Put Options ...................................... 213 6 Fixed Income Instruments ............................................... 217 6.1 Simple Bonds Pricing ............................................. 217 6.1.1 Discounting Factors ........................................ 218 6.1.2 Pricing Bonds with Flat Rates .............................. 219 6.1.3 Pricing Bonds with a Simple Rate Curve ..................... 221 6.1.4 Yield to Maturity .......................................... 222 6.2 Bonds with Embedded Options ...................................... 223 6.2.1 Callable Bonds ............................................. 223 6.2.2 Convertible Bonds .......................................... 225 6.3 Zero-Coupon Yield Curve........................................... 227 6.3.1 Treasury Zero-Coupon Yield Curve ........................... 228 6.3.2 Interbank Zero-Coupon Yield Curve .......................... 231 6.3.3 Credit with Z-Spread ....................................... 232 6.4 CDS Pricing ...................................................... 234 6.4.1 Hazard Rate and Default Probability ........................ 234 6.4.2 Risky Annuities and Durations .............................. 237 6.4.3 CDS Pricing Engine ......................................... 238 6.5 Interest Rates ................................................... 240 6.5.1 Forward Rate Agreement ..................................... 240 6.5.2 Credit Valuation Adjustment ................................ 242 7 Trading Strategies and Backtesting ..................................... 243 7.1 Trading Strategy Identification .................................. 243 7.2 Trading Signals .................................................. 246 7.2.1 Crossover Signals .......................................... 246 7.2.2 Zscore Signals ............................................. 250 7.3 Trend-Following Trading Strategies ............................... 253 7.3.1 APO Crossover .............................................. 253 7.3.2 CCI Crossover .............................................. 257 7.3.3 Fisher Crossover ........................................... 258 7.3.4 Fisher-NATR Crossover ...................................... 259 7.3.5 MA-MFI Crossover ........................................... 261 7.3.6 MA2 Crossover .............................................. 262 7.3.7 MA2-NATR Crossover ......................................... 263 7.3.8 MA3 Crossover .............................................. 265 7.3.9 MACD Crossover ............................................. 266 7.3.10 MAMA Crossover ............................................ 268 7.3.11 PPO Crossover ............................................. 269 7.3.12 PPO-NATR Crossover ........................................ 271 7.3.13 SAR Crossover ............................................. 272 7.3.14 SAR-ADX Crossover ......................................... 273 7.4 Mean-Reversion Trading Strategies ................................ 275 7.4.1 Aroon Oscillator ........................................... 275 7.4.2 CCI Zscore ................................................. 277 7.4.3 CMO Zscore ................................................. 278 7.4.4 Linear Regression .......................................... 280 7.4.5 MA Zscore .................................................. 281 7.4.6 PPO Zscore ................................................. 282 7.4.7 ROC Zscore ................................................. 283 7.4.8 RSI Zscore ................................................. 284 7.4.9 Stochastic Zscore .......................................... 285 7.4.10 TRIX Zscore ............................................... 286 7.4.11 Williams’ %R Zscore ....................................... 287 Index .................................................................... 289
Introduction
        Overview
        Gincker Finance Playground
        Gincker Finance Playground
        Is This Book for You
        How This Book is Organized
Overview
Welcome to Learn Quantitative Finance without Code. This book describes a powerful quantitative finance playground – Gincker Finance, which lets you build advanced financial applications without needing to write a single line of code. With this playground, you can access various market data APIs, create interactive stock charts, perform technical analysis using various technical indicators, backtest trading strategies, and valuate different asset types using build-in pricing engines. I hope that this book will be useful for quant developers, quant analysts, individual traders, 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, and physics modeling, but lack knowledge and experience in programming and 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 without needing to write any code.
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, or engineering. 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 techniques to become a well-equipped individual quant trader without writing a single line of code.
Gincker Finance Playground
The Gincker Finance playground (https://finance.gincker.com) is a free online tool in quantitative finance. It is a software as a template (SaaT) based platform for technical analysis. It converts different financial software packages and applications into standard templates that expose a simple and common interface. This way, you can create stock charts, perform technical analysis, and backtest trading strategies by simply entering a stock ticker and specifying corresponding parameters without needing to write a single line of code.
The Gincker Finance playground implements a variety of templates for stock charts, technical indicators, trading strategies, a backtesting system, and various pricing engines for valuation of different asset types such as equity options and fixed income instruments. Unlike other financial analysis tools that require strong programming background and complicated market data management, the Gincker Finance playground will perform complex financial analysis automatically in just one mouse click.
The Gincker Finance playground also allows you to save your work as a unique URL called gincker. This gincker link not only provides output results, but also brings the development environment directly to users. This means that the gincker can deliver dynamic content: users can use it to regenerate, manipulate, modify, and customize financial analysis to meet their own requirements. The gincker can also be embedded in websites or incorporated into applications. Users can bookmark the ginckers for later use or share them with friends, colleagues, and other users.
Another unique feature of the gincker is that exchanging ginckers is faster and more efficient than transmitting large graphics or data files over the Internet, because ginckers have a small file size – a gincker simply contains a single line of text with the format: “https://finance.gincker.com/ {template}?{xxxxxxxxxx}”. This is even shorter than a Tweet.
The Gincker Finance playground is a web-based platform; there is no need to install it on a local machine. You can simply go to https://finance.gincker.com, select a proper template, and perform various financial analysis out of the box. On the other hand, traditional software usually consists of independent packages installed on a local machine. To create different types of technical analysis or trading strategies, you need to install different packages, which take up a lot of computer resources and time for configuring.
What this Book Includes
This book provides you with
- A complete, in-depth instruction to practical quantitative finance. You can consider this book as a walkthrough user manual for the Gincker Finance playground. After reading this book and running the example programs, you will be able to create various sophisticated business applications in quantitative finance without needing to write a single line of code.
- The walkthrough examples contained in this book allow you to explore technical analysis approaches and understand how the algorithms work in quantitative finance. You can modify the input parameters and customize the output results to form the basis of your own applications in quantitative finance. Some of the examples with different templates on the Gincker Finance playground provided in this book are already sophisticated projects in quantitative finance that you can use directly in your own real-world business applications.
- The dynamic output results from the Gincker Finance playground is a simple URL link called gincker. This gincker can be embedded in external websites, incorporated into desktop applications, or integrated into research papers or reports. You can also bookmark the gincker for later use or share it with friends, colleagues, or other users. The advantage of ginckers over the static output results from traditional software packages is that the gincker can deliver dynamic graphics content – users can use the gincker to regenerate, manipulate, modify, or customize the results to meet their requirements.
Is This Book for You?
You do not have to be an experienced quant developer or analyst to use this book. I designed this book to be useful to people of all levels of financial background without any requirement on programming skill. In fact, I believe that if you have some prior experience with quantitative analysis and development, you will be able to sit down in front of your computer, open your web browser follow the examples provided in this book, and quickly become proficient with the templates implemented on the Gincker Finance playground. For those of you who are already experienced quant analyst or developer, I believe this book has much to offer as well. A great deal of the information in this book about technical analysis in quantitative finance is not available in other tutorial and reference books. In addition, you can use most of the walkthrough examples in this book directly in your own real-world application development. This book will provide you with a level of detail, explanation, instruction, and samples that will enable you to do just about anything related to quantitative finance application development without needing to write any code.
Perhaps you are a scientist, an engineer, a mathematician, or a student, rather than a professional quant developer/analyst; nevertheless, this book is still a good bet for you. Quantitative finance is a complicated field. It usually requires not only a solid background in math and finance, but also a strong programming skill, which may prevent you from entering the quantitative finance field. The Gincker Finance playground made it possible for beginners to get familiar with the field. You can use this playground as a bridge into the quantitative finance you want to work in. You can also consider Gincker Finance as a powerful calculator in quantitative finance – as long as you select a template and enter input parameters, the playground will give you the results immediately. This way, you can gradually learn how the financial models, algorithms, and pricing engines work.
How the Book Is Organized
This book is organized into seven chapters, each of which covers a different topic about quantitative finance. The following summaries of each chapter should give you an overview of the book’s content:
Chapter 1, Overview of Gincker Finance
This chapter provides an overview of the Gincker Finance playground. The playground converts different financial software packages and applications into standard templates, and exposes a simple and common interface that allows you to create stock charts, perform technical analysis, backtest trading strategies.
Chapter 2, Market Data
This chapter contains various walkthrough examples that show how to access the free online market data from different API providers. These market data include the historical end of the day (EOD) stock data, intraday data, interest rate data, and foreign exchange rate data.
Chapter 3, Technical Indicators
This chapter discusses various technical indicators, which are often used in quantitative analysis. A technical indicator is just a mathematical calculation based on historical market data, which is used to predict market trend and direction. I will show you how to use the Gincker Finance playground to calculate different indicators and display the results on your screen.
Chapter 4, Vanilla Options
This chapter covers the Black-Scholes formula used for vanilla options pricing. It shows how to use the Gincker Finance playground to calculate 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 vanilla options.
Chapter 5, Barrier Options
Barrier option is a type of exotic option because it is more complex than basic vanilla options. Its payoff depends on whether or not the underlying asset has reached or exceeded a predetermined price. This chapter shows how to use Gincker Finance to valuate Barrier options.
Chapter 6, 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 Gincker Finance playground to price these complex financial instruments.
Chapter 7, 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.