File size: 4,625 Bytes
c9de3d0
2af8939
a2e1a85
 
 
c9de3d0
2af8939
abbfda6
1a5a085
c9de3d0
a2e1a85
 
c9de3d0
 
a2e1a85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0728cc2
a2e1a85
 
 
 
 
 
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
138
139
140
141
142
143
144
145
146
147
148
149
---
title: FinRobot-claude-4.1-opus
emoji: πŸ€–
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 5.47.0
app_file: app1 - claude-4.1-opus.py
python_version: 3.12
pinned: false
license: apache-2.0
short_description: AI-powered stock market analysis
---

# πŸ€– FinRobot Forecaster

**AI-powered stock market analysis and prediction using advanced language models**

This application provides comprehensive stock market analysis by combining:
- **Real-time stock data** from Alpha Vantage via RapidAPI (premium access)
- **Company news and sentiment** from Finnhub
- **Advanced AI analysis** using Google's Gemini models
- **Financial metrics** and historical performance data

## πŸš€ Features

- **Stock Price Analysis**: Analyze historical price movements over configurable time periods
- **News Sentiment Analysis**: Process company news and market sentiment
- **AI-Powered Predictions**: Generate detailed market outlook using advanced language models
- **Financial Metrics**: Optional inclusion of basic financial data
- **Interactive Interface**: User-friendly Gradio interface for easy interaction

## πŸ“Š How It Works

1. **Data Collection**: Fetches historical stock data and recent company news
2. **Analysis**: Processes the data to identify trends and patterns
3. **AI Processing**: Uses Google Gemini to analyze the information
4. **Prediction**: Generates structured predictions with:
   - Positive developments
   - Potential concerns
   - Price outlook with rationale

## πŸ› οΈ Setup Instructions

### For HuggingFace Spaces:

1. **Fork this repository** to your HuggingFace account
2. **Deploy**: The Space will automatically build and deploy
   - All API keys are already included in the code
   - Multiple API keys are used for better reliability and rate limit handling

### For Local Development:

1. **Clone the repository**:
   ```bash
   git clone <your-repo-url>
   cd finrobot-forecaster
   ```

2. **Install dependencies**:
   ```bash
   pip install -r requirements.txt
   ```

3. **Run the application**:
   ```bash
   python app.py
   ```

## πŸ“ˆ Usage Examples

Try these popular stocks:
- **AAPL** (Apple Inc.)
- **MSFT** (Microsoft Corporation)
- **GOOGL** (Alphabet Inc.)
- **TSLA** (Tesla Inc.)
- **NVDA** (NVIDIA Corporation)

## βš™οΈ Configuration Options

- **Stock Symbol**: Enter any valid ticker symbol
- **Historical Weeks**: Choose 1-6 weeks of historical data
- **Basic Financials**: Toggle to include financial metrics

## πŸ”§ Technical Details

- **Framework**: Gradio 5.46.0
- **AI Model**: Google Gemini 1.5 Pro
- **Data Sources**: RapidAPI Alpha Vantage (2 premium keys), Finnhub
- **Language**: Python 3.11
- **Container**: Optimized for HuggingFace Spaces

## πŸ“ Output Format

The AI analysis provides:

### [Positive Developments]
- Key positive factors affecting the stock
- Recent achievements and growth indicators

### [Potential Concerns]
- Risk factors and challenges
- Market uncertainties

### [Prediction & Analysis]
- One-week price outlook
- Detailed rationale for the prediction

## πŸ›‘οΈ Error Handling & Reliability

### **Comprehensive Fallback System:**
1. **Primary**: RapidAPI Alpha Vantage (2 premium keys with rotation)
2. **Secondary**: Mock data generation (for demonstration)

### **API Key Rotation:**
- **Automatic switching** between RapidAPI keys
- **Rate limit detection** with seamless fallback
- **Comprehensive logging** for debugging
- **Graceful degradation** at every level

### **Error Recovery:**
- **Timeout handling**: 30-second timeout with retry logic
- **Rate limit management**: Automatic key rotation
- **Mock data fallback**: App always works for demonstration
- **User-friendly messages**: Clear error communication

## ⚠️ Disclaimer

**Important**: This application is for educational and research purposes only. The predictions and analysis provided should not be considered as financial advice. Always consult with qualified financial professionals before making investment decisions.

## 🀝 Contributing

Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.

## πŸ“„ License

This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.

## πŸ™ Acknowledgments

- [FinRobot](https://github.com/AI4Finance-Foundation/FinRobot) - Original FinRobot framework
- [Google AI](https://ai.google.dev/) - Gemini models
- [RAPID] - Stock market data
- [Finnhub](https://finnhub.io/) - Financial news and data
- [Gradio](https://gradio.app/) - Web interface framework

---

**Built with ❀️ for the financial AI community**