antitheft159 commited on
Commit
d2506e0
1 Parent(s): 3dd938a

Create stockcomparison.py

Browse files
Files changed (1) hide show
  1. stockcomparison.py +37 -0
stockcomparison.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import yfinance
2
+
3
+ stocks = ['ARM', 'META', 'SPY', 'TSLA']
4
+
5
+ data = yfinance.download(stocks,
6
+ '2024-04-01',
7
+ '2024-05-09')['Close']
8
+
9
+ returns = data.pct_change()
10
+ returns.head()
11
+
12
+ returns = returns.dropna()
13
+ returns.head()
14
+
15
+ average_daily_returns = returns.mean()
16
+ print(average_daily_returns)
17
+
18
+ standard_deviation_daily_returns = returns.std()
19
+ print(standard_deviation_daily_returns)
20
+
21
+ import numpy
22
+ weights = numpy.array([0.25, 0.25, 0.25, 0.25])
23
+
24
+ covariance_matrix = (returns.cov())*250
25
+
26
+ expected_portfolio_performace = numpy.sum(average_daily_returns * weights)
27
+ print(expected_portfolio_performance)
28
+
29
+ returns['Portfolio Returns'] = returns.dot(weights)
30
+ returns.head()
31
+
32
+ daily_cumulative_returns = (1+returns).cumprod()
33
+ print(daily_cumulative_returns)
34
+
35
+ daily_cumulative_returns.tail()
36
+
37
+