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
@@ -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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L27)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L27)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L27)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L27)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L27)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L27)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L27)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L27)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L27)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L27)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L27)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L27)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L27)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L27)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L27)
290
+
291
+ ---
292
+
293
+ ### `#to_h()`
294
+
295
+
296
+
297
+
298
+ ??? info "Source Location"
299
+ [`lib/sqa/portfolio.rb:28`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L28)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio_optimizer.rb#L25)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio_optimizer.rb#L34)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio_optimizer.rb#L51)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio_optimizer.rb#L75)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio_optimizer.rb#L114)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio_optimizer.rb#L146)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio_optimizer.rb#L175)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio_optimizer.rb#L217)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio_optimizer.rb#L285)
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`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio_optimizer.rb#L298)
244
+
245
+ ---
246
+
247
+ ## 📝 Attributes
248
+