A production-quality CLI application for stock analysis and probabilistic forecasting using AI-powered news analysis and Monte Carlo simulation.
- News Analysis: Fetches and analyzes recent news from Google News RSS and optionally Alpaca News API
- AI-Powered Insights: Uses OpenRouter (supports Claude, GPT-4, Gemini, Llama, etc.) to extract events, sentiment, and generate bull/bear cases with citations
- Quantile Forecasting: LightGBM-based quantile regression for p10/p50/p90 return predictions
- Monte Carlo Simulation: Student-t distributed path simulation for intra-month risk metrics
- Rich Terminal Output: Beautiful, user-friendly terminal output with tables and colors
- Multiple Output Formats: Terminal display, JSON export, Markdown reports, and PNG plots
- Python 3.11 or higher
- An OpenRouter API key (required)
- Alpaca API credentials (optional, for additional news sources)
- Clone or download the project:
cd finlg- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Create a
.envfile with your API keys:
# Required - Get your key at https://openrouter.ai/
OPENROUTER_API_KEY=your_openrouter_api_key_here
# Optional - Choose your model (default: anthropic/claude-sonnet-4-20250514)
OPENROUTER_MODEL=anthropic/claude-sonnet-4-20250514
# Optional - for additional news sources
ALPACA_API_KEY=your_alpaca_key_here
ALPACA_API_SECRET=your_alpaca_secret_here
# Optional - customize directories
FINBOT_CACHE_DIR=.cache
FINBOT_OUT_DIR=./outYou can use any model available on OpenRouter by setting OPENROUTER_MODEL:
anthropic/claude-sonnet-4-20250514(default)anthropic/claude-3-opusopenai/gpt-4-turboopenai/gpt-4ogoogle/gemini-prometa-llama/llama-3-70b-instruct- And many more at https://openrouter.ai/models
# Run the interactive wizard
python -m finlg wizard
# Quick forecast for a stock
python -m finlg forecast GOOGL
# Generate full report with plots
python -m finlg report GOOGL --out ./reports/googlAnalyze news and market context for a stock:
python -m finlg analyze GOOGL --news-days 30
python -m finlg analyze AAPL --news-days 14 --json
python -m finlg analyze GOOGL --lang tr # Turkish outputOptions:
--news-days, -n: Days of news to analyze (default: 30)--lang, -l: Output language:en(English) ortr(Turkish) (default: en)--json, -j: Output as JSON--verbose, -v: Enable verbose logging
Generate probabilistic forecast with Monte Carlo simulation:
python -m finlg forecast GOOGL
python -m finlg forecast MSFT --horizon 21 --paths 10000
python -m finlg forecast TSLA --json
python -m finlg forecast GOOGL --lang tr # Turkish outputOptions:
--horizon, -h: Forecast horizon in trading days (default: 21)--paths, -p: Number of Monte Carlo simulation paths (default: 10000)--news-days, -n: Days of news to analyze (default: 30)--lang, -l: Output language:en(English) ortr(Turkish) (default: en)--json, -j: Output as JSON--verbose, -v: Enable verbose logging
Generate complete report with plots and save to files:
python -m finlg report GOOGL --out ./out
python -m finlg report NVDA --horizon 42 --out ./reports/nvda
python -m finlg report GOOGL --lang tr --out ./out # Turkish reportOptions:
--out, -o: Output directory (default: ./out)--horizon, -h: Forecast horizon in trading days (default: 21)--paths, -p: Number of Monte Carlo simulation paths (default: 10000)--news-days, -n: Days of news to analyze (default: 30)--lang, -l: Output language:en(English) ortr(Turkish) (default: en)--json, -j: Output as JSON--verbose, -v: Enable verbose logging
Output files:
summary.md: Markdown report with citationsforecast.json: Machine-readable forecast dataplots/price_forecast.png: Price chart with forecast bandplots/return_distribution.png: End-of-period return histogramplots/drawdown_distribution.png: Max drawdown distributionplots/news_timeline.png: News intensity and sentiment timeline
Guided wizard for step-by-step configuration:
python -m finlg wizard
python -m finlg wizard --lang tr # Turkish promptsOptions:
--lang, -l: Output language:en(English) ortr(Turkish) (default: en)
The wizard will prompt you for:
- Language selection
- Stock ticker
- News analysis period
- Forecast horizon
- Number of simulation paths
- Output directory
- Output format preferences
Finbot supports multiple languages for terminal output and markdown reports:
- English (en): Default language
- Turkish (tr): Full Turkish translation
# Turkish forecast
python -m finlg forecast GOOGL --lang tr
# Turkish report with plots
python -m finlg report GOOGL --lang tr --out ./out
# Interactive wizard in Turkish
python -m finlg wizard --lang trNote: JSON output keys remain in English for API stability, regardless of the --lang setting.
π FINBOT FORECAST: GOOGL
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
As of: 2024-01-15 14:30
Last Price: $175.42
Horizon: 21 trading days
News analyzed: 45 articles (30 days)
π End-of-Period Return Forecast
ββββββββββββββββββ¬ββββββββββ¬βββββββββββββββ
β Percentile β Return β Price Target β
ββββββββββββββββββΌββββββββββΌβββββββββββββββ€
β p10 (bearish) β -5.2% β $166.30 β
β p50 (median) β +2.1% β $179.10 β
β p90 (bullish) β +8.7% β $190.68 β
ββββββββββββββββββ΄ββββββββββ΄βββββββββββββββ
π Intra-Period Risk Metrics
ββββββββββββββββ¬βββββββββ¬βββββββββββββββββββ
β Metric β p50 β p90 (worst case) β
ββββββββββββββββΌβββββββββΌβββββββββββββββββββ€
β Max Drawdown β -3.2% β -8.5% β
β Lowest Point β -2.1% β -6.8% β
β Highest Pointβ +4.5% β +9.2% β
ββββββββββββββββ΄βββββββββ΄βββββββββββββββββββ
π Bull Case
1. Strong Q4 earnings beat expectations with cloud revenue growth
2. AI product launches gaining market traction
3. Cost optimization measures showing results
4. Positive analyst upgrades from major firms
5. Search market share remains dominant
π» Bear Case
1. Regulatory scrutiny increasing in multiple jurisdictions
2. Competition in AI space intensifying
3. Advertising revenue growth slowing
4. Antitrust concerns may limit acquisitions
5. Macro headwinds affecting ad spending
β οΈ Unknowns & Risks
β’ Pending DOJ antitrust case outcome
β’ AI investment ROI timeline uncertain
π― Upcoming Catalysts
β’ Q4 earnings report (late January)
β’ Google I/O developer conference
β οΈ DISCLAIMER: This is not financial advice. Forecasts are probabilistic
estimates based on historical data and news analysis. Past performance
does not guarantee future results. Always do your own research.
| Variable | Required | Default | Description |
|---|---|---|---|
OPENROUTER_API_KEY |
Yes | - | OpenRouter API key for LLM |
OPENROUTER_MODEL |
No | anthropic/claude-sonnet-4.5 |
Model to use |
ALPACA_API_KEY |
No | - | Alpaca API key for news |
ALPACA_API_SECRET |
No | - | Alpaca API secret |
FINBOT_CACHE_DIR |
No | .cache |
Cache directory |
FINBOT_OUT_DIR |
No | ./out |
Default output directory |
finlg/
βββ __init__.py # Package initialization
βββ __main__.py # Entry point for python -m finlg
βββ cli.py # Typer CLI application
βββ config.py # Environment and settings
βββ features.py # Feature engineering
βββ data/
β βββ prices.py # yfinance price fetching
β βββ news.py # Google RSS + Alpaca news
βββ nlp/
β βββ events.py # OpenRouter LLM integration
βββ models/
β βββ quantile.py # LightGBM quantile regression
βββ sim/
β βββ path_sim.py # Monte Carlo simulation
βββ reporting/
β βββ plots.py # Matplotlib visualizations
β βββ render.py # Rich terminal + Markdown output
βββ utils/
βββ cache.py # Disk caching utilities
-
Feature Engineering: Calculates momentum (5/20/60-day returns), volatility (20/60-day), drawdown, volume z-score, benchmark relative strength, and news-derived features (event counts, sentiment scores)
-
Quantile Regression: Uses LightGBM to predict p10/p50/p90 quantiles of forward returns over the specified horizon
-
Monte Carlo Simulation: Generates price paths using:
- EWMA volatility estimation
- Student-t distributed returns (df=5) for heavy tails
- Drift derived from the quantile model's median prediction
-
Data Collection: Fetches news from Google News RSS (primary) and Alpaca News API (optional)
-
Event Extraction: Uses LLM via OpenRouter to classify each article by:
- Event type (earnings, guidance, regulation, etc.)
- Direction (bullish, bearish, mixed, unknown)
- Time horizon (0-2d, 3-10d, 11-30d, 31-90d)
- Confidence score (0-1)
-
Analysis Generation: Synthesizes bull/bear cases with citations from the analyzed articles
Finbot caches:
- Price data (1 hour TTL)
- News fetches (30 minutes TTL)
- LLM responses (24 hours TTL)
Cache is stored in .cache/ by default. Clear cache by deleting this directory.
- Not Financial Advice: This tool is for informational purposes only
- Historical Data: Forecasts are based on historical patterns which may not repeat
- News Coverage: Google News RSS may not capture all relevant news
- Model Uncertainty: Quantile predictions have inherent uncertainty
MIT License - See LICENSE file for details.
Contributions are welcome! Please ensure:
- Code follows existing style (type hints, docstrings)
- Tests pass (when added)
- Documentation is updated