-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain4.py
More file actions
37 lines (28 loc) · 1.07 KB
/
Copy pathmain4.py
File metadata and controls
37 lines (28 loc) · 1.07 KB
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
import yfinance as yf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use('fast')
nvda = yf.download("NVDA")
nvda = nvda.Close.to_frame()
nvda["d_returns"] = np.log(nvda.div(nvda.shift(1)))# daily returns
nvda.dropna(inplace=True)
print(nvda.d_returns.sum()) #if $1 invested since start
print(np.exp(nvda.d_returns.sum()))
nvda["cumm_returns"] = nvda.d_returns.cumsum().apply(np.exp)
nvda.d_returns.mean()*252 #annual average returns
nvda.d_returns.std()*np.sqrt(252)# annual standard deviation
#calculate drawdowns
nvda["cummmax"] = nvda.cumm_returns.cummax()
nvda[["cummmax","cumm_returns"]].plot(figsize=(12,8), title="NVDIA buy and hold+cummmax", fontsize=12)
nvda["drawdown"] = nvda["cummmax"] - nvda["cumm_returns"]
print(nvda.drawdown.max())
print(nvda.drawdown.idxmax())
print(nvda.loc[(nvda.index=='2022-10-14')])
print(nvda.loc[(nvda.index<='2022-10-14')])
nvda["drawdown%"] = (nvda["cummmax"] - nvda["cumm_returns"])/nvda["cummmax"]
print(nvda["drawdown%"].max())
print(nvda["drawdown%"].idxmax())
print(nvda)
#plt.show()