Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from pandas_datareader import data as web | |
import matplotlib.pyplot as plt | |
from datetime import datetime | |
start = datetime(2016,1,1) | |
end = datetime(2017,1,1) | |
assets = ['AAPL', 'FB', 'TSLA'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import python's number crunchers | |
from pandas_datareader import data as web | |
import pandas as pd | |
import numpy as np | |
assets = ['AAPL', 'GM', 'GE', 'FB', 'WMT'] | |
df = pd.DataFrame() | |
for stock in assets: |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
#store the variables in arrays | |
prob = np.array([0.25, 0.5, 0.25]) | |
rate_1 = np.array([0.05, 0.075, 0.10]) | |
rate_2 = np.array([0.2, 0.15, 0.1]) | |
# expected return of each investment | |
expected_return1 = np.sum(prob * rate_1) | |
expected_return2 = np.sum(prob * rate_2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# expected return of the equally weighted portfolio | |
weights = np.array([0.5, 0.5]) | |
individual_returns = np.array([rate_1, rate_2]) | |
portfolio_returns = np.dot(weights, individual_returns) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# covariance matrix given probabilities | |
cov_matrix = np.cov(rate_1, rate_2, ddof=0, aweights=prob) |
OlderNewer