Reader small image

You're reading from  Python for Finance Cookbook

Product typeBook
Published inJan 2020
Reading LevelIntermediate
PublisherPackt
ISBN-139781789618518
Edition1st Edition
Languages
Right arrow
Author (1)
Eryk Lewinson
Eryk Lewinson
author image
Eryk Lewinson

Eryk Lewinson received his master's degree in Quantitative Finance from Erasmus University Rotterdam. In his professional career, he has gained experience in the practical application of data science methods while working in risk management and data science departments of two "big 4" companies, a Dutch neo-broker and most recently the Netherlands' largest online retailer. Outside of work, he has written over a hundred articles about topics related to data science, which have been viewed more than 3 million times. In his free time, he enjoys playing video games, reading books, and traveling with his girlfriend.
Read more about Eryk Lewinson

Right arrow

Multi-Factor Models

This chapter is devoted to estimating various factor models in Python. The idea behind these models is to explain the excess returns (over the risk-free rate) of a certain portfolio or asset using one or more factors (features). These risk factors can be considered a tool for understanding the cross-section of (expected) returns.

In general, factor models can be used to identify interesting assets that can be added to the investment portfolio, which— in turn—should lead to better performing portfolios.

By the end of this chapter, we will have constructed some of the most popular factor models. We will start with the simplest, yet very popular, one-factor model (the Capital Asset Pricing Model, or CAPM) and then explain how to estimate more advanced three-, four-, and five-factor models. We will also cover the interpretation of what these factors...

Implementing the CAPM in Python

In this recipe, we learn how to estimate the famous Capital Asset Pricing Model (CAPM) and obtain the beta coefficient. This model represents the relationship between the expected return on a risky asset and the market risk (also known as systematic or undiversifiable risk). CAPM can be considered a one-factor model, on top of which more complex factor models were built.

CAPM is represented by the following equation:

Here, E(ri) denotes the expected return on asset i, rf is the risk-free rate (such as a government bond), E(rm) is the expected return on the market, and is the beta coefficient.

Beta can be interpreted as the level of the asset return's sensitivity, as compared to the market in general. Some possible examples include:

  • beta <= -1: The asset moves in the opposite direction as the benchmark and in a greater amount than the...

Implementing the Fama-French three-factor model in Python

In their famous paper, Fama and French expanded the CAPM model by adding two additional factors explaining the excess returns of an asset or portfolio. The factors they considered are:

  • The market factor (MKT): It measures the excess return of the market, analogical to the one in the CAPM.
  • The size factor, SMB (Small Minus Big): It measures the excess return of stocks with a small market cap over those with a large market cap.
  • The value factor, HML (High Minus Low): It measures the excess return of value stocks over growth stocks. Value stocks have a high book-to-market ratio, while the growth stocks are characterized by a low ratio.

The model can be represented as follows:

Or in its simpler form:

Here, E(ri) denotes the expected return on asset i, rf is the risk-free rate (such as a government bond), and α is...

Implementing the rolling three-factor model on a portfolio of assets

In this recipe, we learn how to estimate the three-factor model in a rolling fashion. What we mean by rolling is that we always consider an estimation window of a constant size (60 months, in this case) and roll it through the entire dataset, one period at a time. A potential reason for doing such an experiment is to test the stability of the results.

In contrast to the previous recipes, this time, we use portfolio returns instead of a single asset. To keep things simple, we assume that our allocation strategy is to have an equal share of the total portfolio's value in each of the following stocks: Amazon, Google, Apple, and Microsoft. For this experiment, we use stock prices from the years 2010-2018.

How to...

Implementing the four- and five-factor models in Python

In this recipe, we implement two extensions of the Fama-French three-factor model.

Carhart's Four-Factor model: The underlying assumption of this extension is that, within a short period of time, a winner stock will remain a winner, while a loser will remain a loser. An example of a criterion for classifying winners and losers could be the last 12-month cumulative total returns. After identifying the two groups, we long the winners and short the losers within a certain holding period.

The momentum factor (WML; Winners Minus Losers) measures the excess returns of the winner stocks over the loser stocks in the past 12 months (please refer to the See also section of this recipe for references on the calculations of the momentum factor).

The four-factor model can be expressed:

Fama-French's Five-Factor model: Fama...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Python for Finance Cookbook
Published in: Jan 2020Publisher: PacktISBN-13: 9781789618518
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Eryk Lewinson

Eryk Lewinson received his master's degree in Quantitative Finance from Erasmus University Rotterdam. In his professional career, he has gained experience in the practical application of data science methods while working in risk management and data science departments of two "big 4" companies, a Dutch neo-broker and most recently the Netherlands' largest online retailer. Outside of work, he has written over a hundred articles about topics related to data science, which have been viewed more than 3 million times. In his free time, he enjoys playing video games, reading books, and traveling with his girlfriend.
Read more about Eryk Lewinson