sqa 0.0.32 → 0.0.38

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.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +154 -1
  3. data/README.md +4 -0
  4. data/Rakefile +52 -10
  5. data/docs/advanced/index.md +1 -13
  6. data/docs/api/index.md +547 -61
  7. data/docs/api-reference/alphavantageapi.md +1057 -0
  8. data/docs/api-reference/apierror.md +31 -0
  9. data/docs/api-reference/index.md +221 -0
  10. data/docs/api-reference/notimplemented.md +27 -0
  11. data/docs/api-reference/sqa.md +267 -0
  12. data/docs/api-reference/sqa_backtest.md +171 -0
  13. data/docs/api-reference/sqa_backtest_results.md +530 -0
  14. data/docs/api-reference/sqa_badparametererror.md +13 -0
  15. data/docs/api-reference/sqa_config.md +538 -0
  16. data/docs/api-reference/sqa_configurationerror.md +13 -0
  17. data/docs/api-reference/sqa_datafetcherror.md +56 -0
  18. data/docs/api-reference/sqa_dataframe.md +779 -0
  19. data/docs/api-reference/sqa_dataframe_alphavantage.md +30 -0
  20. data/docs/api-reference/sqa_dataframe_data.md +325 -0
  21. data/docs/api-reference/sqa_dataframe_yahoofinance.md +25 -0
  22. data/docs/api-reference/sqa_ensemble.md +413 -0
  23. data/docs/api-reference/sqa_fpop.md +211 -0
  24. data/docs/api-reference/sqa_geneticprogram.md +325 -0
  25. data/docs/api-reference/sqa_geneticprogram_individual.md +114 -0
  26. data/docs/api-reference/sqa_marketregime.md +212 -0
  27. data/docs/api-reference/sqa_multitimeframe.md +227 -0
  28. data/docs/api-reference/sqa_patternmatcher.md +195 -0
  29. data/docs/api-reference/sqa_pluginmanager.md +55 -0
  30. data/docs/api-reference/sqa_portfolio.md +512 -0
  31. data/docs/api-reference/sqa_portfolio_position.md +220 -0
  32. data/docs/api-reference/sqa_portfolio_trade.md +332 -0
  33. data/docs/api-reference/sqa_portfoliooptimizer.md +248 -0
  34. data/docs/api-reference/sqa_riskmanager.md +388 -0
  35. data/docs/api-reference/sqa_seasonalanalyzer.md +121 -0
  36. data/docs/api-reference/sqa_sectoranalyzer.md +163 -0
  37. data/docs/api-reference/sqa_stock.md +661 -0
  38. data/docs/api-reference/sqa_strategy.md +178 -0
  39. data/docs/api-reference/sqa_strategy_bollingerbands.md +26 -0
  40. data/docs/api-reference/sqa_strategy_common.md +29 -0
  41. data/docs/api-reference/sqa_strategy_consensus.md +129 -0
  42. data/docs/api-reference/sqa_strategy_ema.md +41 -0
  43. data/docs/api-reference/sqa_strategy_kbs.md +154 -0
  44. data/docs/api-reference/sqa_strategy_macd.md +26 -0
  45. data/docs/api-reference/sqa_strategy_mp.md +41 -0
  46. data/docs/api-reference/sqa_strategy_mr.md +41 -0
  47. data/docs/api-reference/sqa_strategy_random.md +41 -0
  48. data/docs/api-reference/sqa_strategy_rsi.md +41 -0
  49. data/docs/api-reference/sqa_strategy_sma.md +41 -0
  50. data/docs/api-reference/sqa_strategy_stochastic.md +26 -0
  51. data/docs/api-reference/sqa_strategy_volumebreakout.md +26 -0
  52. data/docs/api-reference/sqa_strategygenerator.md +298 -0
  53. data/docs/api-reference/sqa_strategygenerator_pattern.md +264 -0
  54. data/docs/api-reference/sqa_strategygenerator_patterncontext.md +326 -0
  55. data/docs/api-reference/sqa_strategygenerator_profitablepoint.md +424 -0
  56. data/docs/api-reference/sqa_stream.md +256 -0
  57. data/docs/api-reference/sqa_ticker.md +175 -0
  58. data/docs/api-reference/string.md +135 -0
  59. data/docs/assets/images/advanced-workflow.svg +89 -0
  60. data/docs/assets/images/architecture.svg +107 -0
  61. data/docs/assets/images/data-flow.svg +138 -0
  62. data/docs/assets/images/getting-started-workflow.svg +88 -0
  63. data/docs/assets/images/strategy-flow.svg +78 -0
  64. data/docs/assets/images/system-architecture.svg +150 -0
  65. data/docs/concepts/index.md +292 -19
  66. data/docs/file_formats.md +250 -0
  67. data/docs/getting-started/index.md +1 -14
  68. data/docs/index.md +26 -23
  69. data/docs/llms.txt +109 -0
  70. data/docs/strategies/kbs.md +15 -14
  71. data/docs/strategy.md +381 -3
  72. data/docs/terms_of_use.md +1 -1
  73. data/examples/README.md +10 -0
  74. data/lib/api/alpha_vantage_api.rb +3 -7
  75. data/lib/sqa/backtest.rb +32 -0
  76. data/lib/sqa/config.rb +109 -28
  77. data/lib/sqa/data_frame/data.rb +13 -1
  78. data/lib/sqa/data_frame.rb +193 -26
  79. data/lib/sqa/errors.rb +79 -17
  80. data/lib/sqa/init.rb +70 -15
  81. data/lib/sqa/pattern_matcher.rb +4 -4
  82. data/lib/sqa/portfolio.rb +55 -1
  83. data/lib/sqa/sector_analyzer.rb +3 -11
  84. data/lib/sqa/stock.rb +180 -15
  85. data/lib/sqa/strategy.rb +62 -4
  86. data/lib/sqa/ticker.rb +106 -48
  87. data/lib/sqa/version.rb +1 -1
  88. data/lib/sqa.rb +4 -4
  89. data/mkdocs.yml +69 -81
  90. metadata +89 -21
  91. data/docs/README.md +0 -43
  92. data/examples/sinatra_app/Gemfile +0 -42
  93. data/examples/sinatra_app/Gemfile.lock +0 -268
  94. data/examples/sinatra_app/QUICKSTART.md +0 -169
  95. data/examples/sinatra_app/README.md +0 -471
  96. data/examples/sinatra_app/RUNNING_WITHOUT_TALIB.md +0 -90
  97. data/examples/sinatra_app/TROUBLESHOOTING.md +0 -95
  98. data/examples/sinatra_app/app.rb +0 -404
  99. data/examples/sinatra_app/config.ru +0 -5
  100. data/examples/sinatra_app/public/css/style.css +0 -723
  101. data/examples/sinatra_app/public/debug_macd.html +0 -82
  102. data/examples/sinatra_app/public/js/app.js +0 -107
  103. data/examples/sinatra_app/start.sh +0 -53
  104. data/examples/sinatra_app/views/analyze.erb +0 -306
  105. data/examples/sinatra_app/views/backtest.erb +0 -325
  106. data/examples/sinatra_app/views/dashboard.erb +0 -831
  107. data/examples/sinatra_app/views/error.erb +0 -58
  108. data/examples/sinatra_app/views/index.erb +0 -118
  109. data/examples/sinatra_app/views/layout.erb +0 -61
  110. data/examples/sinatra_app/views/portfolio.erb +0 -43
@@ -1,471 +0,0 @@
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
- **⚠️ IMPORTANT:** Always use `bundle exec` to run the app:
88
-
89
- ```bash
90
- bundle exec ruby app.rb
91
- ```
92
-
93
- **Or use the startup script:**
94
-
95
- ```bash
96
- ./start.sh
97
- ```
98
-
99
- **Why `bundle exec`?** Running `ruby app.rb` without `bundle exec` may fail to load required gems, causing the dashboard to not work properly (buttons won't respond, charts won't load, API calls will fail).
100
-
101
- Or using Rack:
102
- ```bash
103
- bundle exec rackup
104
- ```
105
-
106
- The application will start on `http://localhost:4567`
107
-
108
- ### Navigate the App
109
-
110
- 1. **Home Page** - Quick access to popular stocks
111
- 2. **Search** - Enter any ticker symbol (e.g., AAPL, MSFT, GOOGL)
112
- 3. **Dashboard** - View charts and indicators
113
- 4. **Analysis** - Market regime, seasonal patterns, FPOP
114
- 5. **Backtest** - Test trading strategies
115
-
116
- ### Keyboard Shortcuts
117
-
118
- - `Ctrl/Cmd + K` - Open ticker search modal
119
- - `Escape` - Close modal
120
-
121
- ## API Endpoints
122
-
123
- ### Stock Data
124
-
125
- ```http
126
- GET /api/stock/:ticker
127
- ```
128
-
129
- Returns stock price data with OHLCV (Open, High, Low, Close, Volume).
130
-
131
- **Response:**
132
- ```json
133
- {
134
- "ticker": "AAPL",
135
- "current_price": 175.50,
136
- "change": 2.30,
137
- "change_percent": 1.33,
138
- "high_52w": 198.23,
139
- "low_52w": 124.17,
140
- "dates": ["2023-01-01", "2023-01-02", ...],
141
- "open": [170.0, 171.5, ...],
142
- "high": [172.0, 173.0, ...],
143
- "low": [169.5, 170.8, ...],
144
- "close": [171.0, 172.3, ...],
145
- "volume": [50000000, 48000000, ...]
146
- }
147
- ```
148
-
149
- ### Technical Indicators
150
-
151
- ```http
152
- GET /api/indicators/:ticker
153
- ```
154
-
155
- Returns calculated technical indicators.
156
-
157
- **Response:**
158
- ```json
159
- {
160
- "dates": ["2023-01-01", ...],
161
- "rsi": [45.2, 48.1, ...],
162
- "macd": [0.5, 0.7, ...],
163
- "macd_signal": [0.4, 0.6, ...],
164
- "macd_hist": [0.1, 0.1, ...],
165
- "bb_upper": [180.0, ...],
166
- "bb_middle": [175.0, ...],
167
- "bb_lower": [170.0, ...],
168
- "sma_20": [173.5, ...],
169
- "sma_50": [170.2, ...],
170
- "ema_20": [174.0, ...]
171
- }
172
- ```
173
-
174
- ### Backtest Strategy
175
-
176
- ```http
177
- POST /api/backtest/:ticker
178
- Content-Type: application/x-www-form-urlencoded
179
-
180
- strategy=RSI
181
- ```
182
-
183
- **Response:**
184
- ```json
185
- {
186
- "total_return": 15.45,
187
- "annualized_return": 12.30,
188
- "sharpe_ratio": 1.25,
189
- "max_drawdown": 8.50,
190
- "win_rate": 58.33,
191
- "total_trades": 24,
192
- "profit_factor": 1.85,
193
- "avg_win": 3.20,
194
- "avg_loss": -2.10
195
- }
196
- ```
197
-
198
- ### Market Analysis
199
-
200
- ```http
201
- GET /api/analyze/:ticker
202
- ```
203
-
204
- **Response:**
205
- ```json
206
- {
207
- "regime": {
208
- "type": "bull",
209
- "volatility": "medium",
210
- "strength": 0.75,
211
- "trend": 15.2
212
- },
213
- "seasonal": {
214
- "best_months": [10, 11, 12],
215
- "worst_months": [6, 7, 8],
216
- "best_quarters": [4, 1],
217
- "has_pattern": true
218
- },
219
- "fpop": [...],
220
- "risk": {
221
- "var_95": -0.025,
222
- "sharpe_ratio": 1.15,
223
- "max_drawdown": 0.12
224
- }
225
- }
226
- ```
227
-
228
- ### Compare Strategies
229
-
230
- ```http
231
- POST /api/compare/:ticker
232
- ```
233
-
234
- **Response:**
235
- ```json
236
- [
237
- {
238
- "strategy": "RSI",
239
- "return": 15.45,
240
- "sharpe": 1.25,
241
- "drawdown": 8.50,
242
- "win_rate": 58.33,
243
- "trades": 24
244
- },
245
- ...
246
- ]
247
- ```
248
-
249
- ## Technology Stack
250
-
251
- ### Backend
252
- - **Sinatra** - Lightweight Ruby web framework
253
- - **SQA Library** - Stock analysis and backtesting
254
- - **TA-Lib** - Technical analysis indicators (via sqa-tai gem)
255
- - **Polars** - High-performance DataFrame operations
256
- - **Redis** - KBS blackboard persistence
257
-
258
- ### Frontend
259
- - **Plotly.js** - Interactive financial charts
260
- - **Font Awesome** - Icons
261
- - **Vanilla JavaScript** - No framework dependencies
262
- - **CSS3** - Modern styling with gradients and animations
263
-
264
- ## File Structure
265
-
266
- ```
267
- sinatra_app/
268
- ├── app.rb # Main Sinatra application
269
- ├── config.ru # Rack configuration
270
- ├── Gemfile # Ruby dependencies
271
- ├── public/
272
- │ ├── css/
273
- │ │ └── style.css # Application styles
274
- │ └── js/
275
- │ └── app.js # Client-side JavaScript
276
- ├── views/
277
- │ ├── layout.erb # Base template
278
- │ ├── index.erb # Home page
279
- │ ├── dashboard.erb # Main dashboard with charts
280
- │ ├── analyze.erb # Analysis page
281
- │ ├── backtest.erb # Backtesting interface
282
- │ ├── portfolio.erb # Portfolio optimizer (coming soon)
283
- │ └── error.erb # Error page
284
- └── README.md # This file
285
- ```
286
-
287
- ## Routes
288
-
289
- | Route | Method | Description |
290
- |-------|--------|-------------|
291
- | `/` | GET | Home page with quick links |
292
- | `/dashboard/:ticker` | GET | Main dashboard for ticker |
293
- | `/analyze/:ticker` | GET | Market analysis page |
294
- | `/backtest/:ticker` | GET | Strategy backtesting page |
295
- | `/portfolio` | GET | Portfolio optimization (coming soon) |
296
- | `/api/stock/:ticker` | GET | Get stock data |
297
- | `/api/indicators/:ticker` | GET | Get technical indicators |
298
- | `/api/backtest/:ticker` | POST | Run strategy backtest |
299
- | `/api/analyze/:ticker` | GET | Get market analysis |
300
- | `/api/compare/:ticker` | POST | Compare all strategies |
301
-
302
- ## Configuration
303
-
304
- ### Port and Binding
305
-
306
- Edit `app.rb`:
307
-
308
- ```ruby
309
- set :port, 4567
310
- set :bind, '0.0.0.0' # Allow external connections
311
- ```
312
-
313
- ### Data Source
314
-
315
- The SQA library automatically selects the data source:
316
- 1. Alpha Vantage (if `AV_API_KEY` is set)
317
- 2. Yahoo Finance (fallback)
318
-
319
- ## Deployment
320
-
321
- ### Using Rack
322
-
323
- ```bash
324
- rackup -p 4567
325
- ```
326
-
327
- ### Using Passenger (Production)
328
-
329
- ```bash
330
- passenger start
331
- ```
332
-
333
- ### Using Docker
334
-
335
- ```dockerfile
336
- FROM ruby:3.3
337
- WORKDIR /app
338
- COPY Gemfile* ./
339
- RUN bundle install
340
- COPY . .
341
- EXPOSE 4567
342
- CMD ["ruby", "app.rb"]
343
- ```
344
-
345
- ## Development
346
-
347
- ### Adding New Routes
348
-
349
- Edit `app.rb`:
350
-
351
- ```ruby
352
- get '/my-route/:ticker' do
353
- ticker = params[:ticker].upcase
354
- # ... logic
355
- erb :my_template
356
- end
357
- ```
358
-
359
- ### Adding New Views
360
-
361
- Create `views/my_template.erb`:
362
-
363
- ```erb
364
- <div class="dashboard">
365
- <h1><%= @ticker %></h1>
366
- <!-- Your content -->
367
- </div>
368
- ```
369
-
370
- ### Customizing Styles
371
-
372
- Edit `public/css/style.css`:
373
-
374
- ```css
375
- :root {
376
- --primary-color: #2196F3; /* Change primary color */
377
- }
378
- ```
379
-
380
- ## Troubleshooting
381
-
382
- ### TA-Lib Errors
383
-
384
- ```
385
- Error: libta-lib.so: cannot open shared object file
386
- ```
387
-
388
- **Solution:** Install TA-Lib library (see Installation section)
389
-
390
- ### Redis Connection Errors
391
-
392
- ```
393
- Error: Could not connect to Redis
394
- ```
395
-
396
- **Solution:** Start Redis server: `redis-server`
397
-
398
- ### Stock Data Not Loading
399
-
400
- ```
401
- Error: Failed to load data for TICKER
402
- ```
403
-
404
- **Solutions:**
405
- 1. Check API key is set: `echo $AV_API_KEY`
406
- 2. Verify ticker symbol is valid
407
- 3. Check internet connection
408
- 4. Try a different ticker
409
-
410
- ### Port Already in Use
411
-
412
- ```
413
- Error: Address already in use - bind(2)
414
- ```
415
-
416
- **Solution:** Kill the process using port 4567 or change the port in `app.rb`
417
-
418
- ## Performance Tips
419
-
420
- 1. **Enable Caching** - Cache API responses to reduce load times
421
- 2. **Use Alpha Vantage** - More reliable than Yahoo Finance
422
- 3. **Limit Historical Data** - Use shorter time periods for faster loading
423
- 4. **Optimize Charts** - Reduce data points for better rendering performance
424
-
425
- ## Security Notes
426
-
427
- ⚠️ **Educational Use Only** - This application is for educational purposes.
428
-
429
- **Security Considerations:**
430
- - API keys in environment variables (never commit to git)
431
- - Input validation on ticker symbols
432
- - Rate limiting for API endpoints (recommended for production)
433
- - HTTPS for production deployments
434
- - CSRF protection for form submissions
435
-
436
- ## Contributing
437
-
438
- Improvements welcome! Areas for contribution:
439
-
440
- - [ ] Portfolio optimization interface
441
- - [ ] Pattern discovery visualization
442
- - [ ] Genetic programming UI
443
- - [ ] Real-time streaming dashboard
444
- - [ ] Multi-stock comparison
445
- - [ ] Export data to CSV/PDF
446
- - [ ] Dark mode toggle
447
- - [ ] User authentication
448
- - [ ] Saved watchlists
449
-
450
- ## License
451
-
452
- MIT License - Same as SQA library
453
-
454
- ## Credits
455
-
456
- - **SQA Library** - Stock analysis framework
457
- - **Plotly.js** - Interactive charts
458
- - **Sinatra** - Web framework
459
- - **TA-Lib** - Technical analysis
460
- - **Font Awesome** - Icons
461
-
462
- ## Links
463
-
464
- - [SQA Repository](https://github.com/MadBomber/sqa)
465
- - [Plotly.js Documentation](https://plotly.com/javascript/)
466
- - [Sinatra Documentation](http://sinatrarb.com/)
467
- - [TA-Lib](http://ta-lib.org/)
468
-
469
- ---
470
-
471
- **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.
@@ -1,90 +0,0 @@
1
- # Running the Sinatra App Without TA-Lib
2
-
3
- The SQA Sinatra web app can run with **limited functionality** when the TA-Lib system library is not installed. This is useful for development, testing, or deployments where installing TA-Lib is difficult.
4
-
5
- ## What Works Without TA-Lib
6
-
7
- ✅ **Basic Stock Data Display**
8
- - Loading stock price history from cached CSV files
9
- - Displaying price charts (candlestick and line)
10
- - Volume charts
11
- - Price statistics (current price, 52-week high/low)
12
-
13
- ✅ **Advanced Analysis Features**
14
- - Market regime detection (bull/bear/sideways)
15
- - Seasonal pattern analysis
16
- - Risk metrics (VaR, Sharpe ratio, max drawdown)
17
- - FPOP (Future Period Profit/Loss) analysis
18
-
19
- ✅ **Strategy Comparison**
20
- - Comparing different trading strategies via backtesting
21
-
22
- ## What Doesn't Work Without TA-Lib
23
-
24
- ❌ **Technical Indicators**
25
- - RSI (Relative Strength Index)
26
- - MACD (Moving Average Convergence Divergence)
27
- - Bollinger Bands
28
- - Moving Averages (SMA, EMA)
29
- - All other TA-Lib indicators (150+ total)
30
-
31
- These endpoints will return errors:
32
- - `GET /api/indicators/:ticker` - Returns error when indicators are called
33
-
34
- ## Running the App
35
-
36
- ### With Cached Data (No API Key Required)
37
-
38
- 1. Ensure you have cached stock data in `~/sqa_data/`:
39
- ```
40
- ~/sqa_data/
41
- ├── aapl.csv # Price history
42
- ├── aapl.json # Stock metadata
43
- ```
44
-
45
- 2. Install dependencies:
46
- ```bash
47
- cd examples/sinatra_app
48
- bundle install
49
- ```
50
-
51
- 3. Start the server:
52
- ```bash
53
- bundle exec ruby app.rb
54
- ```
55
-
56
- 4. Visit http://localhost:4567
57
-
58
- ### Installing TA-Lib (Optional)
59
-
60
- To enable technical indicators, install the TA-Lib system library:
61
-
62
- **macOS:**
63
- ```bash
64
- brew install ta-lib
65
- ```
66
-
67
- **Ubuntu/Debian:**
68
- ```bash
69
- wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
70
- tar -xzf ta-lib-0.4.0-src.tar.gz
71
- cd ta-lib/
72
- ./configure --prefix=/usr
73
- make
74
- sudo make install
75
- sudo ldconfig
76
- ```
77
-
78
- **Note:** After installing TA-Lib, you may need to reinstall the gems:
79
- ```bash
80
- bundle install
81
- ```
82
-
83
- ## Error Handling
84
-
85
- The app gracefully handles missing indicators by:
86
- - Starting successfully without TA-Lib
87
- - Showing helpful error messages when indicator endpoints are accessed
88
- - Allowing all non-indicator features to work normally
89
-
90
- If you see errors about indicators, it's expected behavior when TA-Lib is not available.
@@ -1,95 +0,0 @@
1
- # Troubleshooting the Sinatra App
2
-
3
- ## Dashboard page loads but buttons/charts don't work
4
-
5
- This usually means JavaScript errors are preventing the page from functioning.
6
-
7
- ### Quick Fix Checklist
8
-
9
- 1. **Install dependencies first:**
10
- ```bash
11
- cd examples/sinatra_app
12
- bundle install
13
- ```
14
-
15
- 2. **Start the server with bundle exec:**
16
- ```bash
17
- bundle exec ruby app.rb
18
- # OR
19
- bundle exec rackup
20
- ```
21
-
22
- 3. **Check browser console for errors:**
23
- - Open browser DevTools (F12 or Ctrl+Shift+I)
24
- - Go to "Console" tab
25
- - Look for red error messages
26
- - Take a screenshot and check what's failing
27
-
28
- 4. **Check Network tab:**
29
- - Open DevTools → Network tab
30
- - Reload the dashboard page
31
- - Look for failed requests (red status codes)
32
- - Check if `/api/stock/AAPL`, `/api/indicators/AAPL`, `/api/analyze/AAPL` are returning 200 or errors
33
-
34
- ### Common Issues
35
-
36
- #### Issue: "ApexCharts is not defined"
37
- **Symptom:** Charts don't render, console shows `Uncaught ReferenceError: ApexCharts is not defined`
38
-
39
- **Fix:** The CDN link for ApexCharts is missing or blocked. Check `views/layout.erb`:
40
- ```html
41
- <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
42
- ```
43
-
44
- #### Issue: API calls failing with 500 errors
45
- **Symptom:** Network tab shows `/api/indicators/AAPL` returns 500
46
-
47
- **Fix:** This is expected if TA-Lib isn't installed. The app should handle this gracefully.
48
-
49
- #### Issue: Buttons don't respond
50
- **Symptom:** Clicking buttons does nothing
51
-
52
- **Possible causes:**
53
- 1. JavaScript not loaded (check console for errors)
54
- 2. Event handlers not attached (check if page finished loading)
55
- 3. JavaScript errors earlier in the file preventing execution
56
-
57
- ### Debug Mode
58
-
59
- Run the server with verbose logging:
60
- ```bash
61
- RACK_ENV=development bundle exec ruby app.rb
62
- ```
63
-
64
- ### Test API Endpoints Manually
65
-
66
- While server is running, test in another terminal:
67
-
68
- ```bash
69
- # Test stock data
70
- curl -s "http://localhost:4567/api/stock/AAPL?period=30d" | python3 -m json.tool
71
-
72
- # Test indicators (may fail without TA-Lib - that's OK)
73
- curl -s "http://localhost:4567/api/indicators/AAPL?period=30d"
74
-
75
- # Test analysis
76
- curl -s "http://localhost:4567/api/analyze/AAPL" | python3 -m json.tool
77
- ```
78
-
79
- All should return JSON. If you get HTML error pages, there's a server-side issue.
80
-
81
- ### Check if all gems are installed
82
-
83
- ```bash
84
- bundle check
85
- ```
86
-
87
- If it says "The Gemfile's dependencies are satisfied", you're good.
88
-
89
- ### Still not working?
90
-
91
- Please provide:
92
- 1. Screenshot of browser console (DevTools → Console tab)
93
- 2. Screenshot of network tab showing failed requests
94
- 3. Output of `bundle check`
95
- 4. Any errors from server console