sqa 0.0.24 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.goose/memory/development.txt +3 -0
- data/.semver +6 -0
- data/ARCHITECTURE.md +648 -0
- data/CHANGELOG.md +82 -0
- data/CLAUDE.md +653 -0
- data/COMMITS.md +196 -0
- data/DATAFRAME_ARCHITECTURE_REVIEW.md +421 -0
- data/NEXT-STEPS.md +154 -0
- data/README.md +812 -262
- data/TASKS.md +358 -0
- data/TEST_RESULTS.md +140 -0
- data/TODO.md +42 -0
- data/_notes.txt +25 -0
- data/bin/sqa-console +11 -0
- data/data/talk_talk.json +103284 -0
- data/develop_summary.md +313 -0
- data/docs/advanced/backtesting.md +206 -0
- data/docs/advanced/ensemble.md +68 -0
- data/docs/advanced/fpop.md +153 -0
- data/docs/advanced/index.md +112 -0
- data/docs/advanced/multi-timeframe.md +67 -0
- data/docs/advanced/pattern-matcher.md +75 -0
- data/docs/advanced/portfolio-optimizer.md +79 -0
- data/docs/advanced/portfolio.md +166 -0
- data/docs/advanced/risk-management.md +210 -0
- data/docs/advanced/strategy-generator.md +158 -0
- data/docs/advanced/streaming.md +209 -0
- data/docs/ai_and_ml.md +80 -0
- data/docs/api/dataframe.md +1115 -0
- data/docs/api/index.md +126 -0
- data/docs/assets/css/custom.css +88 -0
- data/docs/assets/js/mathjax.js +18 -0
- data/docs/concepts/index.md +68 -0
- data/docs/contributing/index.md +60 -0
- data/docs/data-sources/index.md +66 -0
- data/docs/data_frame.md +317 -97
- data/docs/factors_that_impact_price.md +26 -0
- data/docs/finviz.md +11 -0
- data/docs/fx_pro_bit.md +25 -0
- data/docs/genetic_programming.md +104 -0
- data/docs/getting-started/index.md +123 -0
- data/docs/getting-started/installation.md +229 -0
- data/docs/getting-started/quick-start.md +244 -0
- data/docs/i_gotta_an_idea.md +22 -0
- data/docs/index.md +163 -0
- data/docs/indicators/index.md +97 -0
- data/docs/indicators.md +110 -24
- data/docs/options.md +8 -0
- data/docs/strategies/bollinger-bands.md +146 -0
- data/docs/strategies/consensus.md +64 -0
- data/docs/strategies/custom.md +310 -0
- data/docs/strategies/ema.md +53 -0
- data/docs/strategies/index.md +92 -0
- data/docs/strategies/kbs.md +164 -0
- data/docs/strategies/macd.md +96 -0
- data/docs/strategies/market-profile.md +54 -0
- data/docs/strategies/mean-reversion.md +58 -0
- data/docs/strategies/rsi.md +95 -0
- data/docs/strategies/sma.md +55 -0
- data/docs/strategies/stochastic.md +63 -0
- data/docs/strategies/volume-breakout.md +54 -0
- data/docs/tags.md +7 -0
- data/docs/true_strength_index.md +46 -0
- data/docs/weighted_moving_average.md +48 -0
- data/examples/README.md +354 -0
- data/examples/advanced_features_example.rb +350 -0
- data/examples/fpop_analysis_example.rb +191 -0
- data/examples/genetic_programming_example.rb +148 -0
- data/examples/kbs_strategy_example.rb +208 -0
- data/examples/pattern_context_example.rb +300 -0
- data/examples/rails_app/Gemfile +34 -0
- data/examples/rails_app/README.md +416 -0
- data/examples/rails_app/app/assets/javascripts/application.js +107 -0
- data/examples/rails_app/app/assets/stylesheets/application.css +659 -0
- data/examples/rails_app/app/controllers/analysis_controller.rb +11 -0
- data/examples/rails_app/app/controllers/api/v1/stocks_controller.rb +227 -0
- data/examples/rails_app/app/controllers/application_controller.rb +22 -0
- data/examples/rails_app/app/controllers/backtest_controller.rb +11 -0
- data/examples/rails_app/app/controllers/dashboard_controller.rb +21 -0
- data/examples/rails_app/app/controllers/portfolio_controller.rb +7 -0
- data/examples/rails_app/app/views/analysis/show.html.erb +209 -0
- data/examples/rails_app/app/views/backtest/show.html.erb +171 -0
- data/examples/rails_app/app/views/dashboard/index.html.erb +118 -0
- data/examples/rails_app/app/views/dashboard/show.html.erb +408 -0
- data/examples/rails_app/app/views/errors/show.html.erb +17 -0
- data/examples/rails_app/app/views/layouts/application.html.erb +60 -0
- data/examples/rails_app/app/views/portfolio/index.html.erb +33 -0
- data/examples/rails_app/bin/rails +6 -0
- data/examples/rails_app/config/application.rb +45 -0
- data/examples/rails_app/config/boot.rb +5 -0
- data/examples/rails_app/config/database.yml +18 -0
- data/examples/rails_app/config/environment.rb +11 -0
- data/examples/rails_app/config/routes.rb +26 -0
- data/examples/rails_app/config.ru +8 -0
- data/examples/realtime_stream_example.rb +274 -0
- data/examples/sinatra_app/Gemfile +22 -0
- data/examples/sinatra_app/QUICKSTART.md +159 -0
- data/examples/sinatra_app/README.md +461 -0
- data/examples/sinatra_app/app.rb +344 -0
- data/examples/sinatra_app/config.ru +5 -0
- data/examples/sinatra_app/public/css/style.css +659 -0
- data/examples/sinatra_app/public/js/app.js +107 -0
- data/examples/sinatra_app/views/analyze.erb +306 -0
- data/examples/sinatra_app/views/backtest.erb +325 -0
- data/examples/sinatra_app/views/dashboard.erb +419 -0
- data/examples/sinatra_app/views/error.erb +58 -0
- data/examples/sinatra_app/views/index.erb +118 -0
- data/examples/sinatra_app/views/layout.erb +61 -0
- data/examples/sinatra_app/views/portfolio.erb +43 -0
- data/examples/strategy_generator_example.rb +346 -0
- data/hsa_portfolio.csv +11 -0
- data/justfile +0 -0
- data/lib/api/alpha_vantage_api.rb +462 -0
- data/lib/sqa/backtest.rb +329 -0
- data/lib/sqa/data_frame/alpha_vantage.rb +43 -65
- data/lib/sqa/data_frame/data.rb +92 -0
- data/lib/sqa/data_frame/yahoo_finance.rb +35 -43
- data/lib/sqa/data_frame.rb +148 -243
- data/lib/sqa/ensemble.rb +359 -0
- data/lib/sqa/fpop.rb +199 -0
- data/lib/sqa/gp.rb +259 -0
- data/lib/sqa/indicator.rb +5 -8
- data/lib/sqa/init.rb +15 -8
- data/lib/sqa/market_regime.rb +240 -0
- data/lib/sqa/multi_timeframe.rb +379 -0
- data/lib/sqa/pattern_matcher.rb +497 -0
- data/lib/sqa/portfolio.rb +260 -6
- data/lib/sqa/portfolio_optimizer.rb +377 -0
- data/lib/sqa/risk_manager.rb +442 -0
- data/lib/sqa/seasonal_analyzer.rb +209 -0
- data/lib/sqa/sector_analyzer.rb +300 -0
- data/lib/sqa/stock.rb +67 -125
- data/lib/sqa/strategy/bollinger_bands.rb +42 -0
- data/lib/sqa/strategy/consensus.rb +5 -2
- data/lib/sqa/strategy/kbs_strategy.rb +470 -0
- data/lib/sqa/strategy/macd.rb +46 -0
- data/lib/sqa/strategy/mp.rb +1 -1
- data/lib/sqa/strategy/stochastic.rb +60 -0
- data/lib/sqa/strategy/volume_breakout.rb +57 -0
- data/lib/sqa/strategy.rb +5 -0
- data/lib/sqa/strategy_generator.rb +947 -0
- data/lib/sqa/stream.rb +361 -0
- data/lib/sqa/version.rb +1 -7
- data/lib/sqa.rb +23 -16
- data/main.just +81 -0
- data/mkdocs.yml +288 -0
- data/trace.log +0 -0
- metadata +261 -51
- data/bin/sqa +0 -6
- data/lib/patches/dry-cli.rb +0 -228
- data/lib/sqa/activity.rb +0 -10
- data/lib/sqa/cli.rb +0 -62
- data/lib/sqa/commands/analysis.rb +0 -309
- data/lib/sqa/commands/base.rb +0 -139
- data/lib/sqa/commands/web.rb +0 -199
- data/lib/sqa/commands.rb +0 -22
- data/lib/sqa/constants.rb +0 -23
- data/lib/sqa/indicator/average_true_range.rb +0 -33
- data/lib/sqa/indicator/bollinger_bands.rb +0 -28
- data/lib/sqa/indicator/candlestick_pattern_recognizer.rb +0 -60
- data/lib/sqa/indicator/donchian_channel.rb +0 -29
- data/lib/sqa/indicator/double_top_bottom_pattern.rb +0 -34
- data/lib/sqa/indicator/elliott_wave_theory.rb +0 -57
- data/lib/sqa/indicator/exponential_moving_average.rb +0 -25
- data/lib/sqa/indicator/exponential_moving_average_trend.rb +0 -36
- data/lib/sqa/indicator/fibonacci_retracement.rb +0 -23
- data/lib/sqa/indicator/head_and_shoulders_pattern.rb +0 -26
- data/lib/sqa/indicator/market_profile.rb +0 -32
- data/lib/sqa/indicator/mean_reversion.rb +0 -37
- data/lib/sqa/indicator/momentum.rb +0 -28
- data/lib/sqa/indicator/moving_average_convergence_divergence.rb +0 -29
- data/lib/sqa/indicator/peaks_and_valleys.rb +0 -29
- data/lib/sqa/indicator/predict_next_value.rb +0 -202
- data/lib/sqa/indicator/relative_strength_index.rb +0 -47
- data/lib/sqa/indicator/simple_moving_average.rb +0 -24
- data/lib/sqa/indicator/simple_moving_average_trend.rb +0 -32
- data/lib/sqa/indicator/stochastic_oscillator.rb +0 -68
- data/lib/sqa/indicator/true_range.rb +0 -39
- data/lib/sqa/trade.rb +0 -26
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
# SQA Web Application
|
|
2
|
+
|
|
3
|
+
A modern web interface for the SQA (Simple Qualitative Analysis) stock analysis library. Built with Sinatra, featuring interactive charts powered by Plotly.js, and a responsive UI for comprehensive stock market analysis.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### 📊 Interactive Dashboard
|
|
8
|
+
- **Candlestick & Line Charts** - Visualize price movements with professional financial charts
|
|
9
|
+
- **Volume Analysis** - Track trading volume with color-coded bars
|
|
10
|
+
- **Technical Indicators** - RSI, MACD, SMA, EMA, Bollinger Bands
|
|
11
|
+
- **Key Metrics** - 52-week high/low, current RSI, market regime
|
|
12
|
+
- **Real-time Data** - Fetch latest stock data from Alpha Vantage or Yahoo Finance
|
|
13
|
+
|
|
14
|
+
### 🤖 Strategy Backtesting
|
|
15
|
+
- **6 Built-in Strategies** - RSI, MACD, SMA, EMA, Bollinger Bands, KBS
|
|
16
|
+
- **Detailed Metrics** - Total return, Sharpe ratio, max drawdown, win rate
|
|
17
|
+
- **Strategy Comparison** - Compare all strategies side-by-side
|
|
18
|
+
- **Performance Analytics** - Profit factor, average win/loss, total trades
|
|
19
|
+
|
|
20
|
+
### 📈 Market Analysis
|
|
21
|
+
- **Market Regime Detection** - Identify bull/bear/sideways markets
|
|
22
|
+
- **Seasonal Patterns** - Discover best months and quarters for trading
|
|
23
|
+
- **FPOP Analysis** - Future Period Loss/Profit projections
|
|
24
|
+
- **Risk Metrics** - VaR, Sharpe ratio, maximum drawdown
|
|
25
|
+
|
|
26
|
+
### 🎨 Modern UI/UX
|
|
27
|
+
- **Responsive Design** - Works on desktop, tablet, and mobile
|
|
28
|
+
- **Dark Navigation** - Professional gradient navbar
|
|
29
|
+
- **Interactive Cards** - Hover effects and smooth transitions
|
|
30
|
+
- **Keyboard Shortcuts** - Ctrl/Cmd+K for quick search
|
|
31
|
+
- **Loading States** - Spinners and progress indicators
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
### Prerequisites
|
|
36
|
+
|
|
37
|
+
- Ruby >= 3.2
|
|
38
|
+
- Bundler
|
|
39
|
+
- TA-Lib library (for technical indicators)
|
|
40
|
+
- Redis (for KBS strategy)
|
|
41
|
+
|
|
42
|
+
### Install TA-Lib
|
|
43
|
+
|
|
44
|
+
**macOS:**
|
|
45
|
+
```bash
|
|
46
|
+
brew install ta-lib
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Ubuntu/Debian:**
|
|
50
|
+
```bash
|
|
51
|
+
sudo apt-get install ta-lib-dev
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**Windows:**
|
|
55
|
+
Download from [TA-Lib website](http://ta-lib.org/)
|
|
56
|
+
|
|
57
|
+
### Install Dependencies
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
cd examples/sinatra_app
|
|
61
|
+
bundle install
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Set Up API Keys
|
|
65
|
+
|
|
66
|
+
SQA supports two data sources:
|
|
67
|
+
|
|
68
|
+
**Option 1: Alpha Vantage (Recommended)**
|
|
69
|
+
```bash
|
|
70
|
+
export AV_API_KEY="your_api_key_here"
|
|
71
|
+
```
|
|
72
|
+
Get a free API key from [Alpha Vantage](https://www.alphavantage.co/support/#api-key)
|
|
73
|
+
|
|
74
|
+
**Option 2: Yahoo Finance**
|
|
75
|
+
No API key required, but less reliable and may have rate limits.
|
|
76
|
+
|
|
77
|
+
### Start Redis (for KBS)
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
redis-server
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Usage
|
|
84
|
+
|
|
85
|
+
### Start the Application
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
ruby app.rb
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Or using Rack:
|
|
92
|
+
```bash
|
|
93
|
+
rackup
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The application will start on `http://localhost:4567`
|
|
97
|
+
|
|
98
|
+
### Navigate the App
|
|
99
|
+
|
|
100
|
+
1. **Home Page** - Quick access to popular stocks
|
|
101
|
+
2. **Search** - Enter any ticker symbol (e.g., AAPL, MSFT, GOOGL)
|
|
102
|
+
3. **Dashboard** - View charts and indicators
|
|
103
|
+
4. **Analysis** - Market regime, seasonal patterns, FPOP
|
|
104
|
+
5. **Backtest** - Test trading strategies
|
|
105
|
+
|
|
106
|
+
### Keyboard Shortcuts
|
|
107
|
+
|
|
108
|
+
- `Ctrl/Cmd + K` - Open ticker search modal
|
|
109
|
+
- `Escape` - Close modal
|
|
110
|
+
|
|
111
|
+
## API Endpoints
|
|
112
|
+
|
|
113
|
+
### Stock Data
|
|
114
|
+
|
|
115
|
+
```http
|
|
116
|
+
GET /api/stock/:ticker
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Returns stock price data with OHLCV (Open, High, Low, Close, Volume).
|
|
120
|
+
|
|
121
|
+
**Response:**
|
|
122
|
+
```json
|
|
123
|
+
{
|
|
124
|
+
"ticker": "AAPL",
|
|
125
|
+
"current_price": 175.50,
|
|
126
|
+
"change": 2.30,
|
|
127
|
+
"change_percent": 1.33,
|
|
128
|
+
"high_52w": 198.23,
|
|
129
|
+
"low_52w": 124.17,
|
|
130
|
+
"dates": ["2023-01-01", "2023-01-02", ...],
|
|
131
|
+
"open": [170.0, 171.5, ...],
|
|
132
|
+
"high": [172.0, 173.0, ...],
|
|
133
|
+
"low": [169.5, 170.8, ...],
|
|
134
|
+
"close": [171.0, 172.3, ...],
|
|
135
|
+
"volume": [50000000, 48000000, ...]
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Technical Indicators
|
|
140
|
+
|
|
141
|
+
```http
|
|
142
|
+
GET /api/indicators/:ticker
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Returns calculated technical indicators.
|
|
146
|
+
|
|
147
|
+
**Response:**
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"dates": ["2023-01-01", ...],
|
|
151
|
+
"rsi": [45.2, 48.1, ...],
|
|
152
|
+
"macd": [0.5, 0.7, ...],
|
|
153
|
+
"macd_signal": [0.4, 0.6, ...],
|
|
154
|
+
"macd_hist": [0.1, 0.1, ...],
|
|
155
|
+
"bb_upper": [180.0, ...],
|
|
156
|
+
"bb_middle": [175.0, ...],
|
|
157
|
+
"bb_lower": [170.0, ...],
|
|
158
|
+
"sma_20": [173.5, ...],
|
|
159
|
+
"sma_50": [170.2, ...],
|
|
160
|
+
"ema_20": [174.0, ...]
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Backtest Strategy
|
|
165
|
+
|
|
166
|
+
```http
|
|
167
|
+
POST /api/backtest/:ticker
|
|
168
|
+
Content-Type: application/x-www-form-urlencoded
|
|
169
|
+
|
|
170
|
+
strategy=RSI
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**Response:**
|
|
174
|
+
```json
|
|
175
|
+
{
|
|
176
|
+
"total_return": 15.45,
|
|
177
|
+
"annualized_return": 12.30,
|
|
178
|
+
"sharpe_ratio": 1.25,
|
|
179
|
+
"max_drawdown": 8.50,
|
|
180
|
+
"win_rate": 58.33,
|
|
181
|
+
"total_trades": 24,
|
|
182
|
+
"profit_factor": 1.85,
|
|
183
|
+
"avg_win": 3.20,
|
|
184
|
+
"avg_loss": -2.10
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Market Analysis
|
|
189
|
+
|
|
190
|
+
```http
|
|
191
|
+
GET /api/analyze/:ticker
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Response:**
|
|
195
|
+
```json
|
|
196
|
+
{
|
|
197
|
+
"regime": {
|
|
198
|
+
"type": "bull",
|
|
199
|
+
"volatility": "medium",
|
|
200
|
+
"strength": 0.75,
|
|
201
|
+
"trend": 15.2
|
|
202
|
+
},
|
|
203
|
+
"seasonal": {
|
|
204
|
+
"best_months": [10, 11, 12],
|
|
205
|
+
"worst_months": [6, 7, 8],
|
|
206
|
+
"best_quarters": [4, 1],
|
|
207
|
+
"has_pattern": true
|
|
208
|
+
},
|
|
209
|
+
"fpop": [...],
|
|
210
|
+
"risk": {
|
|
211
|
+
"var_95": -0.025,
|
|
212
|
+
"sharpe_ratio": 1.15,
|
|
213
|
+
"max_drawdown": 0.12
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Compare Strategies
|
|
219
|
+
|
|
220
|
+
```http
|
|
221
|
+
POST /api/compare/:ticker
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Response:**
|
|
225
|
+
```json
|
|
226
|
+
[
|
|
227
|
+
{
|
|
228
|
+
"strategy": "RSI",
|
|
229
|
+
"return": 15.45,
|
|
230
|
+
"sharpe": 1.25,
|
|
231
|
+
"drawdown": 8.50,
|
|
232
|
+
"win_rate": 58.33,
|
|
233
|
+
"trades": 24
|
|
234
|
+
},
|
|
235
|
+
...
|
|
236
|
+
]
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Technology Stack
|
|
240
|
+
|
|
241
|
+
### Backend
|
|
242
|
+
- **Sinatra** - Lightweight Ruby web framework
|
|
243
|
+
- **SQA Library** - Stock analysis and backtesting
|
|
244
|
+
- **TA-Lib** - Technical analysis indicators (via sqa-tai gem)
|
|
245
|
+
- **Polars** - High-performance DataFrame operations
|
|
246
|
+
- **Redis** - KBS blackboard persistence
|
|
247
|
+
|
|
248
|
+
### Frontend
|
|
249
|
+
- **Plotly.js** - Interactive financial charts
|
|
250
|
+
- **Font Awesome** - Icons
|
|
251
|
+
- **Vanilla JavaScript** - No framework dependencies
|
|
252
|
+
- **CSS3** - Modern styling with gradients and animations
|
|
253
|
+
|
|
254
|
+
## File Structure
|
|
255
|
+
|
|
256
|
+
```
|
|
257
|
+
sinatra_app/
|
|
258
|
+
├── app.rb # Main Sinatra application
|
|
259
|
+
├── config.ru # Rack configuration
|
|
260
|
+
├── Gemfile # Ruby dependencies
|
|
261
|
+
├── public/
|
|
262
|
+
│ ├── css/
|
|
263
|
+
│ │ └── style.css # Application styles
|
|
264
|
+
│ └── js/
|
|
265
|
+
│ └── app.js # Client-side JavaScript
|
|
266
|
+
├── views/
|
|
267
|
+
│ ├── layout.erb # Base template
|
|
268
|
+
│ ├── index.erb # Home page
|
|
269
|
+
│ ├── dashboard.erb # Main dashboard with charts
|
|
270
|
+
│ ├── analyze.erb # Analysis page
|
|
271
|
+
│ ├── backtest.erb # Backtesting interface
|
|
272
|
+
│ ├── portfolio.erb # Portfolio optimizer (coming soon)
|
|
273
|
+
│ └── error.erb # Error page
|
|
274
|
+
└── README.md # This file
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Routes
|
|
278
|
+
|
|
279
|
+
| Route | Method | Description |
|
|
280
|
+
|-------|--------|-------------|
|
|
281
|
+
| `/` | GET | Home page with quick links |
|
|
282
|
+
| `/dashboard/:ticker` | GET | Main dashboard for ticker |
|
|
283
|
+
| `/analyze/:ticker` | GET | Market analysis page |
|
|
284
|
+
| `/backtest/:ticker` | GET | Strategy backtesting page |
|
|
285
|
+
| `/portfolio` | GET | Portfolio optimization (coming soon) |
|
|
286
|
+
| `/api/stock/:ticker` | GET | Get stock data |
|
|
287
|
+
| `/api/indicators/:ticker` | GET | Get technical indicators |
|
|
288
|
+
| `/api/backtest/:ticker` | POST | Run strategy backtest |
|
|
289
|
+
| `/api/analyze/:ticker` | GET | Get market analysis |
|
|
290
|
+
| `/api/compare/:ticker` | POST | Compare all strategies |
|
|
291
|
+
|
|
292
|
+
## Configuration
|
|
293
|
+
|
|
294
|
+
### Port and Binding
|
|
295
|
+
|
|
296
|
+
Edit `app.rb`:
|
|
297
|
+
|
|
298
|
+
```ruby
|
|
299
|
+
set :port, 4567
|
|
300
|
+
set :bind, '0.0.0.0' # Allow external connections
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Data Source
|
|
304
|
+
|
|
305
|
+
The SQA library automatically selects the data source:
|
|
306
|
+
1. Alpha Vantage (if `AV_API_KEY` is set)
|
|
307
|
+
2. Yahoo Finance (fallback)
|
|
308
|
+
|
|
309
|
+
## Deployment
|
|
310
|
+
|
|
311
|
+
### Using Rack
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
rackup -p 4567
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### Using Passenger (Production)
|
|
318
|
+
|
|
319
|
+
```bash
|
|
320
|
+
passenger start
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Using Docker
|
|
324
|
+
|
|
325
|
+
```dockerfile
|
|
326
|
+
FROM ruby:3.3
|
|
327
|
+
WORKDIR /app
|
|
328
|
+
COPY Gemfile* ./
|
|
329
|
+
RUN bundle install
|
|
330
|
+
COPY . .
|
|
331
|
+
EXPOSE 4567
|
|
332
|
+
CMD ["ruby", "app.rb"]
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## Development
|
|
336
|
+
|
|
337
|
+
### Adding New Routes
|
|
338
|
+
|
|
339
|
+
Edit `app.rb`:
|
|
340
|
+
|
|
341
|
+
```ruby
|
|
342
|
+
get '/my-route/:ticker' do
|
|
343
|
+
ticker = params[:ticker].upcase
|
|
344
|
+
# ... logic
|
|
345
|
+
erb :my_template
|
|
346
|
+
end
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Adding New Views
|
|
350
|
+
|
|
351
|
+
Create `views/my_template.erb`:
|
|
352
|
+
|
|
353
|
+
```erb
|
|
354
|
+
<div class="dashboard">
|
|
355
|
+
<h1><%= @ticker %></h1>
|
|
356
|
+
<!-- Your content -->
|
|
357
|
+
</div>
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### Customizing Styles
|
|
361
|
+
|
|
362
|
+
Edit `public/css/style.css`:
|
|
363
|
+
|
|
364
|
+
```css
|
|
365
|
+
:root {
|
|
366
|
+
--primary-color: #2196F3; /* Change primary color */
|
|
367
|
+
}
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
## Troubleshooting
|
|
371
|
+
|
|
372
|
+
### TA-Lib Errors
|
|
373
|
+
|
|
374
|
+
```
|
|
375
|
+
Error: libta-lib.so: cannot open shared object file
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
**Solution:** Install TA-Lib library (see Installation section)
|
|
379
|
+
|
|
380
|
+
### Redis Connection Errors
|
|
381
|
+
|
|
382
|
+
```
|
|
383
|
+
Error: Could not connect to Redis
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
**Solution:** Start Redis server: `redis-server`
|
|
387
|
+
|
|
388
|
+
### Stock Data Not Loading
|
|
389
|
+
|
|
390
|
+
```
|
|
391
|
+
Error: Failed to load data for TICKER
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
**Solutions:**
|
|
395
|
+
1. Check API key is set: `echo $AV_API_KEY`
|
|
396
|
+
2. Verify ticker symbol is valid
|
|
397
|
+
3. Check internet connection
|
|
398
|
+
4. Try a different ticker
|
|
399
|
+
|
|
400
|
+
### Port Already in Use
|
|
401
|
+
|
|
402
|
+
```
|
|
403
|
+
Error: Address already in use - bind(2)
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
**Solution:** Kill the process using port 4567 or change the port in `app.rb`
|
|
407
|
+
|
|
408
|
+
## Performance Tips
|
|
409
|
+
|
|
410
|
+
1. **Enable Caching** - Cache API responses to reduce load times
|
|
411
|
+
2. **Use Alpha Vantage** - More reliable than Yahoo Finance
|
|
412
|
+
3. **Limit Historical Data** - Use shorter time periods for faster loading
|
|
413
|
+
4. **Optimize Charts** - Reduce data points for better rendering performance
|
|
414
|
+
|
|
415
|
+
## Security Notes
|
|
416
|
+
|
|
417
|
+
⚠️ **Educational Use Only** - This application is for educational purposes.
|
|
418
|
+
|
|
419
|
+
**Security Considerations:**
|
|
420
|
+
- API keys in environment variables (never commit to git)
|
|
421
|
+
- Input validation on ticker symbols
|
|
422
|
+
- Rate limiting for API endpoints (recommended for production)
|
|
423
|
+
- HTTPS for production deployments
|
|
424
|
+
- CSRF protection for form submissions
|
|
425
|
+
|
|
426
|
+
## Contributing
|
|
427
|
+
|
|
428
|
+
Improvements welcome! Areas for contribution:
|
|
429
|
+
|
|
430
|
+
- [ ] Portfolio optimization interface
|
|
431
|
+
- [ ] Pattern discovery visualization
|
|
432
|
+
- [ ] Genetic programming UI
|
|
433
|
+
- [ ] Real-time streaming dashboard
|
|
434
|
+
- [ ] Multi-stock comparison
|
|
435
|
+
- [ ] Export data to CSV/PDF
|
|
436
|
+
- [ ] Dark mode toggle
|
|
437
|
+
- [ ] User authentication
|
|
438
|
+
- [ ] Saved watchlists
|
|
439
|
+
|
|
440
|
+
## License
|
|
441
|
+
|
|
442
|
+
MIT License - Same as SQA library
|
|
443
|
+
|
|
444
|
+
## Credits
|
|
445
|
+
|
|
446
|
+
- **SQA Library** - Stock analysis framework
|
|
447
|
+
- **Plotly.js** - Interactive charts
|
|
448
|
+
- **Sinatra** - Web framework
|
|
449
|
+
- **TA-Lib** - Technical analysis
|
|
450
|
+
- **Font Awesome** - Icons
|
|
451
|
+
|
|
452
|
+
## Links
|
|
453
|
+
|
|
454
|
+
- [SQA Repository](https://github.com/MadBomber/sqa)
|
|
455
|
+
- [Plotly.js Documentation](https://plotly.com/javascript/)
|
|
456
|
+
- [Sinatra Documentation](http://sinatrarb.com/)
|
|
457
|
+
- [TA-Lib](http://ta-lib.org/)
|
|
458
|
+
|
|
459
|
+
---
|
|
460
|
+
|
|
461
|
+
**Disclaimer:** This software is for educational and research purposes only. Do not use for actual trading without proper due diligence. The authors are not responsible for financial losses.
|