
Python for Finance

The following program aims at generating an efficient frontier based on two stocks with known means, standard deviations, and correlation. We have just six input values: two means, two standard deviations, the correlation (ρ), and the number of simulations. To generate the correlated y1 and y2 time series, we generate the uncorrelated x1 and x2 series first. Then, we apply the following formulae:
Another important issue is how to construct an objective function to minimize. Our objective function is the standard deviation of the portfolio in addition to a penalty that is defined as the scaled absolute deviation from our target portfolio mean.
In other words, we minimize both the risk of the portfolio and the deviation of our portfolio return from our target return, as shown in the following code:
import numpy as np import scipy as sp import pandas as pd import matplotlib.pyplot as plt from datetime import datetime...
Change the font size
Change margin width
Change background colour