#### Overview of this book

Python for Finance
Credits
Acknowledgments
www.PacktPub.com
Preface
Free Chapter
Introduction and Installation of Python
13 Lines of Python to Price a Call Option
Introduction to Modules
Statistical Analysis of Time Series
Index

## Constructing an efficient frontier

In finance, constructing an efficient frontier is always a challenging job. This is especially true with real-world data. In this section, we discuss the estimation of a variance-covariance matrix and its optimization, finding an optimal portfolio, and constructing an efficient frontier with stock data downloaded from Yahoo! Finance.

### Estimating a variance-covariance matrix

When a return matrix is given, we could estimate its variance-covariance matrix. For a given set of weights, we could further estimate the portfolio variance. The formulae to estimate the variance and standard deviation for returns from a single stock are given as follows:

Here, Ri is the stock return for period i, is their mean, and n is the number of the observations. For an n-stock portfolio, we have the following formulae:

The variance of a two-stock portfolio is given as follows:

Here, is the covariance between stocks 1 and 2, is the correlation coefficient between stocks 1 and 2....