forked from borisng0112ca/StockScreeningScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex6m.py
28 lines (21 loc) · 779 Bytes
/
index6m.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
import yfinance as yf
import datetime as dt
import pandas as pd
def sixMonthIndex(tickers, percent):
try:
start = dt.datetime.today() - dt.timedelta(180)
end = dt.datetime.today()
cl_price = pd.DataFrame()
print('\n')
for ticker in tickers:
cl_price[ticker]= yf.download(ticker, start, end, period = "6mo")["Adj Close"]
list6m = cl_price.iloc[-1] / cl_price.iloc[0]
list6m.sort_values(ascending = False, inplace = True)
print("\n6 month Index")
print(list6m)
finalList = list(list6m.index.values)
finalList = finalList[:int(len(finalList)*percent)]
return finalList
except:
print("\nError in 6-month Index calculation...")
return []