-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stocks.py
45 lines (24 loc) · 838 Bytes
/
Stocks.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
41
42
43
44
45
from yahoo_fin import stock_info as si
import yfinance
from complex_mathematics.ml import LinearRegression
import numpy as np
import pandas as pd
tickers = si.tickers_nasdaq()
rate = {}
n = 0
for ticker in tickers:
tick = yfinance.Ticker(ticker)
try:
y = np.array(tick.history("6mo")["High"])
step = 180/y.shape[0]
X = np.arange(step, 180 + step, step).reshape(-1, 1)
model = LinearRegression(optimization_method="NormalEquations")
model.fit(X, y)
rate[ticker] = model.params[0]
except:
None
n += 1
print("Percent Done: ", n*100/len(tickers))
rate = dict(sorted(rate.items(), key=lambda item: item[1], reverse=True))
df = pd.DataFrame(rate.items(), columns=["Ticker", "Rate"])
df.to_csv("Stock_Rate_Changes", index=False)