• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Efficient Frontier looks weird

Hi all, could you please help me identify if there is anything wrong in my code? And if nothing is wrong, could you please let me know why the graph looks weird?

Efficient Frontier:
# -*- coding: utf-8 -*-
Created on Wed Jan 13 17:03:13 2021


import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from math import *
from scipy.optimize import minimize
pd.set_option('display.max_rows', 10)
pd.set_option('display.max_columns', 10)
import pickle

from pandas_datareader import data as wb
for t in tickers:
    data[t]=wb.DataReader(t, data_source='yahoo', start='07-5-2012', end='5-7-2020')['Adj Close']
all_weights=np.zeros((num_ports, len(data.columns)))
for ind in range(num_ports):
    vol_array[ind]=sqrt(np.dot(weights.T, np.dot(weights, log_returns.cov()*252)))
plt.scatter(vol_array, ret_array, c=sharpe_array, s=8)


  • efficient frontier.png
    efficient frontier.png
    10.8 KB · Views: 1,155
what do you think looks weird about the graph?

it looks like you're graphing convex combinations for 2 stocks based on 5,000 draws from a bi-variate uniform distribution from (0,1].

I hadn't really thought of this for looking at the efficient frontier. Usually, I'd optimize over the range of min asset return to max asset return to get an idea.

This is an interesting approach. I see the weights are normalized to 1, which is good. You annulized returns and vol, which is also good?

I guess one asset had a negative ann return -4% over the period and the other was positive ann 4%, which would tie out w/ your graph.

What insight are you hoping to make from the graph? There's no optimization that I see, so the covariance of the assets is only included implicitly in the results of the risk / return trade off. A traditional MVO would minimize risk for a given return target - which would cut off the bottom little curve because it's clearly not optimal.
Last edited: