stockcomparison / stockcomparison.py
antitheft159's picture
Create stockcomparison.py
d2506e0 verified
raw
history blame
776 Bytes
import yfinance
stocks = ['ARM', 'META', 'SPY', 'TSLA']
data = yfinance.download(stocks,
'2024-04-01',
'2024-05-09')['Close']
returns = data.pct_change()
returns.head()
returns = returns.dropna()
returns.head()
average_daily_returns = returns.mean()
print(average_daily_returns)
standard_deviation_daily_returns = returns.std()
print(standard_deviation_daily_returns)
import numpy
weights = numpy.array([0.25, 0.25, 0.25, 0.25])
covariance_matrix = (returns.cov())*250
expected_portfolio_performace = numpy.sum(average_daily_returns * weights)
print(expected_portfolio_performance)
returns['Portfolio Returns'] = returns.dot(weights)
returns.head()
daily_cumulative_returns = (1+returns).cumprod()
print(daily_cumulative_returns)
daily_cumulative_returns.tail()