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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d6d22476a47a9bfc41607bfaf78edd211f3e8be7badaef817512b3b9c04cb04
|
|
4
|
+
data.tar.gz: 97ae20203d7bca4bef0bb619e1ae4550071e6072ebe8d357ec99a5957df874a4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3a51b38307d0c14f750dab7916a505dfd59e793a0d3bd1e1f19c45e5daab39d7e4b0913ace7661bfdb056017f9e5ac43164ea194c4f06d5dbb1423d3cdad6649
|
|
7
|
+
data.tar.gz: cc4985173611bc3131cb017beb0e3812a3df593799ef1423b741aa7c9113f4ef308df1bba6f808990731bb9d101502dd641a44582dea7a1460d3d65a03bd152b
|
data/.semver
ADDED
data/ARCHITECTURE.md
ADDED
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
# SQA Project - Refactoring Architecture Plan
|
|
2
|
+
|
|
3
|
+
**Date:** 2025-01-05
|
|
4
|
+
**Session:** claude/review-codebase-planning-011CUqHdDz75cZMoeGXq8XfR
|
|
5
|
+
|
|
6
|
+
## Executive Summary
|
|
7
|
+
|
|
8
|
+
The SQA project is being refactored from a monolithic gem into a modular 3-gem architecture:
|
|
9
|
+
|
|
10
|
+
1. **sqa-talib** - Pure indicator library (TA-Lib wrapper)
|
|
11
|
+
2. **sqa** - Strategy framework (refactored, v1.0.0)
|
|
12
|
+
3. **sqa-cli** - CLI tool with AI integration
|
|
13
|
+
|
|
14
|
+
## Current Status
|
|
15
|
+
|
|
16
|
+
✅ **Completed:**
|
|
17
|
+
- Comprehensive codebase review
|
|
18
|
+
- Architecture planning and design
|
|
19
|
+
- sqa-talib gem created (locally, awaiting repo authorization)
|
|
20
|
+
|
|
21
|
+
🔄 **In Progress:**
|
|
22
|
+
- Documenting architecture decisions
|
|
23
|
+
- Preparing sqa-talib for transfer to dedicated repo
|
|
24
|
+
|
|
25
|
+
⏳ **Pending:**
|
|
26
|
+
- sqa-cli gem creation
|
|
27
|
+
- sqa repo refactoring to v1.0.0
|
|
28
|
+
- Integration testing
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Architecture Overview
|
|
33
|
+
|
|
34
|
+
### Before (Monolithic)
|
|
35
|
+
```
|
|
36
|
+
sqa (one gem)
|
|
37
|
+
├── Indicators (Ruby implementations)
|
|
38
|
+
├── Strategies
|
|
39
|
+
├── CLI commands
|
|
40
|
+
├── Data loading
|
|
41
|
+
├── Portfolio management
|
|
42
|
+
└── Everything else
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### After (Modular)
|
|
46
|
+
```
|
|
47
|
+
┌─────────────────────────────────────┐
|
|
48
|
+
│ sqa-cli │
|
|
49
|
+
│ (CLI Tool - Application) │
|
|
50
|
+
│ - Commands │
|
|
51
|
+
│ - Data loading │
|
|
52
|
+
│ - AI integration │
|
|
53
|
+
│ - Portfolio management │
|
|
54
|
+
└─────────────────────────────────────┘
|
|
55
|
+
↓ ↓
|
|
56
|
+
┌─────────────────┐ ┌─────────────────┐
|
|
57
|
+
│ sqa-talib │ │ sqa │
|
|
58
|
+
│ (Indicators) │ │ (Strategies) │
|
|
59
|
+
│ │ │ │
|
|
60
|
+
│ - TA-Lib wrap │ │ - Strategy API │
|
|
61
|
+
│ - 200+ indics │ │ - Built-ins │
|
|
62
|
+
│ - NEW REPO │ │ - Backtesting │
|
|
63
|
+
└─────────────────┘ │ - DataFrame │
|
|
64
|
+
↓ │ - REFACTORED │
|
|
65
|
+
┌─────────────────┐ └─────────────────┘
|
|
66
|
+
│ ta_lib_ffi │ ↓
|
|
67
|
+
│ (C library) │ ┌─────────────────┐
|
|
68
|
+
└─────────────────┘ │ sqa-talib │
|
|
69
|
+
│ (uses for data)│
|
|
70
|
+
└─────────────────┘
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Detailed Component Breakdown
|
|
76
|
+
|
|
77
|
+
### 1. sqa-talib (NEW - Indicator Library)
|
|
78
|
+
|
|
79
|
+
**Repository:** https://github.com/MadBomber/sqa-talib
|
|
80
|
+
**Version:** 0.1.0
|
|
81
|
+
**Status:** Created locally, awaiting repo access
|
|
82
|
+
|
|
83
|
+
**Purpose:** Pure technical analysis indicator library wrapping TA-Lib
|
|
84
|
+
|
|
85
|
+
**What it contains:**
|
|
86
|
+
- Ruby wrapper around `ta_lib_ffi` gem
|
|
87
|
+
- 200+ technical indicators from TA-Lib C library
|
|
88
|
+
- Clean Ruby API with keyword arguments
|
|
89
|
+
- Parameter validation and error handling
|
|
90
|
+
- Comprehensive test suite
|
|
91
|
+
- Full documentation (MkDocs)
|
|
92
|
+
|
|
93
|
+
**Key indicators implemented:**
|
|
94
|
+
- **Overlap Studies:** SMA, EMA, WMA, BBANDS
|
|
95
|
+
- **Momentum:** RSI, MACD, STOCH, MOM
|
|
96
|
+
- **Volatility:** ATR, TRANGE
|
|
97
|
+
- **Volume:** OBV, AD
|
|
98
|
+
- **Patterns:** Doji, Hammer, Engulfing, and 60+ more
|
|
99
|
+
|
|
100
|
+
**Dependencies:**
|
|
101
|
+
- `ta_lib_ffi ~> 0.3` (requires TA-Lib C library)
|
|
102
|
+
|
|
103
|
+
**API Example:**
|
|
104
|
+
```ruby
|
|
105
|
+
require 'sqa/talib'
|
|
106
|
+
|
|
107
|
+
prices = [44.34, 44.09, 44.15, 43.61, 44.33]
|
|
108
|
+
|
|
109
|
+
# Simple API
|
|
110
|
+
sma = SQA::TALib.sma(prices, period: 5)
|
|
111
|
+
rsi = SQA::TALib.rsi(prices, period: 14)
|
|
112
|
+
upper, middle, lower = SQA::TALib.bbands(prices, period: 20)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Files created:**
|
|
116
|
+
```
|
|
117
|
+
sqa-talib/
|
|
118
|
+
├── lib/sqa/talib.rb # Main wrapper (300+ lines)
|
|
119
|
+
├── lib/sqa/talib/version.rb
|
|
120
|
+
├── sqa-talib.gemspec
|
|
121
|
+
├── README.md
|
|
122
|
+
├── LICENSE (MIT)
|
|
123
|
+
├── CHANGELOG.md
|
|
124
|
+
├── Gemfile
|
|
125
|
+
├── Rakefile
|
|
126
|
+
├── test/
|
|
127
|
+
│ ├── test_helper.rb
|
|
128
|
+
│ └── sqa/talib_test.rb # Comprehensive tests
|
|
129
|
+
├── docs/
|
|
130
|
+
│ ├── index.md
|
|
131
|
+
│ ├── getting-started/
|
|
132
|
+
│ │ ├── installation.md
|
|
133
|
+
│ │ └── quick-start.md
|
|
134
|
+
│ ├── api-reference.md
|
|
135
|
+
│ └── mkdocs.yml
|
|
136
|
+
└── .github/workflows/
|
|
137
|
+
├── test.yml # CI for Ruby 3.1, 3.2, 3.3
|
|
138
|
+
└── docs.yml # Auto-deploy docs
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
### 2. sqa (REFACTORED - Strategy Framework)
|
|
144
|
+
|
|
145
|
+
**Repository:** https://github.com/MadBomber/sqa
|
|
146
|
+
**Version:** 0.0.25 → 1.0.0 (breaking change)
|
|
147
|
+
**Status:** Awaiting refactoring
|
|
148
|
+
|
|
149
|
+
**Purpose:** Trading strategy development and execution framework
|
|
150
|
+
|
|
151
|
+
**What stays:**
|
|
152
|
+
- ✅ Strategy framework (`lib/sqa/strategy/`)
|
|
153
|
+
- ✅ Built-in strategies (Random, RSI, SMA, EMA, MR, MP, Consensus)
|
|
154
|
+
- ✅ DataFrame (`lib/sqa/data_frame.rb`)
|
|
155
|
+
- ✅ Patches (`lib/patches/`)
|
|
156
|
+
- ✅ Backtesting framework (to be enhanced)
|
|
157
|
+
|
|
158
|
+
**What moves out:**
|
|
159
|
+
- ❌ Indicator implementations → moved to sqa-talib
|
|
160
|
+
- ❌ CLI commands → moved to sqa-cli
|
|
161
|
+
- ❌ Stock, Portfolio, Config classes → moved to sqa-cli
|
|
162
|
+
- ❌ Data loading code → moved to sqa-cli
|
|
163
|
+
- ❌ Trade/Activity tracking → moved to sqa-cli
|
|
164
|
+
|
|
165
|
+
**New dependencies:**
|
|
166
|
+
```ruby
|
|
167
|
+
spec.add_dependency 'sqa-talib', '~> 0.1' # For indicator calculations
|
|
168
|
+
spec.add_dependency 'hashie', '~> 5.0' # DataFrame (upgrade from 4.1)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**Migration path:**
|
|
172
|
+
```ruby
|
|
173
|
+
# Old (v0.x) - DEPRECATED
|
|
174
|
+
SQA::Indicator.rsi(prices, 14)
|
|
175
|
+
|
|
176
|
+
# New (v1.x) - Use sqa-talib
|
|
177
|
+
require 'sqa/talib'
|
|
178
|
+
SQA::TALib.rsi(prices, period: 14)
|
|
179
|
+
|
|
180
|
+
# Strategies stay the same
|
|
181
|
+
SQA::Strategy::RSI.new.analyze(data)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**Documentation needed:**
|
|
185
|
+
- MIGRATION.md - Upgrade guide for v0.x → v1.0
|
|
186
|
+
- Updated README explaining new architecture
|
|
187
|
+
- Deprecation notices for old APIs
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
### 3. sqa-cli (NEW - CLI Application)
|
|
192
|
+
|
|
193
|
+
**Repository:** https://github.com/MadBomber/sqa-cli
|
|
194
|
+
**Version:** 0.1.0
|
|
195
|
+
**Status:** To be created
|
|
196
|
+
|
|
197
|
+
**Purpose:** Complete command-line tool for stock analysis with AI
|
|
198
|
+
|
|
199
|
+
**What it contains:**
|
|
200
|
+
- CLI commands (analyze, backtest, report, web)
|
|
201
|
+
- Data loading (AlphaVantage, Yahoo Finance, CSV)
|
|
202
|
+
- Stock and Portfolio management
|
|
203
|
+
- Trade and Activity tracking
|
|
204
|
+
- SQLite persistence (NEW!)
|
|
205
|
+
- AI integration with ruby_llm (NEW!)
|
|
206
|
+
- Configuration management
|
|
207
|
+
- Web interface (to be completed)
|
|
208
|
+
|
|
209
|
+
**Dependencies:**
|
|
210
|
+
```ruby
|
|
211
|
+
# Core gems
|
|
212
|
+
spec.add_dependency 'sqa', '~> 1.0' # Strategies
|
|
213
|
+
spec.add_dependency 'sqa-talib', '~> 0.1' # Indicators
|
|
214
|
+
|
|
215
|
+
# CLI
|
|
216
|
+
spec.add_dependency 'dry-cli'
|
|
217
|
+
spec.add_dependency 'tty-table'
|
|
218
|
+
|
|
219
|
+
# Data sources
|
|
220
|
+
spec.add_dependency 'alphavantage'
|
|
221
|
+
spec.add_dependency 'faraday'
|
|
222
|
+
spec.add_dependency 'api_key_manager'
|
|
223
|
+
|
|
224
|
+
# Storage
|
|
225
|
+
spec.add_dependency 'sqlite3' # NEW!
|
|
226
|
+
|
|
227
|
+
# AI Integration
|
|
228
|
+
spec.add_dependency 'ruby_llm' # NEW!
|
|
229
|
+
spec.add_dependency 'ruby_llm-mcp' # NEW!
|
|
230
|
+
spec.add_dependency 'prompt_manager' # NEW!
|
|
231
|
+
|
|
232
|
+
# Utilities
|
|
233
|
+
spec.add_dependency 'nenv'
|
|
234
|
+
spec.add_dependency 'sem_version'
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**Structure:**
|
|
238
|
+
```
|
|
239
|
+
sqa-cli/
|
|
240
|
+
├── bin/sqa # Main executable
|
|
241
|
+
├── lib/sqa/cli/
|
|
242
|
+
│ ├── commands/
|
|
243
|
+
│ │ ├── analyze.rb # Portfolio analysis
|
|
244
|
+
│ │ ├── backtest.rb # Strategy backtesting
|
|
245
|
+
│ │ ├── report.rb # Report generation
|
|
246
|
+
│ │ └── web.rb # Web interface
|
|
247
|
+
│ ├── stock.rb
|
|
248
|
+
│ ├── portfolio.rb
|
|
249
|
+
│ ├── config.rb
|
|
250
|
+
│ ├── storage.rb # SQLite persistence
|
|
251
|
+
│ └── ai/ # AI integration
|
|
252
|
+
│ ├── client.rb # ruby_llm wrapper
|
|
253
|
+
│ ├── analyzer.rb # Strategy analysis
|
|
254
|
+
│ ├── commentator.rb # Market commentary
|
|
255
|
+
│ └── prompt_manager.rb # Prompt templates
|
|
256
|
+
└── docs/
|
|
257
|
+
├── installation.md
|
|
258
|
+
├── commands/
|
|
259
|
+
├── ai-integration/
|
|
260
|
+
└── tutorials/
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## AI Integration Strategy
|
|
266
|
+
|
|
267
|
+
### Libraries Used
|
|
268
|
+
|
|
269
|
+
1. **ruby_llm** - Core LLM integration
|
|
270
|
+
- Multi-provider support (OpenAI, Anthropic, local models)
|
|
271
|
+
- Unified API
|
|
272
|
+
|
|
273
|
+
2. **ruby_llm-mcp** - Model Context Protocol
|
|
274
|
+
- External data source integration
|
|
275
|
+
- Real-time market data feeds
|
|
276
|
+
- News and sentiment analysis
|
|
277
|
+
|
|
278
|
+
3. **prompt_manager** - Prompt template management
|
|
279
|
+
- Structured prompts for analysis
|
|
280
|
+
- Context-aware recommendations
|
|
281
|
+
- Configurable AI personality
|
|
282
|
+
|
|
283
|
+
### AI Features Planned
|
|
284
|
+
|
|
285
|
+
**Strategy Analysis:**
|
|
286
|
+
```bash
|
|
287
|
+
sqa analyze --ticker AAPL --ai-commentary
|
|
288
|
+
```
|
|
289
|
+
- LLM analyzes historical performance
|
|
290
|
+
- Recommends best strategies for specific stocks
|
|
291
|
+
- Explains reasoning in natural language
|
|
292
|
+
|
|
293
|
+
**Natural Language Queries:**
|
|
294
|
+
```bash
|
|
295
|
+
sqa query "What's the best strategy for AAPL in the last 6 months?"
|
|
296
|
+
```
|
|
297
|
+
- Parse user questions
|
|
298
|
+
- Run analysis
|
|
299
|
+
- Generate conversational responses
|
|
300
|
+
|
|
301
|
+
**Market Commentary:**
|
|
302
|
+
```bash
|
|
303
|
+
sqa report --portfolio portfolio.csv --ai-summary
|
|
304
|
+
```
|
|
305
|
+
- Generate portfolio summaries
|
|
306
|
+
- Explain indicator signals
|
|
307
|
+
- Risk assessment with reasoning
|
|
308
|
+
|
|
309
|
+
**Backtesting Narratives:**
|
|
310
|
+
```bash
|
|
311
|
+
sqa backtest --strategy rsi --ai-explain
|
|
312
|
+
```
|
|
313
|
+
- Analyze why strategy succeeded/failed
|
|
314
|
+
- Identify market conditions
|
|
315
|
+
- Suggest improvements
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## Key Decisions Made
|
|
320
|
+
|
|
321
|
+
### 1. TA-Lib vs Pure Ruby
|
|
322
|
+
**Decision:** Use TA-Lib C library (via ta_lib_ffi)
|
|
323
|
+
|
|
324
|
+
**Rationale:**
|
|
325
|
+
- 200+ battle-tested indicators
|
|
326
|
+
- 30x faster than pure Ruby
|
|
327
|
+
- Industry standard
|
|
328
|
+
- Well-documented
|
|
329
|
+
|
|
330
|
+
**Trade-off:** Requires system dependency (TA-Lib C library)
|
|
331
|
+
|
|
332
|
+
### 2. Repository Structure
|
|
333
|
+
**Decision:** 3 separate gems (sqa-talib, sqa, sqa-cli)
|
|
334
|
+
|
|
335
|
+
**Rationale:**
|
|
336
|
+
- Clear separation of concerns
|
|
337
|
+
- Users can pick what they need
|
|
338
|
+
- Each component focused and maintainable
|
|
339
|
+
- Library users don't need CLI dependencies
|
|
340
|
+
|
|
341
|
+
**Alternative considered:** Keep everything in sqa repo (rejected - too complex)
|
|
342
|
+
|
|
343
|
+
### 3. Namespace Strategy
|
|
344
|
+
**Decision:** Keep `SQA` namespace for all gems
|
|
345
|
+
|
|
346
|
+
**Rationale:**
|
|
347
|
+
- Simple for users
|
|
348
|
+
- No confusion with nested namespaces
|
|
349
|
+
- Clear module names distinguish purposes:
|
|
350
|
+
- `SQA::TALib` - Indicators
|
|
351
|
+
- `SQA::Strategy` - Strategies
|
|
352
|
+
- `SQA::CLI` - CLI commands
|
|
353
|
+
|
|
354
|
+
### 4. Version Numbers
|
|
355
|
+
**Decision:**
|
|
356
|
+
- sqa-talib: 0.1.0 (new gem)
|
|
357
|
+
- sqa: 0.0.25 → 1.0.0 (breaking changes)
|
|
358
|
+
- sqa-cli: 0.1.0 (new gem)
|
|
359
|
+
|
|
360
|
+
**Rationale:**
|
|
361
|
+
- v1.0.0 for sqa signals major refactoring
|
|
362
|
+
- Semantic versioning clearly indicates breaking changes
|
|
363
|
+
- New gems start at 0.1.0 (experimental)
|
|
364
|
+
|
|
365
|
+
### 5. Data Storage
|
|
366
|
+
**Decision:** SQLite for sqa-cli
|
|
367
|
+
|
|
368
|
+
**Rationale:**
|
|
369
|
+
- No server setup required
|
|
370
|
+
- Fast queries for analysis
|
|
371
|
+
- Single-file database (portable)
|
|
372
|
+
- Easy migration to PostgreSQL later if needed
|
|
373
|
+
- Keep CSV for portability and user editing
|
|
374
|
+
|
|
375
|
+
### 6. Documentation
|
|
376
|
+
**Decision:** MkDocs with Material theme, GitHub Pages hosting
|
|
377
|
+
|
|
378
|
+
**Rationale:**
|
|
379
|
+
- Beautiful, professional docs
|
|
380
|
+
- Easy to write (Markdown)
|
|
381
|
+
- Search, dark mode, responsive
|
|
382
|
+
- Auto-deployed via GitHub Actions
|
|
383
|
+
- Free hosting on GitHub Pages
|
|
384
|
+
|
|
385
|
+
### 7. Ruby Version
|
|
386
|
+
**Decision:** Require Ruby >= 3.1.0
|
|
387
|
+
|
|
388
|
+
**Rationale:**
|
|
389
|
+
- ta_lib_ffi requires Ruby >= 3.1
|
|
390
|
+
- Modern Ruby features
|
|
391
|
+
- Better performance
|
|
392
|
+
- Still widely supported
|
|
393
|
+
|
|
394
|
+
### 8. AI Library Choice
|
|
395
|
+
**Decision:** ruby_llm + ruby_llm-mcp + prompt_manager
|
|
396
|
+
|
|
397
|
+
**Rationale:**
|
|
398
|
+
- Multi-provider support (not locked to one LLM)
|
|
399
|
+
- MCP for external data integration
|
|
400
|
+
- Structured prompt management
|
|
401
|
+
- Active development
|
|
402
|
+
- Clean API
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
## Migration Guide (v0.x → v1.0)
|
|
407
|
+
|
|
408
|
+
### For Library Users
|
|
409
|
+
|
|
410
|
+
**Old way (v0.x):**
|
|
411
|
+
```ruby
|
|
412
|
+
require 'sqa'
|
|
413
|
+
|
|
414
|
+
prices = [100, 101, 102]
|
|
415
|
+
rsi = SQA::Indicator.rsi(prices, 14)
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
**New way (v1.0+):**
|
|
419
|
+
```ruby
|
|
420
|
+
require 'sqa/talib' # Add this gem
|
|
421
|
+
require 'sqa'
|
|
422
|
+
|
|
423
|
+
prices = [100, 101, 102]
|
|
424
|
+
rsi = SQA::TALib.rsi(prices, period: 14) # Changed!
|
|
425
|
+
|
|
426
|
+
# Strategies work the same
|
|
427
|
+
strategy = SQA::Strategy::RSI.new
|
|
428
|
+
signal = strategy.analyze(data)
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
### For CLI Users
|
|
432
|
+
|
|
433
|
+
**Old way:**
|
|
434
|
+
```bash
|
|
435
|
+
gem install sqa
|
|
436
|
+
sqa --help # Limited functionality
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
**New way:**
|
|
440
|
+
```bash
|
|
441
|
+
gem install sqa-cli # Different gem!
|
|
442
|
+
sqa --help # Full CLI with AI
|
|
443
|
+
|
|
444
|
+
# sqa-cli automatically installs sqa and sqa-talib
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### Deprecation Timeline
|
|
448
|
+
|
|
449
|
+
1. **v1.0.0 Release** - Indicators removed, point to sqa-talib
|
|
450
|
+
2. **v1.1.0** - Add deprecation warnings for old API
|
|
451
|
+
3. **v2.0.0** - Remove compatibility shims
|
|
452
|
+
|
|
453
|
+
---
|
|
454
|
+
|
|
455
|
+
## Implementation Timeline
|
|
456
|
+
|
|
457
|
+
### Phase 1: Foundation (Week 1-2) ✅ IN PROGRESS
|
|
458
|
+
- [x] Review codebase
|
|
459
|
+
- [x] Design architecture
|
|
460
|
+
- [x] Create sqa-talib gem
|
|
461
|
+
- [ ] Push to GitHub (blocked by repo authorization)
|
|
462
|
+
- [ ] Document decisions
|
|
463
|
+
|
|
464
|
+
### Phase 2: sqa Refactoring (Week 3-4)
|
|
465
|
+
- [ ] Remove indicator code from sqa
|
|
466
|
+
- [ ] Add sqa-talib dependency
|
|
467
|
+
- [ ] Update tests
|
|
468
|
+
- [ ] Create MIGRATION.md
|
|
469
|
+
- [ ] Update README
|
|
470
|
+
- [ ] Bump to v1.0.0
|
|
471
|
+
|
|
472
|
+
### Phase 3: sqa-cli Creation (Week 5-6)
|
|
473
|
+
- [ ] Create sqa-cli gem structure
|
|
474
|
+
- [ ] Migrate CLI code from sqa
|
|
475
|
+
- [ ] Add SQLite persistence
|
|
476
|
+
- [ ] Basic AI integration
|
|
477
|
+
- [ ] Complete commands
|
|
478
|
+
- [ ] Documentation
|
|
479
|
+
|
|
480
|
+
### Phase 4: AI Integration (Week 7-8)
|
|
481
|
+
- [ ] ruby_llm integration
|
|
482
|
+
- [ ] Prompt templates
|
|
483
|
+
- [ ] Strategy analyzer
|
|
484
|
+
- [ ] Natural language interface
|
|
485
|
+
- [ ] MCP integration
|
|
486
|
+
|
|
487
|
+
### Phase 5: Testing & Release (Week 9-10)
|
|
488
|
+
- [ ] Integration testing
|
|
489
|
+
- [ ] Performance testing
|
|
490
|
+
- [ ] Documentation review
|
|
491
|
+
- [ ] Beta release
|
|
492
|
+
- [ ] Gather feedback
|
|
493
|
+
- [ ] Official release
|
|
494
|
+
|
|
495
|
+
---
|
|
496
|
+
|
|
497
|
+
## Testing Strategy
|
|
498
|
+
|
|
499
|
+
### Unit Tests
|
|
500
|
+
- Each gem has independent test suite
|
|
501
|
+
- Minitest framework
|
|
502
|
+
- SimpleCov for coverage (target: 80%+)
|
|
503
|
+
- CI runs on Ruby 3.1, 3.2, 3.3
|
|
504
|
+
|
|
505
|
+
### Integration Tests
|
|
506
|
+
- Test sqa-cli with both dependencies
|
|
507
|
+
- Real-world usage scenarios
|
|
508
|
+
- Performance benchmarks
|
|
509
|
+
|
|
510
|
+
### Manual Testing
|
|
511
|
+
- Install all three gems together
|
|
512
|
+
- Run CLI commands
|
|
513
|
+
- Test AI integration
|
|
514
|
+
- Documentation accuracy
|
|
515
|
+
|
|
516
|
+
---
|
|
517
|
+
|
|
518
|
+
## Release Checklist
|
|
519
|
+
|
|
520
|
+
### sqa-talib
|
|
521
|
+
- [ ] All tests passing
|
|
522
|
+
- [ ] Documentation complete
|
|
523
|
+
- [ ] README accurate
|
|
524
|
+
- [ ] CHANGELOG updated
|
|
525
|
+
- [ ] Tagged release (v0.1.0)
|
|
526
|
+
- [ ] Push to RubyGems.org
|
|
527
|
+
- [ ] GitHub Pages docs deployed
|
|
528
|
+
|
|
529
|
+
### sqa
|
|
530
|
+
- [ ] Indicators removed
|
|
531
|
+
- [ ] sqa-talib integrated
|
|
532
|
+
- [ ] Tests updated and passing
|
|
533
|
+
- [ ] MIGRATION.md written
|
|
534
|
+
- [ ] README updated
|
|
535
|
+
- [ ] CHANGELOG updated (v1.0.0)
|
|
536
|
+
- [ ] Tagged release
|
|
537
|
+
- [ ] Push to RubyGems.org
|
|
538
|
+
- [ ] Announce breaking changes
|
|
539
|
+
|
|
540
|
+
### sqa-cli
|
|
541
|
+
- [ ] All features complete
|
|
542
|
+
- [ ] Tests passing
|
|
543
|
+
- [ ] Documentation complete
|
|
544
|
+
- [ ] AI integration working
|
|
545
|
+
- [ ] CHANGELOG updated
|
|
546
|
+
- [ ] Tagged release (v0.1.0)
|
|
547
|
+
- [ ] Push to RubyGems.org
|
|
548
|
+
- [ ] Demo video/tutorial
|
|
549
|
+
|
|
550
|
+
---
|
|
551
|
+
|
|
552
|
+
## Open Questions
|
|
553
|
+
|
|
554
|
+
1. **API Keys Configuration**
|
|
555
|
+
- How should users configure LLM API keys?
|
|
556
|
+
- Environment variables? Config file? Both?
|
|
557
|
+
|
|
558
|
+
2. **Web Interface**
|
|
559
|
+
- Rails or Sinatra?
|
|
560
|
+
- Should it be separate from CLI?
|
|
561
|
+
|
|
562
|
+
3. **Backtesting Engine**
|
|
563
|
+
- Should backtesting be in sqa (strategies) or sqa-cli (application)?
|
|
564
|
+
- Current plan: Core in sqa, CLI interface in sqa-cli
|
|
565
|
+
|
|
566
|
+
4. **Deployment**
|
|
567
|
+
- Will users deploy sqa-cli as a service?
|
|
568
|
+
- Container support needed?
|
|
569
|
+
|
|
570
|
+
---
|
|
571
|
+
|
|
572
|
+
## Risk Mitigation
|
|
573
|
+
|
|
574
|
+
### Risk: TA-Lib Installation Complexity
|
|
575
|
+
**Mitigation:**
|
|
576
|
+
- Comprehensive installation docs
|
|
577
|
+
- Docker image with TA-Lib pre-installed
|
|
578
|
+
- Error messages with installation instructions
|
|
579
|
+
|
|
580
|
+
### Risk: Breaking Changes in v1.0
|
|
581
|
+
**Mitigation:**
|
|
582
|
+
- Clear migration guide
|
|
583
|
+
- Deprecation warnings
|
|
584
|
+
- Blog post announcing changes
|
|
585
|
+
- Email to known users
|
|
586
|
+
|
|
587
|
+
### Risk: AI Integration Costs
|
|
588
|
+
**Mitigation:**
|
|
589
|
+
- Support multiple LLM providers (including free/local)
|
|
590
|
+
- Rate limiting
|
|
591
|
+
- Caching responses
|
|
592
|
+
- Optional feature (not required)
|
|
593
|
+
|
|
594
|
+
### Risk: Three Gems Coordination
|
|
595
|
+
**Mitigation:**
|
|
596
|
+
- Careful semantic versioning
|
|
597
|
+
- Integration tests
|
|
598
|
+
- Coordinated releases
|
|
599
|
+
- Clear dependency specifications
|
|
600
|
+
|
|
601
|
+
---
|
|
602
|
+
|
|
603
|
+
## Success Metrics
|
|
604
|
+
|
|
605
|
+
### Technical
|
|
606
|
+
- [ ] All tests passing
|
|
607
|
+
- [ ] 80%+ code coverage
|
|
608
|
+
- [ ] Documentation coverage: 100%
|
|
609
|
+
- [ ] Zero critical bugs
|
|
610
|
+
|
|
611
|
+
### User Adoption
|
|
612
|
+
- [ ] 100+ gem downloads in first month
|
|
613
|
+
- [ ] 5+ GitHub stars per repo
|
|
614
|
+
- [ ] Positive feedback on Reddit/HN
|
|
615
|
+
|
|
616
|
+
### Performance
|
|
617
|
+
- [ ] Indicator calculations <1ms (TA-Lib)
|
|
618
|
+
- [ ] CLI commands respond <5s
|
|
619
|
+
- [ ] AI queries <10s
|
|
620
|
+
|
|
621
|
+
---
|
|
622
|
+
|
|
623
|
+
## Resources
|
|
624
|
+
|
|
625
|
+
### Documentation
|
|
626
|
+
- [TA-Lib](https://ta-lib.org/) - C library documentation
|
|
627
|
+
- [ta_lib_ffi](https://github.com/TA-Lib/ta-lib-ruby) - Ruby FFI wrapper
|
|
628
|
+
- [ruby_llm](https://github.com/patterns-ai-core/ruby_llm) - LLM integration
|
|
629
|
+
- [MkDocs Material](https://squidfunk.github.io/mkdocs-material/) - Documentation theme
|
|
630
|
+
|
|
631
|
+
### Similar Projects
|
|
632
|
+
- [TA-Lib](https://github.com/mrjbq7/ta-lib) - Python wrapper
|
|
633
|
+
- [Backtrader](https://www.backtrader.com/) - Python backtesting framework
|
|
634
|
+
- [ruby-technical-analysis](https://github.com/intrinio/technical-analysis) - Pure Ruby indicators
|
|
635
|
+
|
|
636
|
+
---
|
|
637
|
+
|
|
638
|
+
## Contact & Support
|
|
639
|
+
|
|
640
|
+
- **Author:** Dewayne VanHoozer
|
|
641
|
+
- **Email:** dvanhoozer@gmail.com
|
|
642
|
+
- **GitHub:** https://github.com/MadBomber
|
|
643
|
+
- **Issues:** Use GitHub issues for each repository
|
|
644
|
+
|
|
645
|
+
---
|
|
646
|
+
|
|
647
|
+
**Last Updated:** 2025-01-05
|
|
648
|
+
**Next Review:** After sqa-talib repository access granted
|