-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
137 lines (106 loc) · 4.68 KB
/
Copy pathfunctions.py
File metadata and controls
137 lines (106 loc) · 4.68 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from yahooquery import Ticker
import requests
#--------------------------------------------------------------------------------------
# https://github.com/rreichel3/US-Stock-Symbols
#--------------------------------------------------------------------------------------
def download_nasdaq_symbols(path):
"""
Download nasdaq symbols.
Parameters:
path(string): path of file to write list of downloaded symbols
Returns:
None
"""
url = 'https://raw.githubusercontent.com/rreichel3/US-Stock-Symbols/main/nasdaq/nasdaq_tickers.txt'
response = requests.get(url)
with open(path, 'wb') as f:
f.write(response.content)
#--------------------------------------------------------------------------------------
def is_symbol_equity(symbol_name, ticker_data):
#--------------------------------------------------------------------------------------
"""
Is the symbol name an equity (versus ETF, etc)?
Parameters:
symbol(string): The symbol name, e.g. AAPL
width (Ticker): Ticker object with data for the above symbol
Returns:
boolean: True if symbol is an equity, otherwise false
"""
if (ticker_data.price[symbol_name]['quoteType'] == "EQUITY"):
return True
else:
return False
#--------------------------------------------------------------------------------------
def is_last_close_greater_than_min(symbol_name, ticker_data, min_val):
#--------------------------------------------------------------------------------------
"""
Is the close of the symbol > minimum value?
Parameters:
symbol(string): The symbol name, e.g. AAPL
width (Ticker): Ticker object with data for the above symbol
min_val(int): Minimum value to compare
Returns:
boolean: True if close is > minimum value, otherwise false
"""
if (ticker_data.price[symbol_name]['regularMarketDayLow'] > min_val):
return True
else:
return False
#--------------------------------------------------------------------------------------
def is_price_volume_greater_than_min(symbol_name, ticker_data, min_val):
#--------------------------------------------------------------------------------------
"""
Is price * volume > minimum?
Parameters:
symbol(string): The symbol name, e.g. AAPL
width (Ticker): Ticker object with data for the above symbol
min_val(int): Minimum value to compare
Returns:
boolean: True if price * volume > minimum, otherwise false
"""
# Price times volume
price_volume = ticker_data.price[symbol_name]['regularMarketPrice'] * ticker_data.price[symbol_name]['regularMarketVolume']
if (price_volume > min_val):
return True
else:
return False
#--------------------------------------------------------------------------------------
def is_new_net_high(symbol_name, ticker_data):
#--------------------------------------------------------------------------------------
"""
Is the symbol a new 52-week high?
Parameters:
symbol(string): The symbol name, e.g. AAPL
width (Ticker): Ticker object with data for the above symbol
Returns:
boolean: True if symbol is 52-week high, otherwise false
"""
if (ticker_data.price[symbol_name]['regularMarketDayHigh'] >= ticker_data.summary_detail[symbol_name]['fiftyTwoWeekHigh']):
return True
else:
return False
#--------------------------------------------------------------------------------------
def is_new_net_low(symbol_name, ticker_data):
#--------------------------------------------------------------------------------------
"""
Is the symbol a new 52-week low?
Parameters:
symbol(string): The symbol name, e.g. AAPL
width (Ticker): Ticker object with data for the above symbol
Returns:
boolean: True if symbol is 52-week low, otherwise false
"""
if (ticker_data.price[symbol_name]['regularMarketDayLow'] <= ticker_data.summary_detail[symbol_name]['fiftyTwoWeekLow']):
return True
else:
return False
#--------------------------------------------------------------------------------------
# Test code
#--------------------------------------------------------------------------------------
# sym_name = 'aapl'
# ticker_data = Ticker(sym_name)
# print(f'Symbol name {sym_name} is of type {ticker_data.price[sym_name]["quoteType"]}')
# print(sym.price)
#print(f'Is {sym_name} an equity:', is_symbol_equity(sym_name, ticker_data))
# print(f'Is {sym_name} close > 2:', is_last_close_greater_than_min(sym_name, ticker_data, 2))
# print(f'Is {sym_name} price * volume > 10,000:', is_price_volume_greater_than_min(sym_name, ticker_data, 10000))