<jupyter_start><jupyter_text>Obtaining the Efficient Frontier - Part II *Suggested Answers follow (usually there are multiple ways to solve a problem in Python).* Ok, let’s continue the exercise from the last lecture. You already downloaded the data and generated two random weightings.<jupyter_code>import numpy as np
import pandas as pd
from pandas_datareader import data as wb
import matplotlib.pyplot as plt
%matplotlib inline

assets = ['WMT', 'FB']
pf_data = pd.DataFrame()

for a in assets:
    pf_data[a] = wb.DataReader(a, data_source = 'yahoo', start = '2014-1-1')['Adj Close']
log_returns = np.log(pf_data / pf_data.shift(1))

num_assets = len(assets)

weights = np.random.random(num_assets)
weights /= np.sum(weights)
weights<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09908735332464146, 'fraction_numerical': 0.009126466753585397, 'mean_word_length': 5.453781512605042, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '388833', 'license': 'Apache-2.0', 'n_tokens_mistral': 263, 'n_tokens_neox': 251, 'n_words': 84, 'path': '23 - Python for Finance/5_Markowitz Portfolio Optimization/3_Obtaining the Efficient Frontier in Python - Part II (5:18)/Obtaining the Efficient Frontier - Part II - Exercise.ipynb', 'repo_name': 'olayinka04/365-data-science-courses', 'size': '767'}