sqa 0.0.32 → 0.0.37

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 (109) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +92 -1
  3. data/README.md +4 -0
  4. data/Rakefile +52 -10
  5. data/docs/IMPROVEMENT_PLAN.md +531 -0
  6. data/docs/advanced/index.md +1 -13
  7. data/docs/api/index.md +547 -61
  8. data/docs/api-reference/alphavantageapi.md +1057 -0
  9. data/docs/api-reference/apierror.md +31 -0
  10. data/docs/api-reference/index.md +221 -0
  11. data/docs/api-reference/notimplemented.md +27 -0
  12. data/docs/api-reference/sqa.md +267 -0
  13. data/docs/api-reference/sqa_backtest.md +137 -0
  14. data/docs/api-reference/sqa_backtest_results.md +530 -0
  15. data/docs/api-reference/sqa_badparametererror.md +13 -0
  16. data/docs/api-reference/sqa_config.md +538 -0
  17. data/docs/api-reference/sqa_configurationerror.md +13 -0
  18. data/docs/api-reference/sqa_datafetcherror.md +56 -0
  19. data/docs/api-reference/sqa_dataframe.md +752 -0
  20. data/docs/api-reference/sqa_dataframe_alphavantage.md +30 -0
  21. data/docs/api-reference/sqa_dataframe_data.md +325 -0
  22. data/docs/api-reference/sqa_dataframe_yahoofinance.md +25 -0
  23. data/docs/api-reference/sqa_ensemble.md +413 -0
  24. data/docs/api-reference/sqa_fpop.md +211 -0
  25. data/docs/api-reference/sqa_geneticprogram.md +325 -0
  26. data/docs/api-reference/sqa_geneticprogram_individual.md +114 -0
  27. data/docs/api-reference/sqa_marketregime.md +212 -0
  28. data/docs/api-reference/sqa_multitimeframe.md +227 -0
  29. data/docs/api-reference/sqa_patternmatcher.md +195 -0
  30. data/docs/api-reference/sqa_pluginmanager.md +55 -0
  31. data/docs/api-reference/sqa_portfolio.md +455 -0
  32. data/docs/api-reference/sqa_portfolio_position.md +220 -0
  33. data/docs/api-reference/sqa_portfolio_trade.md +332 -0
  34. data/docs/api-reference/sqa_portfoliooptimizer.md +248 -0
  35. data/docs/api-reference/sqa_riskmanager.md +388 -0
  36. data/docs/api-reference/sqa_seasonalanalyzer.md +121 -0
  37. data/docs/api-reference/sqa_sectoranalyzer.md +163 -0
  38. data/docs/api-reference/sqa_stock.md +649 -0
  39. data/docs/api-reference/sqa_strategy.md +178 -0
  40. data/docs/api-reference/sqa_strategy_bollingerbands.md +26 -0
  41. data/docs/api-reference/sqa_strategy_common.md +29 -0
  42. data/docs/api-reference/sqa_strategy_consensus.md +129 -0
  43. data/docs/api-reference/sqa_strategy_ema.md +41 -0
  44. data/docs/api-reference/sqa_strategy_kbs.md +154 -0
  45. data/docs/api-reference/sqa_strategy_macd.md +26 -0
  46. data/docs/api-reference/sqa_strategy_mp.md +41 -0
  47. data/docs/api-reference/sqa_strategy_mr.md +41 -0
  48. data/docs/api-reference/sqa_strategy_random.md +41 -0
  49. data/docs/api-reference/sqa_strategy_rsi.md +41 -0
  50. data/docs/api-reference/sqa_strategy_sma.md +41 -0
  51. data/docs/api-reference/sqa_strategy_stochastic.md +26 -0
  52. data/docs/api-reference/sqa_strategy_volumebreakout.md +26 -0
  53. data/docs/api-reference/sqa_strategygenerator.md +298 -0
  54. data/docs/api-reference/sqa_strategygenerator_pattern.md +264 -0
  55. data/docs/api-reference/sqa_strategygenerator_patterncontext.md +326 -0
  56. data/docs/api-reference/sqa_strategygenerator_profitablepoint.md +424 -0
  57. data/docs/api-reference/sqa_stream.md +256 -0
  58. data/docs/api-reference/sqa_ticker.md +175 -0
  59. data/docs/api-reference/string.md +135 -0
  60. data/docs/assets/images/advanced-workflow.svg +89 -0
  61. data/docs/assets/images/architecture.svg +107 -0
  62. data/docs/assets/images/data-flow.svg +138 -0
  63. data/docs/assets/images/getting-started-workflow.svg +88 -0
  64. data/docs/assets/images/strategy-flow.svg +78 -0
  65. data/docs/assets/images/system-architecture.svg +150 -0
  66. data/docs/concepts/index.md +292 -19
  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/config.rb +109 -28
  76. data/lib/sqa/data_frame/data.rb +13 -1
  77. data/lib/sqa/data_frame.rb +168 -26
  78. data/lib/sqa/errors.rb +79 -17
  79. data/lib/sqa/init.rb +70 -15
  80. data/lib/sqa/pattern_matcher.rb +4 -4
  81. data/lib/sqa/portfolio.rb +1 -1
  82. data/lib/sqa/sector_analyzer.rb +3 -11
  83. data/lib/sqa/stock.rb +169 -15
  84. data/lib/sqa/strategy.rb +62 -4
  85. data/lib/sqa/ticker.rb +106 -48
  86. data/lib/sqa/version.rb +1 -1
  87. data/lib/sqa.rb +4 -4
  88. data/mkdocs.yml +68 -81
  89. metadata +89 -21
  90. data/docs/README.md +0 -43
  91. data/examples/sinatra_app/Gemfile +0 -42
  92. data/examples/sinatra_app/Gemfile.lock +0 -268
  93. data/examples/sinatra_app/QUICKSTART.md +0 -169
  94. data/examples/sinatra_app/README.md +0 -471
  95. data/examples/sinatra_app/RUNNING_WITHOUT_TALIB.md +0 -90
  96. data/examples/sinatra_app/TROUBLESHOOTING.md +0 -95
  97. data/examples/sinatra_app/app.rb +0 -404
  98. data/examples/sinatra_app/config.ru +0 -5
  99. data/examples/sinatra_app/public/css/style.css +0 -723
  100. data/examples/sinatra_app/public/debug_macd.html +0 -82
  101. data/examples/sinatra_app/public/js/app.js +0 -107
  102. data/examples/sinatra_app/start.sh +0 -53
  103. data/examples/sinatra_app/views/analyze.erb +0 -306
  104. data/examples/sinatra_app/views/backtest.erb +0 -325
  105. data/examples/sinatra_app/views/dashboard.erb +0 -831
  106. data/examples/sinatra_app/views/error.erb +0 -58
  107. data/examples/sinatra_app/views/index.erb +0 -118
  108. data/examples/sinatra_app/views/layout.erb +0 -61
  109. data/examples/sinatra_app/views/portfolio.erb +0 -43
@@ -0,0 +1,455 @@
1
+ # 📦 SQA::Portfolio
2
+
3
+ !!! abstract "Source Information"
4
+ **Defined in:** `lib/sqa/portfolio.rb:7`
5
+
6
+ **Inherits from:** `Object`
7
+
8
+ ## 🏭 Class Methods
9
+
10
+ ### `.load_from_csv(filename)`
11
+
12
+ Load portfolio from CSV file
13
+
14
+ !!! info "Parameters"
15
+
16
+ | Name | Type | Description |
17
+ |------|------|-------------|
18
+ | `filename` | `String` | Path to CSV file |
19
+
20
+
21
+ ??? info "Source Location"
22
+ `lib/sqa/portfolio.rb:236`
23
+
24
+ ---
25
+
26
+ ## 🔨 Instance Methods
27
+
28
+ ### `#positions()`
29
+
30
+ Returns the value of attribute positions.
31
+
32
+
33
+
34
+
35
+ ??? info "Source Location"
36
+ `lib/sqa/portfolio.rb:8`
37
+
38
+ ---
39
+
40
+ ### `#positions=(value)`
41
+
42
+ Sets the attribute positions
43
+
44
+ !!! info "Parameters"
45
+
46
+ | Name | Type | Description |
47
+ |------|------|-------------|
48
+ | `value` | `Any` | the value to set the attribute positions to. |
49
+
50
+
51
+ ??? info "Source Location"
52
+ `lib/sqa/portfolio.rb:8`
53
+
54
+ ---
55
+
56
+ ### `#trades()`
57
+
58
+ Returns the value of attribute trades.
59
+
60
+
61
+
62
+
63
+ ??? info "Source Location"
64
+ `lib/sqa/portfolio.rb:8`
65
+
66
+ ---
67
+
68
+ ### `#trades=(value)`
69
+
70
+ Sets the attribute trades
71
+
72
+ !!! info "Parameters"
73
+
74
+ | Name | Type | Description |
75
+ |------|------|-------------|
76
+ | `value` | `Any` | the value to set the attribute trades to. |
77
+
78
+
79
+ ??? info "Source Location"
80
+ `lib/sqa/portfolio.rb:8`
81
+
82
+ ---
83
+
84
+ ### `#cash()`
85
+
86
+ Returns the value of attribute cash.
87
+
88
+
89
+
90
+
91
+ ??? info "Source Location"
92
+ `lib/sqa/portfolio.rb:8`
93
+
94
+ ---
95
+
96
+ ### `#cash=(value)`
97
+
98
+ Sets the attribute cash
99
+
100
+ !!! info "Parameters"
101
+
102
+ | Name | Type | Description |
103
+ |------|------|-------------|
104
+ | `value` | `Any` | the value to set the attribute cash to. |
105
+
106
+
107
+ ??? info "Source Location"
108
+ `lib/sqa/portfolio.rb:8`
109
+
110
+ ---
111
+
112
+ ### `#initial_cash()`
113
+
114
+ Returns the value of attribute initial_cash.
115
+
116
+
117
+
118
+
119
+ ??? info "Source Location"
120
+ `lib/sqa/portfolio.rb:8`
121
+
122
+ ---
123
+
124
+ ### `#initial_cash=(value)`
125
+
126
+ Sets the attribute initial_cash
127
+
128
+ !!! info "Parameters"
129
+
130
+ | Name | Type | Description |
131
+ |------|------|-------------|
132
+ | `value` | `Any` | the value to set the attribute initial_cash to. |
133
+
134
+
135
+ ??? info "Source Location"
136
+ `lib/sqa/portfolio.rb:8`
137
+
138
+ ---
139
+
140
+ ### `#commission()`
141
+
142
+ Returns the value of attribute commission.
143
+
144
+
145
+
146
+
147
+ ??? info "Source Location"
148
+ `lib/sqa/portfolio.rb:8`
149
+
150
+ ---
151
+
152
+ ### `#commission=(value)`
153
+
154
+ Sets the attribute commission
155
+
156
+ !!! info "Parameters"
157
+
158
+ | Name | Type | Description |
159
+ |------|------|-------------|
160
+ | `value` | `Any` | the value to set the attribute commission to. |
161
+
162
+
163
+ ??? info "Source Location"
164
+ `lib/sqa/portfolio.rb:8`
165
+
166
+ ---
167
+
168
+ ### `#initialize(initial_cash: = 10_000.0, commission: = 0.0)`
169
+
170
+
171
+ !!! success "Returns"
172
+
173
+ **Type:** `Portfolio`
174
+
175
+
176
+
177
+ a new instance of Portfolio
178
+
179
+ ??? info "Source Location"
180
+ `lib/sqa/portfolio.rb:41`
181
+
182
+ ---
183
+
184
+ ### `#buy(ticker, shares:, price:, date: = Date.today)`
185
+
186
+ Buy shares of a stock
187
+
188
+ !!! info "Parameters"
189
+
190
+ | Name | Type | Description |
191
+ |------|------|-------------|
192
+ | `ticker` | `String` | Stock ticker symbol |
193
+ | `shares` | `Integer` | Number of shares to buy |
194
+ | `price` | `Float` | Price per share |
195
+ | `date` | `Date` | Date of trade |
196
+ !!! success "Returns"
197
+
198
+ **Type:** `Trade`
199
+
200
+
201
+
202
+ The executed trade
203
+
204
+ ??? info "Source Location"
205
+ `lib/sqa/portfolio.rb:55`
206
+
207
+ ---
208
+
209
+ ### `#sell(ticker, shares:, price:, date: = Date.today)`
210
+
211
+ Sell shares of a stock
212
+
213
+ !!! info "Parameters"
214
+
215
+ | Name | Type | Description |
216
+ |------|------|-------------|
217
+ | `ticker` | `String` | Stock ticker symbol |
218
+ | `shares` | `Integer` | Number of shares to sell |
219
+ | `price` | `Float` | Price per share |
220
+ | `date` | `Date` | Date of trade |
221
+ !!! success "Returns"
222
+
223
+ **Type:** `Trade`
224
+
225
+
226
+
227
+ The executed trade
228
+
229
+ ??? info "Source Location"
230
+ `lib/sqa/portfolio.rb:98`
231
+
232
+ ---
233
+
234
+ ### `#position(ticker)`
235
+
236
+ Get current position for a ticker
237
+
238
+ !!! info "Parameters"
239
+
240
+ | Name | Type | Description |
241
+ |------|------|-------------|
242
+ | `ticker` | `String` | Stock ticker symbol |
243
+ !!! success "Returns"
244
+
245
+ **Type:** `Position, nil`
246
+
247
+
248
+
249
+ The position or nil if not found
250
+
251
+ ??? info "Source Location"
252
+ `lib/sqa/portfolio.rb:135`
253
+
254
+ ---
255
+
256
+ ### `#all_positions()`
257
+
258
+ Get all current positions
259
+
260
+
261
+ !!! success "Returns"
262
+
263
+ **Type:** `Hash`
264
+
265
+
266
+
267
+ Hash of ticker => Position
268
+
269
+ ??? info "Source Location"
270
+ `lib/sqa/portfolio.rb:141`
271
+
272
+ ---
273
+
274
+ ### `#value(current_prices = {})`
275
+
276
+ Calculate total portfolio value
277
+
278
+ !!! info "Parameters"
279
+
280
+ | Name | Type | Description |
281
+ |------|------|-------------|
282
+ | `current_prices` | `Hash` | Hash of ticker => current_price |
283
+ !!! success "Returns"
284
+
285
+ **Type:** `Float`
286
+
287
+
288
+
289
+ Total portfolio value (cash + positions)
290
+
291
+ ??? info "Source Location"
292
+ `lib/sqa/portfolio.rb:148`
293
+
294
+ ---
295
+
296
+ ### `#profit_loss(current_prices = {})`
297
+
298
+ Calculate total profit/loss across all positions
299
+
300
+ !!! info "Parameters"
301
+
302
+ | Name | Type | Description |
303
+ |------|------|-------------|
304
+ | `current_prices` | `Hash` | Hash of ticker => current_price |
305
+ !!! success "Returns"
306
+
307
+ **Type:** `Float`
308
+
309
+
310
+
311
+ Total P&L
312
+
313
+ ??? info "Source Location"
314
+ `lib/sqa/portfolio.rb:160`
315
+
316
+ ---
317
+
318
+ ### `#profit_loss_percent(current_prices = {})`
319
+
320
+ Calculate profit/loss percentage
321
+
322
+ !!! info "Parameters"
323
+
324
+ | Name | Type | Description |
325
+ |------|------|-------------|
326
+ | `current_prices` | `Hash` | Hash of ticker => current_price |
327
+ !!! success "Returns"
328
+
329
+ **Type:** `Float`
330
+
331
+
332
+
333
+ P&L percentage
334
+
335
+ ??? info "Source Location"
336
+ `lib/sqa/portfolio.rb:167`
337
+
338
+ ---
339
+
340
+ ### `#total_return(current_prices = {})`
341
+
342
+ Calculate total return (including dividends if tracked)
343
+
344
+ !!! info "Parameters"
345
+
346
+ | Name | Type | Description |
347
+ |------|------|-------------|
348
+ | `current_prices` | `Hash` | Hash of ticker => current_price |
349
+ !!! success "Returns"
350
+
351
+ **Type:** `Float`
352
+
353
+
354
+
355
+ Total return as decimal (e.g., 0.15 for 15%)
356
+
357
+ ??? info "Source Location"
358
+ `lib/sqa/portfolio.rb:175`
359
+
360
+ ---
361
+
362
+ ### `#trade_history()`
363
+
364
+ Get trade history
365
+
366
+
367
+ !!! success "Returns"
368
+
369
+ **Type:** `Array<Trade>`
370
+
371
+
372
+
373
+ Array of all trades
374
+
375
+ ??? info "Source Location"
376
+ `lib/sqa/portfolio.rb:182`
377
+
378
+ ---
379
+
380
+ ### `#summary(current_prices = {})`
381
+
382
+ Get summary statistics
383
+
384
+ !!! info "Parameters"
385
+
386
+ | Name | Type | Description |
387
+ |------|------|-------------|
388
+ | `current_prices` | `Hash` | Hash of ticker => current_price |
389
+ !!! success "Returns"
390
+
391
+ **Type:** `Hash`
392
+
393
+
394
+
395
+ Summary statistics
396
+
397
+ ??? info "Source Location"
398
+ `lib/sqa/portfolio.rb:189`
399
+
400
+ ---
401
+
402
+ ### `#save_to_csv(filename)`
403
+
404
+ Save portfolio to CSV file
405
+
406
+ !!! info "Parameters"
407
+
408
+ | Name | Type | Description |
409
+ |------|------|-------------|
410
+ | `filename` | `String` | Path to CSV file |
411
+
412
+
413
+ ??? info "Source Location"
414
+ `lib/sqa/portfolio.rb:206`
415
+
416
+ ---
417
+
418
+ ### `#save_trades_to_csv(filename)`
419
+
420
+ Save trade history to CSV file
421
+
422
+ !!! info "Parameters"
423
+
424
+ | Name | Type | Description |
425
+ |------|------|-------------|
426
+ | `filename` | `String` | Path to CSV file |
427
+
428
+
429
+ ??? info "Source Location"
430
+ `lib/sqa/portfolio.rb:217`
431
+
432
+ ---
433
+
434
+ ## 📝 Attributes
435
+
436
+ ### 🔄 `positions` <small>read/write</small>
437
+
438
+ Returns the value of attribute positions.
439
+
440
+ ### 🔄 `trades` <small>read/write</small>
441
+
442
+ Returns the value of attribute trades.
443
+
444
+ ### 🔄 `cash` <small>read/write</small>
445
+
446
+ Returns the value of attribute cash.
447
+
448
+ ### 🔄 `initial_cash` <small>read/write</small>
449
+
450
+ Returns the value of attribute initial_cash.
451
+
452
+ ### 🔄 `commission` <small>read/write</small>
453
+
454
+ Returns the value of attribute commission.
455
+
@@ -0,0 +1,220 @@
1
+ # 📦 SQA::Portfolio::Position
2
+
3
+ !!! note "Description"
4
+ Represents a single position in the portfolio
5
+
6
+ !!! abstract "Source Information"
7
+ **Defined in:** `lib/sqa/portfolio.rb:11`
8
+
9
+ **Inherits from:** `Struct`
10
+
11
+ ## 🔨 Instance Methods
12
+
13
+ ### `#ticker=(value)`
14
+
15
+ Sets the attribute ticker
16
+
17
+ !!! info "Parameters"
18
+
19
+ | Name | Type | Description |
20
+ |------|------|-------------|
21
+ | `value` | `Object` | the value to set the attribute ticker to. |
22
+ !!! success "Returns"
23
+
24
+ **Type:** `Object`
25
+
26
+
27
+
28
+ the newly set value
29
+
30
+ ??? info "Source Location"
31
+ `lib/sqa/portfolio.rb:11`
32
+
33
+ ---
34
+
35
+ ### `#ticker()`
36
+
37
+ Returns the value of attribute ticker
38
+
39
+
40
+ !!! success "Returns"
41
+
42
+ **Type:** `Object`
43
+
44
+
45
+
46
+ the current value of ticker
47
+
48
+ ??? info "Source Location"
49
+ `lib/sqa/portfolio.rb:11`
50
+
51
+ ---
52
+
53
+ ### `#shares=(value)`
54
+
55
+ Sets the attribute shares
56
+
57
+ !!! info "Parameters"
58
+
59
+ | Name | Type | Description |
60
+ |------|------|-------------|
61
+ | `value` | `Object` | the value to set the attribute shares to. |
62
+ !!! success "Returns"
63
+
64
+ **Type:** `Object`
65
+
66
+
67
+
68
+ the newly set value
69
+
70
+ ??? info "Source Location"
71
+ `lib/sqa/portfolio.rb:11`
72
+
73
+ ---
74
+
75
+ ### `#shares()`
76
+
77
+ Returns the value of attribute shares
78
+
79
+
80
+ !!! success "Returns"
81
+
82
+ **Type:** `Object`
83
+
84
+
85
+
86
+ the current value of shares
87
+
88
+ ??? info "Source Location"
89
+ `lib/sqa/portfolio.rb:11`
90
+
91
+ ---
92
+
93
+ ### `#avg_cost=(value)`
94
+
95
+ Sets the attribute avg_cost
96
+
97
+ !!! info "Parameters"
98
+
99
+ | Name | Type | Description |
100
+ |------|------|-------------|
101
+ | `value` | `Object` | the value to set the attribute avg_cost to. |
102
+ !!! success "Returns"
103
+
104
+ **Type:** `Object`
105
+
106
+
107
+
108
+ the newly set value
109
+
110
+ ??? info "Source Location"
111
+ `lib/sqa/portfolio.rb:11`
112
+
113
+ ---
114
+
115
+ ### `#avg_cost()`
116
+
117
+ Returns the value of attribute avg_cost
118
+
119
+
120
+ !!! success "Returns"
121
+
122
+ **Type:** `Object`
123
+
124
+
125
+
126
+ the current value of avg_cost
127
+
128
+ ??? info "Source Location"
129
+ `lib/sqa/portfolio.rb:11`
130
+
131
+ ---
132
+
133
+ ### `#total_cost=(value)`
134
+
135
+ Sets the attribute total_cost
136
+
137
+ !!! info "Parameters"
138
+
139
+ | Name | Type | Description |
140
+ |------|------|-------------|
141
+ | `value` | `Object` | the value to set the attribute total_cost to. |
142
+ !!! success "Returns"
143
+
144
+ **Type:** `Object`
145
+
146
+
147
+
148
+ the newly set value
149
+
150
+ ??? info "Source Location"
151
+ `lib/sqa/portfolio.rb:11`
152
+
153
+ ---
154
+
155
+ ### `#total_cost()`
156
+
157
+ Returns the value of attribute total_cost
158
+
159
+
160
+ !!! success "Returns"
161
+
162
+ **Type:** `Object`
163
+
164
+
165
+
166
+ the current value of total_cost
167
+
168
+ ??? info "Source Location"
169
+ `lib/sqa/portfolio.rb:11`
170
+
171
+ ---
172
+
173
+ ### `#value(current_price)`
174
+
175
+
176
+
177
+
178
+ ??? info "Source Location"
179
+ `lib/sqa/portfolio.rb:12`
180
+
181
+ ---
182
+
183
+ ### `#profit_loss(current_price)`
184
+
185
+
186
+
187
+
188
+ ??? info "Source Location"
189
+ `lib/sqa/portfolio.rb:16`
190
+
191
+ ---
192
+
193
+ ### `#profit_loss_percent(current_price)`
194
+
195
+
196
+
197
+
198
+ ??? info "Source Location"
199
+ `lib/sqa/portfolio.rb:20`
200
+
201
+ ---
202
+
203
+ ## 📝 Attributes
204
+
205
+ ### 🔄 `ticker` <small>read/write</small>
206
+
207
+ Returns the value of attribute ticker
208
+
209
+ ### 🔄 `shares` <small>read/write</small>
210
+
211
+ Returns the value of attribute shares
212
+
213
+ ### 🔄 `avg_cost` <small>read/write</small>
214
+
215
+ Returns the value of attribute avg_cost
216
+
217
+ ### 🔄 `total_cost` <small>read/write</small>
218
+
219
+ Returns the value of attribute total_cost
220
+