10.12.2019 Views

Python for Finance

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Multifactor Models and Performance Measures

Introduction to the Fama-French

three-factor model

Before discussing the Fama-French three-factor model and other models, let's look at

a general equation for a three-factor linear model:

Here, y is the dependent variable, α is the intercept, x1, x2, and x3 are three

independent variables, β1, β2 and β3 are three coefficients, and ε is a random factor.

In other words, we try to use three independent variables to explain one dependent

variable. The same as a one-factor linear model, the graphical presentation of this

three-factor linear model is a straight line, in a four-dimensional space, and the

power of each independent variable is a unit as well. Here, we will use two simple

examples to show how to run multifactor linear regression. For the first example,

we have the following code. The values have no specific meaning and readers could

enter their own values as well:

from pandas.stats.api import ols

import pandas as pd

y = [0.065, 0.0265, -0.0593, -0.001,0.0346]

x1 = [0.055, -0.09, -0.041,0.045,0.022]

x2 = [0.025, 0.10, 0.021,0.145,0.012]

x3= [0.015, -0.08, 0.341,0.245,-0.022]

df=pd.DataFrame({"y":y,"x1":x1, 'x2':x2,'x3':x3})

result=ols(y=df['y'],x=df[['x1','x2','x3']])

print(result)

In the preceding program, the pandas.stats.api.ols() function is applied. OLS

stands for Ordinary Least Squares. For more information about the OLS model, we

could use the help() function; see the following two lines of code. For brevity, the

output is not shown here:

from pandas.stats.api import ols

help(ols)

[ 214 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!