Spaces:
Running
Running
| """ | |
| Saturday Fundamental Analysis Runner | |
| Runs fundamental analysis for all tickers in available_tickers table | |
| """ | |
| import sys | |
| from pathlib import Path | |
| from datetime import datetime | |
| # Add src to path | |
| sys.path.insert(0, str(Path(__file__).parent / "src")) | |
| from db.local_database import LocalDatabase, DatabaseEntry, DataType | |
| from fundamental_analysis.decision_maker import evaluate_stock | |
| def run_saturday_analysis(): | |
| """Run fundamental analysis for all available tickers""" | |
| print("=" * 60) | |
| print("π SATURDAY FUNDAMENTAL ANALYSIS") | |
| print("=" * 60) | |
| print(f"Started at: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n") | |
| # Initialize database | |
| db = LocalDatabase() | |
| # Get all available tickers | |
| tickers = db.get_all_available_tickers() | |
| total = len(tickers) | |
| if total == 0: | |
| print("β οΈ No tickers found in available_tickers table") | |
| print("Run: python src/db/populate_tickers.py alpaca") | |
| return | |
| print(f"π Found {total} tickers to analyze\n") | |
| success_count = 0 | |
| error_count = 0 | |
| skipped_count = 0 | |
| for i, ticker in enumerate(tickers, 1): | |
| try: | |
| print(f"[{i}/{total}] Analyzing {ticker}...", end=" ") | |
| # Run fundamental analysis | |
| result = evaluate_stock(ticker, compare_to_sector=False) | |
| if result is None: | |
| print("β οΈ Skipped (no data)") | |
| skipped_count += 1 | |
| continue | |
| # Save to database | |
| today = datetime.now().date().isoformat() | |
| entry = DatabaseEntry( | |
| date=today, | |
| data_type=DataType.FUNDAMENTAL.value, | |
| ticker=ticker, | |
| data=result, | |
| metadata={'saturday_batch': True} | |
| ) | |
| if db.save(entry, expiry_days=7): | |
| print(f"β {result.get('recommendation', 'HOLD')}") | |
| success_count += 1 | |
| else: | |
| print("β Save failed") | |
| error_count += 1 | |
| except Exception as e: | |
| print(f"β Error: {e}") | |
| error_count += 1 | |
| print("\n" + "=" * 60) | |
| print("π ANALYSIS COMPLETE") | |
| print("=" * 60) | |
| print(f"β Success: {success_count}") | |
| print(f"β οΈ Skipped: {skipped_count}") | |
| print(f"β Errors: {error_count}") | |
| print(f"π Total: {total}") | |
| print(f"\nCompleted at: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") | |
| print("=" * 60) | |
| if __name__ == "__main__": | |
| run_saturday_analysis() | |