-
Notifications
You must be signed in to change notification settings - Fork 2
/
risk.py
40 lines (29 loc) · 895 Bytes
/
risk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
"""Risk.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1mLFpTMFs_Qd_6pjmfEdDSKnZS5EB3k7B
"""
import pandas as pd
import yfinance as yf
import matplotlib.pyplot as plt
import seaborn
import numpy as np
stocks = ["GOOGL","AMZN","TSLA"]
stocks = yf.download(stocks, start ="2015-01-01",end = "2020-12-08")
data = stocks.loc[:,"Close"].copy()
data.plot(figsize = (17,8), fontsize = 18)
plt.style.use("seaborn")
plt.show()
data.head()
data.pct_change()
com = data.pct_change().dropna()
com.describe()
sum = com.describe().T.loc[:,["mean","std"]]
sum
sum["mean"]=sum["mean"]*252
sum["std"]=sum["std"]*np.sqrt(252)
sum
sum.plot.scatter(x = "std", y = "mean", figsize =(12,8), s = 50, fontsize =15)
for i in sum.index:
plt.annotate(i,xy=(sum.loc[i,"std"]+0.002,sum.loc[i,"mean"]+0.002),size=15)