Skip to main content

Über dieses Buch

Quantitative Finance with R offers a winning strategy for devising expertly-crafted and workable trading models using the R open source programming language, providing readers with a step-by-step approach to understanding complex quantitative finance problems and building functional computer code.



1. An Overview

My primary intent in writing this book is to provide the reader with basic programming, financial, and mathematical tools that can be successfully leveraged both in industry and academia. I cover the use of the R programming language, as well as the R environment as a means for manipulating financial market data and for solving a subset of problems that quants and traders typically encounter in their day-to-day activities. The chapters that follow should be treated as a tutorial on a recommended set of tools that I have personally found useful and that have served me well during the last few years of my career as a quant trader/developer. I am writing this book from the vantage point of a quant practitioner and not that of an academic. A significant portion of the content is based on my lecture notes from a graduate level class in quantitative finance that I teach on a part-time basis at Loyola University in Chicago.

Harry Georgakopoulos

2. Tools of the Trade

The primary tools that quants and traders rely on to perform their daily activities include intuition, data, computer hardware, computer software, mathematics, and finance. They utilize these tools in ingenious ways as a means to an end. The end, of course, is the generation of consistent profits in the financial markets. Many traders have done well for themselves by relying on intuition alone. But intuition alone, on average, will not yield superior results. A tool chest of sorts is required in order to maximize the quant/trader’s chances of producing consistent and favorable outcomes. A programming language is one such tool. In this book, we will learn how to wield the R programming language for the purposes of manipulating data, performing math operations, automating workflows, displaying informative visualizations, creating reproducible results, and doing lots of other cool stuff

Harry Georgakopoulos

3. Working with Data

Financial data comes in many forms and sizes. In this book, we will mostly concern ourselves with a particular class of financial data, namely, time series data. Time series data contain a time component that is primarily used as an index (key) to identify other meaningful values. Another way to think about time series data is as key-value pairs in which the key is the time, and the value is either a single entry or a vector of entries. The following table gives an idea of what a typical daily time series for the stock AAPL might look like. This data was downloaded from Yahoo1 in the form of a .csv file.

Harry Georgakopoulos

4. Basic Statistics and Probability

We now know how to convert raw time series data into xts objects, how to use quantmod to retrieve data from local and remote repos, and how to create basic visualizations with ggplot2. The next logical step is to start looking for patterns in the data that might reveal exploitable trading opportunities. This course of action inevitably leads us to ask questions about the statistical nature of financial time series.

Harry Georgakopoulos

5. Intermediate Statistics and Probability

This chapter will explore the statistical nature of stock prices and address the topics of stationarity, normality, and autocorrelation of stock returns. These are important concepts that will enable us to perform statistical inference1 and pave the way for the construction of trading strategies.

Harry Georgakopoulos

6. Spreads, Betas and Risk

In the previous chapter, we concluded that no noticeable autocorrelation exists for daily returns. This implies that knowing the level of the previous day’s return does not help us in forecasting today’s return. The hypothesis we will formulate in this section is that we can artificially create a time series that is somewhat forecastable. We will refer to this new time series as a spread. The claim we are making is that a stock spread has a better chance of being tradable than an individual outright does. This, of course, is a subjective and suspicious statement in and of itself. Bear with me, though for the remainder of the chapter. I am mostly interested in conveying a methodology of thinking rather than a concrete fact about price behavior.

Harry Georgakopoulos

7. Backtesting with Quantstrat

Backtesting is one of those activities in quantitative finance and trading that takes up a significant amount of time. It refers to the systematic methodology of testing out a particular hypothesis about market dynamics on a subset of historical data. It is akin to the scientific method in that it attempts to reconcile hypotheses with empirical observations. The end goal is to form predictions that result in profitable outcomes. The implicit assumption in all of this is that the historical patterns will, with high probability, manifest again in the future. The ultimate goal is to be ready to capitalize on those patterns when they are again detected

Harry Georgakopoulos

8. High-Frequency Data

Up to this point, we have only focused on daily equity data for our analysis. This low-granularity data comes with the nice property of being homogeneously spaced out in time. Homogeneity in time is a property that makes the mathematics of time series analysis much easier to handle. Tick data, on the other hand, is inherently nonhomogenous in time. Events such as book updates, trade updates, exchange messages and high-frequency news feeds, tend to arrive at arbitrary times.

Harry Georgakopoulos

9. Options

Options are tradable derivate contracts that “derive” their value from other underlying instruments. Wikipedia defines these instruments as follows: “An Option is a contract which gives the buyer (the owner) the right, but not the obligation, to buy or sell an underlying asset or instrument at a specified strike price on or before a specified date [130].” They are similar to futures contracts in that they provide a mechanism to purchase or sell a certain physical or financial asset sometime in the future at a price that is known in the present.Whereas futures obligate the contract holder to purchase or sell the underlying asset at the agreed-upon price, options provide the “option” to purchase or sell the underlying asset at the agreed-upon price. This added flexibility or optionality comes at a premium. No upfront exchange of funds is required in order for the buyer and seller to enter into a futures contract. To buy an options contract, however, the buyer has to pay a premium. Similarly, the person selling the option contract gets to collect the premium.

Harry Georgakopoulos

10. Optimization

Consider the problem of finding the best asset allocation strategy across thousands of investments so that the highest return is achieved with the smallest amount of risk. The methodology for coming up with the answer to such a question requires us to select parameters that will maximize/minimize our objective function subject to constraints. In our case, a plausible objective function might be the total return of a strategy divided by the maximum drawdown of the strategy over a predefined period. The constraints might be the total amount of capital devoted to each asset within the portfolio. Many interesting problems in finance, computer science, and the physical sciences rely on the specification and use of models. These mathematical formulations typically include one or more parameters as part of their input specifications. Optimization is a branch of mathematics that provides techniques for finding the best values for these parameters under constraints. R has a slew of packages that deal with optimization, and we will look at a few of them in this chapter.

Harry Georgakopoulos

11. Speed, Testing, and Reporting

This last chapter could have easily been labeled as the “Miscellaneous” chapter. It includes a discussion on three important topics of which R programmers need to be aware. The first topic addresses the methods that can be used to speed up native R code and to allow interoperability between R and C++. The second topic revolves around the idea of test-driven development and how R users can write unit tests in order to improve their code quality and reliability. The chapter ends with a discussion on research reproducibility and reporting within R. [41]. A streamlined and elegant reporting workflow has been made possible by the recent work of the RStudio team and packages such as sweave and knitr [145, 146]. The generation of a sample .pdf report via knitr is presented at the end of the chapter.

Harry Georgakopoulos


Weitere Informationen

Premium Partner

micromStellmach & BröckersBBL | Bernsau BrockdorffMaturus Finance GmbHPlutahww hermann wienberg wilhelmAvaloq Evolution AG

BranchenIndex Online

Die B2B-Firmensuche für Industrie und Wirtschaft: Kostenfrei in Firmenprofilen nach Lieferanten, Herstellern, Dienstleistern und Händlern recherchieren.



Blockchain-Effekte im Banking und im Wealth Management

Es steht fest, dass Blockchain-Technologie die Welt verändern wird. Weit weniger klar ist, wie genau dies passiert. Ein englischsprachiges Whitepaper des Fintech-Unternehmens Avaloq untersucht, welche Einsatzszenarien es im Banking und in der Vermögensverwaltung geben könnte – „Blockchain: Plausibility within Banking and Wealth Management“. Einige dieser plausiblen Einsatzszenarien haben sogar das Potenzial für eine massive Disruption. Ein bereits existierendes Beispiel liefert der Initial Coin Offering-Markt: ICO statt IPO.
Jetzt gratis downloaden!