feat: Add detailed stock view function and interactive signal exploration

This commit is contained in:
Bobby Abellana (aider) 2025-02-06 22:19:55 -08:00
parent bf4c5a1b94
commit bb3c5fe933
No known key found for this signature in database
GPG Key ID: 647714CC45F3647B

View File

@ -162,6 +162,53 @@ def get_valid_tickers(min_price: float, max_price: float, min_volume: int, inter
print(f"Error fetching tickers: {str(e)}")
return []
def view_stock_details(ticker: str, interval: str, start_date: datetime, end_date: datetime) -> None:
"""Display detailed data for a single stock"""
print(f"\n📊 Detailed Analysis for {ticker}")
print(f"Interval: {interval}")
print(f"Date Range: {start_date.date()} to {end_date.date()}")
try:
# Get price data
df = get_stock_data(ticker, start_date, end_date, interval)
if df.empty:
print("No data found for this stock")
return
print("\nData Sample:")
print("First 5 rows:")
print(df.head().to_string())
print("\nLast 5 rows:")
print(df.tail().to_string())
print(f"\nTotal rows: {len(df)}")
# Calculate SunnyBands
sunny = SunnyBands()
results = sunny.calculate(df)
# Get last values
last_price = df.iloc[-1]
last_bands = results.iloc[-1]
print("\nLatest Values:")
print(f"Date: {last_price['date']}")
print(f"Open: ${last_price['open']:.2f}")
print(f"High: ${last_price['high']:.2f}")
print(f"Low: ${last_price['low']:.2f}")
print(f"Close: ${last_price['close']:.2f}")
print(f"Volume: {last_price['volume']:,}")
print(f"\nSunnyBands Indicators:")
print(f"DMA: ${last_bands['dma']:.2f}")
print(f"Upper Band: ${last_bands['upper_band']:.2f}")
print(f"Lower Band: ${last_bands['lower_band']:.2f}")
print(f"Bullish Signal: {'Yes' if last_bands['bullish_signal'] else 'No'}")
print(f"Bearish Signal: {'Yes' if last_bands['bearish_signal'] else 'No'}")
except Exception as e:
print(f"Error analyzing {ticker}: {str(e)}")
def run_sunny_scanner(min_price: float, max_price: float, min_volume: int) -> None:
"""Run the SunnyBand scanner and save results"""
print(f"\nInitializing scan for stocks between ${min_price:.2f} and ${max_price:.2f}")
@ -292,3 +339,22 @@ def run_sunny_scanner(min_price: float, max_price: float, min_volume: int) -> No
if not bullish_signals and not bearish_signals:
print("\nNo signals found for today.")
else:
while True:
view_choice = input("\nWould you like to view detailed data for a stock? (Enter ticker or 'n' to exit): ").upper()
if view_choice == 'N':
break
# Check if ticker is in our signals
found = False
for signals in [bullish_signals, bearish_signals]:
for signal in signals:
if signal['ticker'] == view_choice:
found = True
view_stock_details(view_choice, interval, start_date, end_date)
break
if found:
break
if not found:
print(f"Ticker {view_choice} not found in signals list.")