-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (44 loc) · 1.91 KB
/
main.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
46
47
48
49
50
51
52
"""Main script that executes the trading analysis."""
import logging
from config import CONFIG
import user_inputs
import tickers
import ticker_data
import classifier
import indicators
import reporting
@user_inputs.handle_keyboard_interrupt
def main():
"""
Main function that executes the trading analysis.
"""
choice = user_inputs.prompt_ticker_selection()
# Get the tickers list based on the user's choice
selected_tickers = tickers.get_tickers_list_by_index(int(choice)-1)
list_name = CONFIG['TICKERS_LISTS'][int(choice) - 1].get('name')
# If user chose a custom list, get the selected tickers
if list_name == 'custom_tickers':
selected_tickers = user_inputs.prompt_custom_ticker_list()
logging.info("Starting trading analysis...")
# Initialize yfinance session
ticker_data.initialize_session()
# Send a warmup request
r = ticker_data.fetch_ticker('SPY')
logging.info("Warmup request sent: %s", r.info.get('symbol'))
# Apply fundamental filters
compliant_tickers_data = ticker_data.fetch_tickers_by_fundamentals(selected_tickers)
compliant_ticker_names = [ticker.ticker for ticker in compliant_tickers_data]
num_compliant_tickers = len(compliant_ticker_names)
if not compliant_tickers_data:
logging.info("No tickers passed the fundamental filters.")
return
else:
logging.info("%d tickers passed the fundamental filters", num_compliant_tickers)
# Identify the top movers
bullish_tickers, bearish_tickers = classifier.get_bullish_bearish(compliant_tickers_data)
buy_targets, sell_targets = indicators.generate_targets(bullish_tickers, bearish_tickers)
trading_signals = reporting.format_summary(compliant_tickers_data, buy_targets, sell_targets)
# Print the summary
reporting.print_trading_signals(trading_signals)
if __name__ == "__main__":
main()