sqa 0.0.31 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +104 -0
- data/CLAUDE.md +21 -0
- data/README.md +60 -32
- data/Rakefile +52 -10
- data/docs/IMPROVEMENT_PLAN.md +531 -0
- data/docs/advanced/index.md +1 -13
- data/docs/api/dataframe.md +0 -1
- data/docs/api/index.md +547 -61
- data/docs/api-reference/alphavantageapi.md +1057 -0
- data/docs/api-reference/apierror.md +31 -0
- data/docs/api-reference/index.md +221 -0
- data/docs/api-reference/notimplemented.md +27 -0
- data/docs/api-reference/sqa.md +267 -0
- data/docs/api-reference/sqa_backtest.md +137 -0
- data/docs/api-reference/sqa_backtest_results.md +530 -0
- data/docs/api-reference/sqa_badparametererror.md +13 -0
- data/docs/api-reference/sqa_config.md +538 -0
- data/docs/api-reference/sqa_configurationerror.md +13 -0
- data/docs/api-reference/sqa_datafetcherror.md +56 -0
- data/docs/api-reference/sqa_dataframe.md +752 -0
- data/docs/api-reference/sqa_dataframe_alphavantage.md +30 -0
- data/docs/api-reference/sqa_dataframe_data.md +325 -0
- data/docs/api-reference/sqa_dataframe_yahoofinance.md +25 -0
- data/docs/api-reference/sqa_ensemble.md +413 -0
- data/docs/api-reference/sqa_fpop.md +211 -0
- data/docs/api-reference/sqa_geneticprogram.md +325 -0
- data/docs/api-reference/sqa_geneticprogram_individual.md +114 -0
- data/docs/api-reference/sqa_marketregime.md +212 -0
- data/docs/api-reference/sqa_multitimeframe.md +227 -0
- data/docs/api-reference/sqa_patternmatcher.md +195 -0
- data/docs/api-reference/sqa_pluginmanager.md +55 -0
- data/docs/api-reference/sqa_portfolio.md +455 -0
- data/docs/api-reference/sqa_portfolio_position.md +220 -0
- data/docs/api-reference/sqa_portfolio_trade.md +332 -0
- data/docs/api-reference/sqa_portfoliooptimizer.md +248 -0
- data/docs/api-reference/sqa_riskmanager.md +388 -0
- data/docs/api-reference/sqa_seasonalanalyzer.md +121 -0
- data/docs/api-reference/sqa_sectoranalyzer.md +163 -0
- data/docs/api-reference/sqa_stock.md +649 -0
- data/docs/api-reference/sqa_strategy.md +178 -0
- data/docs/api-reference/sqa_strategy_bollingerbands.md +26 -0
- data/docs/api-reference/sqa_strategy_common.md +29 -0
- data/docs/api-reference/sqa_strategy_consensus.md +129 -0
- data/docs/api-reference/sqa_strategy_ema.md +41 -0
- data/docs/api-reference/sqa_strategy_kbs.md +154 -0
- data/docs/api-reference/sqa_strategy_macd.md +26 -0
- data/docs/api-reference/sqa_strategy_mp.md +41 -0
- data/docs/api-reference/sqa_strategy_mr.md +41 -0
- data/docs/api-reference/sqa_strategy_random.md +41 -0
- data/docs/api-reference/sqa_strategy_rsi.md +41 -0
- data/docs/api-reference/sqa_strategy_sma.md +41 -0
- data/docs/api-reference/sqa_strategy_stochastic.md +26 -0
- data/docs/api-reference/sqa_strategy_volumebreakout.md +26 -0
- data/docs/api-reference/sqa_strategygenerator.md +298 -0
- data/docs/api-reference/sqa_strategygenerator_pattern.md +264 -0
- data/docs/api-reference/sqa_strategygenerator_patterncontext.md +326 -0
- data/docs/api-reference/sqa_strategygenerator_profitablepoint.md +424 -0
- data/docs/api-reference/sqa_stream.md +256 -0
- data/docs/api-reference/sqa_ticker.md +175 -0
- data/docs/api-reference/string.md +135 -0
- data/docs/assets/images/advanced-workflow.svg +89 -0
- data/docs/assets/images/architecture.svg +107 -0
- data/docs/assets/images/data-flow.svg +138 -0
- data/docs/assets/images/getting-started-workflow.svg +88 -0
- data/docs/assets/images/sqa.jpg +0 -0
- data/docs/assets/images/strategy-flow.svg +78 -0
- data/docs/assets/images/system-architecture.svg +150 -0
- data/docs/concepts/index.md +292 -27
- data/docs/data_frame.md +0 -1
- data/docs/getting-started/index.md +1 -30
- data/docs/getting-started/installation.md +2 -2
- data/docs/getting-started/quick-start.md +4 -4
- data/docs/index.md +26 -25
- data/docs/llms.txt +109 -0
- data/docs/strategies/bollinger-bands.md +1 -1
- data/docs/strategies/kbs.md +15 -14
- data/docs/strategies/rsi.md +1 -1
- data/docs/strategy.md +381 -3
- data/docs/terms_of_use.md +1 -1
- data/examples/README.md +10 -0
- data/lib/api/alpha_vantage_api.rb +3 -7
- data/lib/sqa/config.rb +109 -28
- data/lib/sqa/data_frame/alpha_vantage.rb +13 -3
- data/lib/sqa/data_frame/data.rb +13 -1
- data/lib/sqa/data_frame.rb +189 -41
- data/lib/sqa/errors.rb +79 -17
- data/lib/sqa/indicator.rb +17 -4
- data/lib/sqa/init.rb +70 -15
- data/lib/sqa/pattern_matcher.rb +4 -4
- data/lib/sqa/portfolio.rb +1 -1
- data/lib/sqa/sector_analyzer.rb +3 -11
- data/lib/sqa/stock.rb +236 -20
- data/lib/sqa/strategy.rb +62 -4
- data/lib/sqa/ticker.rb +107 -42
- data/lib/sqa/version.rb +1 -1
- data/lib/sqa.rb +16 -8
- data/mkdocs.yml +68 -117
- metadata +90 -36
- data/docs/README.md +0 -43
- data/docs/alpha_vantage_technical_indicators.md +0 -62
- data/docs/average_true_range.md +0 -9
- data/docs/bollinger_bands.md +0 -15
- data/docs/candlestick_pattern_recognizer.md +0 -4
- data/docs/donchian_channel.md +0 -5
- data/docs/double_top_bottom_pattern.md +0 -3
- data/docs/exponential_moving_average.md +0 -19
- data/docs/fibonacci_retracement.md +0 -30
- data/docs/head_and_shoulders_pattern.md +0 -3
- data/docs/market_profile.md +0 -4
- data/docs/momentum.md +0 -19
- data/docs/moving_average_convergence_divergence.md +0 -23
- data/docs/peaks_and_valleys.md +0 -11
- data/docs/relative_strength_index.md +0 -6
- data/docs/simple_moving_average.md +0 -8
- data/docs/stochastic_oscillator.md +0 -4
- data/docs/ta_lib.md +0 -160
- data/docs/true_range.md +0 -12
- data/docs/true_strength_index.md +0 -46
- data/docs/weighted_moving_average.md +0 -48
- data/examples/sinatra_app/Gemfile +0 -22
- data/examples/sinatra_app/QUICKSTART.md +0 -159
- data/examples/sinatra_app/README.md +0 -461
- data/examples/sinatra_app/app.rb +0 -344
- data/examples/sinatra_app/config.ru +0 -5
- data/examples/sinatra_app/public/css/style.css +0 -659
- data/examples/sinatra_app/public/js/app.js +0 -107
- data/examples/sinatra_app/views/analyze.erb +0 -306
- data/examples/sinatra_app/views/backtest.erb +0 -325
- data/examples/sinatra_app/views/dashboard.erb +0 -419
- data/examples/sinatra_app/views/error.erb +0 -58
- data/examples/sinatra_app/views/index.erb +0 -118
- data/examples/sinatra_app/views/layout.erb +0 -61
- data/examples/sinatra_app/views/portfolio.erb +0 -43
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
# 📦 SQA::Portfolio::Trade
|
|
2
|
+
|
|
3
|
+
!!! note "Description"
|
|
4
|
+
Represents a single trade
|
|
5
|
+
|
|
6
|
+
!!! abstract "Source Information"
|
|
7
|
+
**Defined in:** `lib/sqa/portfolio.rb:27`
|
|
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:27`
|
|
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:27`
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
### `#action=(value)`
|
|
54
|
+
|
|
55
|
+
Sets the attribute action
|
|
56
|
+
|
|
57
|
+
!!! info "Parameters"
|
|
58
|
+
|
|
59
|
+
| Name | Type | Description |
|
|
60
|
+
|------|------|-------------|
|
|
61
|
+
| `value` | `Object` | the value to set the attribute action 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:27`
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
### `#action()`
|
|
76
|
+
|
|
77
|
+
Returns the value of attribute action
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
!!! success "Returns"
|
|
81
|
+
|
|
82
|
+
**Type:** `Object`
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
the current value of action
|
|
87
|
+
|
|
88
|
+
??? info "Source Location"
|
|
89
|
+
`lib/sqa/portfolio.rb:27`
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
### `#shares=(value)`
|
|
94
|
+
|
|
95
|
+
Sets the attribute shares
|
|
96
|
+
|
|
97
|
+
!!! info "Parameters"
|
|
98
|
+
|
|
99
|
+
| Name | Type | Description |
|
|
100
|
+
|------|------|-------------|
|
|
101
|
+
| `value` | `Object` | the value to set the attribute shares 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:27`
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
### `#shares()`
|
|
116
|
+
|
|
117
|
+
Returns the value of attribute shares
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
!!! success "Returns"
|
|
121
|
+
|
|
122
|
+
**Type:** `Object`
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
the current value of shares
|
|
127
|
+
|
|
128
|
+
??? info "Source Location"
|
|
129
|
+
`lib/sqa/portfolio.rb:27`
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
### `#price=(value)`
|
|
134
|
+
|
|
135
|
+
Sets the attribute price
|
|
136
|
+
|
|
137
|
+
!!! info "Parameters"
|
|
138
|
+
|
|
139
|
+
| Name | Type | Description |
|
|
140
|
+
|------|------|-------------|
|
|
141
|
+
| `value` | `Object` | the value to set the attribute price 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:27`
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
### `#price()`
|
|
156
|
+
|
|
157
|
+
Returns the value of attribute price
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
!!! success "Returns"
|
|
161
|
+
|
|
162
|
+
**Type:** `Object`
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
the current value of price
|
|
167
|
+
|
|
168
|
+
??? info "Source Location"
|
|
169
|
+
`lib/sqa/portfolio.rb:27`
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
### `#date=(value)`
|
|
174
|
+
|
|
175
|
+
Sets the attribute date
|
|
176
|
+
|
|
177
|
+
!!! info "Parameters"
|
|
178
|
+
|
|
179
|
+
| Name | Type | Description |
|
|
180
|
+
|------|------|-------------|
|
|
181
|
+
| `value` | `Object` | the value to set the attribute date to. |
|
|
182
|
+
!!! success "Returns"
|
|
183
|
+
|
|
184
|
+
**Type:** `Object`
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
the newly set value
|
|
189
|
+
|
|
190
|
+
??? info "Source Location"
|
|
191
|
+
`lib/sqa/portfolio.rb:27`
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
### `#date()`
|
|
196
|
+
|
|
197
|
+
Returns the value of attribute date
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
!!! success "Returns"
|
|
201
|
+
|
|
202
|
+
**Type:** `Object`
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
the current value of date
|
|
207
|
+
|
|
208
|
+
??? info "Source Location"
|
|
209
|
+
`lib/sqa/portfolio.rb:27`
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
### `#total=(value)`
|
|
214
|
+
|
|
215
|
+
Sets the attribute total
|
|
216
|
+
|
|
217
|
+
!!! info "Parameters"
|
|
218
|
+
|
|
219
|
+
| Name | Type | Description |
|
|
220
|
+
|------|------|-------------|
|
|
221
|
+
| `value` | `Object` | the value to set the attribute total to. |
|
|
222
|
+
!!! success "Returns"
|
|
223
|
+
|
|
224
|
+
**Type:** `Object`
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
the newly set value
|
|
229
|
+
|
|
230
|
+
??? info "Source Location"
|
|
231
|
+
`lib/sqa/portfolio.rb:27`
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
### `#total()`
|
|
236
|
+
|
|
237
|
+
Returns the value of attribute total
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
!!! success "Returns"
|
|
241
|
+
|
|
242
|
+
**Type:** `Object`
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
the current value of total
|
|
247
|
+
|
|
248
|
+
??? info "Source Location"
|
|
249
|
+
`lib/sqa/portfolio.rb:27`
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
### `#commission=(value)`
|
|
254
|
+
|
|
255
|
+
Sets the attribute commission
|
|
256
|
+
|
|
257
|
+
!!! info "Parameters"
|
|
258
|
+
|
|
259
|
+
| Name | Type | Description |
|
|
260
|
+
|------|------|-------------|
|
|
261
|
+
| `value` | `Object` | the value to set the attribute commission to. |
|
|
262
|
+
!!! success "Returns"
|
|
263
|
+
|
|
264
|
+
**Type:** `Object`
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
the newly set value
|
|
269
|
+
|
|
270
|
+
??? info "Source Location"
|
|
271
|
+
`lib/sqa/portfolio.rb:27`
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
### `#commission()`
|
|
276
|
+
|
|
277
|
+
Returns the value of attribute commission
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
!!! success "Returns"
|
|
281
|
+
|
|
282
|
+
**Type:** `Object`
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
the current value of commission
|
|
287
|
+
|
|
288
|
+
??? info "Source Location"
|
|
289
|
+
`lib/sqa/portfolio.rb:27`
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
### `#to_h()`
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
??? info "Source Location"
|
|
299
|
+
`lib/sqa/portfolio.rb:28`
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## 📝 Attributes
|
|
304
|
+
|
|
305
|
+
### 🔄 `ticker` <small>read/write</small>
|
|
306
|
+
|
|
307
|
+
Returns the value of attribute ticker
|
|
308
|
+
|
|
309
|
+
### 🔄 `action` <small>read/write</small>
|
|
310
|
+
|
|
311
|
+
Returns the value of attribute action
|
|
312
|
+
|
|
313
|
+
### 🔄 `shares` <small>read/write</small>
|
|
314
|
+
|
|
315
|
+
Returns the value of attribute shares
|
|
316
|
+
|
|
317
|
+
### 🔄 `price` <small>read/write</small>
|
|
318
|
+
|
|
319
|
+
Returns the value of attribute price
|
|
320
|
+
|
|
321
|
+
### 🔄 `date` <small>read/write</small>
|
|
322
|
+
|
|
323
|
+
Returns the value of attribute date
|
|
324
|
+
|
|
325
|
+
### 🔄 `total` <small>read/write</small>
|
|
326
|
+
|
|
327
|
+
Returns the value of attribute total
|
|
328
|
+
|
|
329
|
+
### 🔄 `commission` <small>read/write</small>
|
|
330
|
+
|
|
331
|
+
Returns the value of attribute commission
|
|
332
|
+
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# 📦 SQA::PortfolioOptimizer
|
|
2
|
+
|
|
3
|
+
!!! note "Description"
|
|
4
|
+
PortfolioOptimizer - Multi-objective portfolio optimization
|
|
5
|
+
|
|
6
|
+
Provides methods for:
|
|
7
|
+
- Mean-Variance Optimization (Markowitz)
|
|
8
|
+
- Multi-objective optimization (return vs risk vs drawdown)
|
|
9
|
+
- Efficient Frontier calculation
|
|
10
|
+
- Risk Parity allocation
|
|
11
|
+
- Minimum Variance portfolio
|
|
12
|
+
- Maximum Sharpe portfolio
|
|
13
|
+
|
|
14
|
+
!!! abstract "Source Information"
|
|
15
|
+
**Defined in:** `lib/sqa/portfolio_optimizer.rb:25`
|
|
16
|
+
|
|
17
|
+
**Inherits from:** `Object`
|
|
18
|
+
|
|
19
|
+
## 🏭 Class Methods
|
|
20
|
+
|
|
21
|
+
### `.portfolio_returns(returns_matrix, weights)`
|
|
22
|
+
|
|
23
|
+
Calculate portfolio returns given weights
|
|
24
|
+
|
|
25
|
+
!!! info "Parameters"
|
|
26
|
+
|
|
27
|
+
| Name | Type | Description |
|
|
28
|
+
|------|------|-------------|
|
|
29
|
+
| `returns_matrix` | `Array<Array<Float>>` | Returns for each asset (rows = assets, cols = periods) |
|
|
30
|
+
| `weights` | `Array<Float>` | Portfolio weights (must sum to 1.0) |
|
|
31
|
+
!!! success "Returns"
|
|
32
|
+
|
|
33
|
+
**Type:** `Array<Float>`
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
Portfolio returns over time
|
|
38
|
+
|
|
39
|
+
??? info "Source Location"
|
|
40
|
+
`lib/sqa/portfolio_optimizer.rb:34`
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
### `.portfolio_variance(returns_matrix, weights)`
|
|
45
|
+
|
|
46
|
+
Calculate portfolio variance
|
|
47
|
+
|
|
48
|
+
!!! info "Parameters"
|
|
49
|
+
|
|
50
|
+
| Name | Type | Description |
|
|
51
|
+
|------|------|-------------|
|
|
52
|
+
| `returns_matrix` | `Array<Array<Float>>` | Returns for each asset |
|
|
53
|
+
| `weights` | `Array<Float>` | Portfolio weights |
|
|
54
|
+
!!! success "Returns"
|
|
55
|
+
|
|
56
|
+
**Type:** `Float`
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
Portfolio variance
|
|
61
|
+
|
|
62
|
+
??? info "Source Location"
|
|
63
|
+
`lib/sqa/portfolio_optimizer.rb:51`
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
### `.maximum_sharpe(returns_matrix, risk_free_rate: = 0.02, constraints: = {})`
|
|
68
|
+
|
|
69
|
+
Find Maximum Sharpe Ratio portfolio
|
|
70
|
+
|
|
71
|
+
Uses numerical optimization to find weights that maximize Sharpe ratio.
|
|
72
|
+
|
|
73
|
+
!!! info "Parameters"
|
|
74
|
+
|
|
75
|
+
| Name | Type | Description |
|
|
76
|
+
|------|------|-------------|
|
|
77
|
+
| `returns_matrix` | `Array<Array<Float>>` | Returns for each asset |
|
|
78
|
+
| `risk_free_rate` | `Float` | Risk-free rate (default: 0.02) |
|
|
79
|
+
| `constraints` | `Hash` | Optimization constraints |
|
|
80
|
+
!!! success "Returns"
|
|
81
|
+
|
|
82
|
+
**Type:** `Hash`
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
{ weights: Array, sharpe: Float, return: Float, volatility: Float }
|
|
87
|
+
|
|
88
|
+
??? info "Source Location"
|
|
89
|
+
`lib/sqa/portfolio_optimizer.rb:75`
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
### `.minimum_variance(returns_matrix, constraints: = {})`
|
|
94
|
+
|
|
95
|
+
Find Minimum Variance portfolio
|
|
96
|
+
|
|
97
|
+
!!! info "Parameters"
|
|
98
|
+
|
|
99
|
+
| Name | Type | Description |
|
|
100
|
+
|------|------|-------------|
|
|
101
|
+
| `returns_matrix` | `Array<Array<Float>>` | Returns for each asset |
|
|
102
|
+
| `constraints` | `Hash` | Optimization constraints |
|
|
103
|
+
!!! success "Returns"
|
|
104
|
+
|
|
105
|
+
**Type:** `Hash`
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
{ weights: Array, variance: Float, volatility: Float }
|
|
110
|
+
|
|
111
|
+
??? info "Source Location"
|
|
112
|
+
`lib/sqa/portfolio_optimizer.rb:114`
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
### `.risk_parity(returns_matrix)`
|
|
117
|
+
|
|
118
|
+
Calculate Risk Parity portfolio
|
|
119
|
+
|
|
120
|
+
Allocate weights so each asset contributes equally to portfolio risk.
|
|
121
|
+
|
|
122
|
+
!!! info "Parameters"
|
|
123
|
+
|
|
124
|
+
| Name | Type | Description |
|
|
125
|
+
|------|------|-------------|
|
|
126
|
+
| `returns_matrix` | `Array<Array<Float>>` | Returns for each asset |
|
|
127
|
+
!!! success "Returns"
|
|
128
|
+
|
|
129
|
+
**Type:** `Hash`
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
{ weights: Array, volatility: Float }
|
|
134
|
+
|
|
135
|
+
??? info "Source Location"
|
|
136
|
+
`lib/sqa/portfolio_optimizer.rb:146`
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
### `.efficient_frontier(returns_matrix, num_portfolios: = 50)`
|
|
141
|
+
|
|
142
|
+
Calculate Efficient Frontier
|
|
143
|
+
|
|
144
|
+
Generate portfolios along the efficient frontier.
|
|
145
|
+
|
|
146
|
+
!!! info "Parameters"
|
|
147
|
+
|
|
148
|
+
| Name | Type | Description |
|
|
149
|
+
|------|------|-------------|
|
|
150
|
+
| `returns_matrix` | `Array<Array<Float>>` | Returns for each asset |
|
|
151
|
+
| `num_portfolios` | `Integer` | Number of portfolios to generate |
|
|
152
|
+
!!! success "Returns"
|
|
153
|
+
|
|
154
|
+
**Type:** `Array<Hash>`
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
Array of portfolio hashes
|
|
159
|
+
|
|
160
|
+
??? info "Source Location"
|
|
161
|
+
`lib/sqa/portfolio_optimizer.rb:175`
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
### `.multi_objective(returns_matrix, objectives: = {})`
|
|
166
|
+
|
|
167
|
+
Multi-objective optimization
|
|
168
|
+
|
|
169
|
+
Optimize portfolio for multiple objectives simultaneously.
|
|
170
|
+
|
|
171
|
+
!!! info "Parameters"
|
|
172
|
+
|
|
173
|
+
| Name | Type | Description |
|
|
174
|
+
|------|------|-------------|
|
|
175
|
+
| `returns_matrix` | `Array<Array<Float>>` | Returns for each asset |
|
|
176
|
+
| `objectives` | `Hash` | Objectives with weights |
|
|
177
|
+
!!! success "Returns"
|
|
178
|
+
|
|
179
|
+
**Type:** `Hash`
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
Optimal portfolio
|
|
184
|
+
!!! example "Usage Examples"
|
|
185
|
+
|
|
186
|
+
```ruby
|
|
187
|
+
result = SQA::PortfolioOptimizer.multi_objective(
|
|
188
|
+
returns_matrix,
|
|
189
|
+
objectives: {
|
|
190
|
+
maximize_return: 0.4,
|
|
191
|
+
minimize_volatility: 0.3,
|
|
192
|
+
minimize_drawdown: 0.3
|
|
193
|
+
}
|
|
194
|
+
)
|
|
195
|
+
```
|
|
196
|
+
??? info "Source Location"
|
|
197
|
+
`lib/sqa/portfolio_optimizer.rb:217`
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
### `.equal_weight(num_assets)`
|
|
202
|
+
|
|
203
|
+
Equal weight portfolio (1/N rule)
|
|
204
|
+
|
|
205
|
+
!!! info "Parameters"
|
|
206
|
+
|
|
207
|
+
| Name | Type | Description |
|
|
208
|
+
|------|------|-------------|
|
|
209
|
+
| `num_assets` | `Integer` | Number of assets |
|
|
210
|
+
!!! success "Returns"
|
|
211
|
+
|
|
212
|
+
**Type:** `Array<Float>`
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
Equal weights
|
|
217
|
+
|
|
218
|
+
??? info "Source Location"
|
|
219
|
+
`lib/sqa/portfolio_optimizer.rb:285`
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
### `.rebalance(current_values:, target_weights:, total_value:, prices:)`
|
|
224
|
+
|
|
225
|
+
Rebalance portfolio to target weights
|
|
226
|
+
|
|
227
|
+
!!! info "Parameters"
|
|
228
|
+
|
|
229
|
+
| Name | Type | Description |
|
|
230
|
+
|------|------|-------------|
|
|
231
|
+
| `current_values` | `Hash` | Current holdings { ticker => value } |
|
|
232
|
+
| `target_weights` | `Hash` | Target weights { ticker => weight } |
|
|
233
|
+
| `total_value` | `Float` | Total portfolio value |
|
|
234
|
+
!!! success "Returns"
|
|
235
|
+
|
|
236
|
+
**Type:** `Hash`
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
Rebalancing trades { ticker => { action: :buy/:sell, shares: N, value: $ } }
|
|
241
|
+
|
|
242
|
+
??? info "Source Location"
|
|
243
|
+
`lib/sqa/portfolio_optimizer.rb:298`
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## 📝 Attributes
|
|
248
|
+
|