Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Python for Finance

You're reading from   Mastering Python for Finance Understand, design, and implement state-of-the-art mathematical and statistical applications used in finance with Python

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher Packt
ISBN-13 9781784394516
Length 340 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (12) Chapters Close

Preface 1. Python for Financial Applications FREE CHAPTER 2. The Importance of Linearity in Finance 3. Nonlinearity in Finance 4. Numerical Procedures 5. Interest Rates and Derivatives 6. Interactive Financial Analytics with Python and VSTOXX 7. Big Data with Python 8. Algorithmic Trading 9. Backtesting 10. Excel with Python Index

Multivariate linear regression of factor models

Many Python packages such as SciPy come with several variants of regression functions. In particular, the statsmodels package is a complement to SciPy with descriptive statistics and estimation of statistical models. The official page for statsmodels is http://statsmodels.sourceforge.net/.

In this example, we will use the ols function of the statsmodels module to perform an ordinary least squares regression and view its summary.

Let's assume that you have implemented an APT model with seven factors that return the values of Y. Consider the following set of data collected over 9 time periods, Multivariate linear regression of factor models to Multivariate linear regression of factor models. X1 to X7 are independent variables observed at each period. The regression problem is therefore structured as:Multivariate linear regression of factor models.

A simple ordinary least squares regression on values of X and Y can be performed with the following code:

""" Least squares regression with statsmodels """
import numpy as np
import statsmodels.api as sm
...
lock icon The rest of the chapter is locked
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.
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 $19.99/month. Cancel anytime