sqa 0.0.37 → 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 (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +62 -0
  3. data/docs/api-reference/alphavantageapi.md +105 -105
  4. data/docs/api-reference/apierror.md +2 -2
  5. data/docs/api-reference/index.md +2 -2
  6. data/docs/api-reference/notimplemented.md +2 -2
  7. data/docs/api-reference/sqa.md +12 -12
  8. data/docs/api-reference/sqa_backtest.md +43 -9
  9. data/docs/api-reference/sqa_backtest_results.md +34 -34
  10. data/docs/api-reference/sqa_badparametererror.md +1 -1
  11. data/docs/api-reference/sqa_config.md +31 -31
  12. data/docs/api-reference/sqa_configurationerror.md +1 -1
  13. data/docs/api-reference/sqa_datafetcherror.md +3 -3
  14. data/docs/api-reference/sqa_dataframe.md +63 -36
  15. data/docs/api-reference/sqa_dataframe_alphavantage.md +2 -2
  16. data/docs/api-reference/sqa_dataframe_data.md +18 -18
  17. data/docs/api-reference/sqa_dataframe_yahoofinance.md +2 -2
  18. data/docs/api-reference/sqa_ensemble.md +21 -21
  19. data/docs/api-reference/sqa_fpop.md +8 -8
  20. data/docs/api-reference/sqa_geneticprogram.md +20 -20
  21. data/docs/api-reference/sqa_geneticprogram_individual.md +8 -8
  22. data/docs/api-reference/sqa_marketregime.md +10 -10
  23. data/docs/api-reference/sqa_multitimeframe.md +11 -11
  24. data/docs/api-reference/sqa_patternmatcher.md +9 -9
  25. data/docs/api-reference/sqa_pluginmanager.md +4 -4
  26. data/docs/api-reference/sqa_portfolio.md +84 -27
  27. data/docs/api-reference/sqa_portfolio_position.md +12 -12
  28. data/docs/api-reference/sqa_portfolio_trade.md +16 -16
  29. data/docs/api-reference/sqa_portfoliooptimizer.md +10 -10
  30. data/docs/api-reference/sqa_riskmanager.md +12 -12
  31. data/docs/api-reference/sqa_seasonalanalyzer.md +6 -6
  32. data/docs/api-reference/sqa_sectoranalyzer.md +9 -9
  33. data/docs/api-reference/sqa_stock.md +48 -36
  34. data/docs/api-reference/sqa_strategy.md +8 -8
  35. data/docs/api-reference/sqa_strategy_bollingerbands.md +2 -2
  36. data/docs/api-reference/sqa_strategy_common.md +3 -3
  37. data/docs/api-reference/sqa_strategy_consensus.md +12 -12
  38. data/docs/api-reference/sqa_strategy_ema.md +4 -4
  39. data/docs/api-reference/sqa_strategy_kbs.md +11 -11
  40. data/docs/api-reference/sqa_strategy_macd.md +2 -2
  41. data/docs/api-reference/sqa_strategy_mp.md +4 -4
  42. data/docs/api-reference/sqa_strategy_mr.md +4 -4
  43. data/docs/api-reference/sqa_strategy_random.md +4 -4
  44. data/docs/api-reference/sqa_strategy_rsi.md +4 -4
  45. data/docs/api-reference/sqa_strategy_sma.md +4 -4
  46. data/docs/api-reference/sqa_strategy_stochastic.md +2 -2
  47. data/docs/api-reference/sqa_strategy_volumebreakout.md +2 -2
  48. data/docs/api-reference/sqa_strategygenerator.md +19 -19
  49. data/docs/api-reference/sqa_strategygenerator_pattern.md +17 -17
  50. data/docs/api-reference/sqa_strategygenerator_patterncontext.md +21 -21
  51. data/docs/api-reference/sqa_strategygenerator_profitablepoint.md +27 -27
  52. data/docs/api-reference/sqa_stream.md +18 -18
  53. data/docs/api-reference/sqa_ticker.md +8 -8
  54. data/docs/api-reference/string.md +11 -11
  55. data/docs/file_formats.md +250 -0
  56. data/lib/sqa/backtest.rb +32 -0
  57. data/lib/sqa/data_frame.rb +25 -0
  58. data/lib/sqa/portfolio.rb +54 -0
  59. data/lib/sqa/stock.rb +11 -0
  60. data/lib/sqa/version.rb +1 -1
  61. data/mkdocs.yml +1 -0
  62. metadata +2 -2
  63. data/docs/IMPROVEMENT_PLAN.md +0 -531
@@ -1,7 +1,7 @@
1
1
  # 🔧 SQA::MarketRegime
2
2
 
3
3
  !!! abstract "Source Information"
4
- **Defined in:** `lib/sqa/market_regime.rb:17`
4
+ **Defined in:** [`lib/sqa/market_regime.rb:17`](https://github.com/madbomber/sqa/blob/main/lib/sqa/market_regime.rb#L17)
5
5
 
6
6
  ## 🏭 Class Methods
7
7
 
@@ -25,7 +25,7 @@ Detect current market regime for a stock
25
25
  Regime metadata with both symbolic and numeric values
26
26
 
27
27
  ??? info "Source Location"
28
- `lib/sqa/market_regime.rb:26`
28
+ [`lib/sqa/market_regime.rb:26`](https://github.com/madbomber/sqa/blob/main/lib/sqa/market_regime.rb#L26)
29
29
 
30
30
  ---
31
31
 
@@ -50,7 +50,7 @@ Splits historical data into regime periods
50
50
  Array of regime periods
51
51
 
52
52
  ??? info "Source Location"
53
- `lib/sqa/market_regime.rb:61`
53
+ [`lib/sqa/market_regime.rb:61`](https://github.com/madbomber/sqa/blob/main/lib/sqa/market_regime.rb#L61)
54
54
 
55
55
  ---
56
56
 
@@ -72,7 +72,7 @@ Classify regime type based on trend with numeric score
72
72
  { type: Symbol, score: Float }
73
73
 
74
74
  ??? info "Source Location"
75
- `lib/sqa/market_regime.rb:109`
75
+ [`lib/sqa/market_regime.rb:109`](https://github.com/madbomber/sqa/blob/main/lib/sqa/market_regime.rb#L109)
76
76
 
77
77
  ---
78
78
 
@@ -94,7 +94,7 @@ Classify regime type based on trend (backward compatibility)
94
94
  :bull, :bear, or :sideways
95
95
 
96
96
  ??? info "Source Location"
97
- `lib/sqa/market_regime.rb:136`
97
+ [`lib/sqa/market_regime.rb:136`](https://github.com/madbomber/sqa/blob/main/lib/sqa/market_regime.rb#L136)
98
98
 
99
99
  ---
100
100
 
@@ -116,7 +116,7 @@ Detect volatility regime with numeric score
116
116
  { type: Symbol, score: Float }
117
117
 
118
118
  ??? info "Source Location"
119
- `lib/sqa/market_regime.rb:145`
119
+ [`lib/sqa/market_regime.rb:145`](https://github.com/madbomber/sqa/blob/main/lib/sqa/market_regime.rb#L145)
120
120
 
121
121
  ---
122
122
 
@@ -138,7 +138,7 @@ Detect volatility regime (backward compatibility)
138
138
  :low, :medium, or :high
139
139
 
140
140
  ??? info "Source Location"
141
- `lib/sqa/market_regime.rb:170`
141
+ [`lib/sqa/market_regime.rb:170`](https://github.com/madbomber/sqa/blob/main/lib/sqa/market_regime.rb#L170)
142
142
 
143
143
  ---
144
144
 
@@ -160,7 +160,7 @@ Detect trend strength with numeric score
160
160
  { type: Symbol, score: Float }
161
161
 
162
162
  ??? info "Source Location"
163
- `lib/sqa/market_regime.rb:179`
163
+ [`lib/sqa/market_regime.rb:179`](https://github.com/madbomber/sqa/blob/main/lib/sqa/market_regime.rb#L179)
164
164
 
165
165
  ---
166
166
 
@@ -182,7 +182,7 @@ Detect trend strength (backward compatibility)
182
182
  :weak, :moderate, or :strong
183
183
 
184
184
  ??? info "Source Location"
185
- `lib/sqa/market_regime.rb:211`
185
+ [`lib/sqa/market_regime.rb:211`](https://github.com/madbomber/sqa/blob/main/lib/sqa/market_regime.rb#L211)
186
186
 
187
187
  ---
188
188
 
@@ -204,7 +204,7 @@ Split data by regime
204
204
  Data grouped by regime type
205
205
 
206
206
  ??? info "Source Location"
207
- `lib/sqa/market_regime.rb:220`
207
+ [`lib/sqa/market_regime.rb:220`](https://github.com/madbomber/sqa/blob/main/lib/sqa/market_regime.rb#L220)
208
208
 
209
209
  ---
210
210
 
@@ -14,7 +14,7 @@
14
14
  - Use lower timeframe for entry timing
15
15
 
16
16
  !!! abstract "Source Information"
17
- **Defined in:** `lib/sqa/multi_timeframe.rb:23`
17
+ **Defined in:** [`lib/sqa/multi_timeframe.rb:23`](https://github.com/madbomber/sqa/blob/main/lib/sqa/multi_timeframe.rb#L23)
18
18
 
19
19
  **Inherits from:** `Object`
20
20
 
@@ -28,7 +28,7 @@ Returns the value of attribute stock.
28
28
 
29
29
 
30
30
  ??? info "Source Location"
31
- `lib/sqa/multi_timeframe.rb:24`
31
+ [`lib/sqa/multi_timeframe.rb:24`](https://github.com/madbomber/sqa/blob/main/lib/sqa/multi_timeframe.rb#L24)
32
32
 
33
33
  ---
34
34
 
@@ -40,7 +40,7 @@ Returns the value of attribute timeframes.
40
40
 
41
41
 
42
42
  ??? info "Source Location"
43
- `lib/sqa/multi_timeframe.rb:24`
43
+ [`lib/sqa/multi_timeframe.rb:24`](https://github.com/madbomber/sqa/blob/main/lib/sqa/multi_timeframe.rb#L24)
44
44
 
45
45
  ---
46
46
 
@@ -62,7 +62,7 @@ Initialize multi-timeframe analyzer
62
62
  a new instance of MultiTimeframe
63
63
 
64
64
  ??? info "Source Location"
65
- `lib/sqa/multi_timeframe.rb:31`
65
+ [`lib/sqa/multi_timeframe.rb:31`](https://github.com/madbomber/sqa/blob/main/lib/sqa/multi_timeframe.rb#L31)
66
66
 
67
67
  ---
68
68
 
@@ -74,7 +74,7 @@ Convert daily data to weekly and monthly
74
74
 
75
75
 
76
76
  ??? info "Source Location"
77
- `lib/sqa/multi_timeframe.rb:42`
77
+ [`lib/sqa/multi_timeframe.rb:42`](https://github.com/madbomber/sqa/blob/main/lib/sqa/multi_timeframe.rb#L42)
78
78
 
79
79
  ---
80
80
 
@@ -96,7 +96,7 @@ Check trend alignment across timeframes
96
96
  Trend direction for each timeframe
97
97
 
98
98
  ??? info "Source Location"
99
- `lib/sqa/multi_timeframe.rb:56`
99
+ [`lib/sqa/multi_timeframe.rb:56`](https://github.com/madbomber/sqa/blob/main/lib/sqa/multi_timeframe.rb#L56)
100
100
 
101
101
  ---
102
102
 
@@ -122,7 +122,7 @@ Uses higher timeframe for trend, lower for timing.
122
122
  :buy, :sell, or :hold
123
123
 
124
124
  ??? info "Source Location"
125
- `lib/sqa/multi_timeframe.rb:102`
125
+ [`lib/sqa/multi_timeframe.rb:102`](https://github.com/madbomber/sqa/blob/main/lib/sqa/multi_timeframe.rb#L102)
126
126
 
127
127
  ---
128
128
 
@@ -146,7 +146,7 @@ Levels that appear on multiple timeframes are stronger.
146
146
  Support and resistance levels
147
147
 
148
148
  ??? info "Source Location"
149
- `lib/sqa/multi_timeframe.rb:138`
149
+ [`lib/sqa/multi_timeframe.rb:138`](https://github.com/madbomber/sqa/blob/main/lib/sqa/multi_timeframe.rb#L138)
150
150
 
151
151
  ---
152
152
 
@@ -169,7 +169,7 @@ Calculate indicators for each timeframe
169
169
  Indicator values for each timeframe
170
170
 
171
171
  ??? info "Source Location"
172
- `lib/sqa/multi_timeframe.rb:167`
172
+ [`lib/sqa/multi_timeframe.rb:167`](https://github.com/madbomber/sqa/blob/main/lib/sqa/multi_timeframe.rb#L167)
173
173
 
174
174
  ---
175
175
 
@@ -189,7 +189,7 @@ Divergence occurs when price and indicator move in opposite directions.
189
189
  Divergence information
190
190
 
191
191
  ??? info "Source Location"
192
- `lib/sqa/multi_timeframe.rb:197`
192
+ [`lib/sqa/multi_timeframe.rb:197`](https://github.com/madbomber/sqa/blob/main/lib/sqa/multi_timeframe.rb#L197)
193
193
 
194
194
  ---
195
195
 
@@ -211,7 +211,7 @@ Check if timeframes confirm each other
211
211
  Confirmation status
212
212
 
213
213
  ??? info "Source Location"
214
- `lib/sqa/multi_timeframe.rb:228`
214
+ [`lib/sqa/multi_timeframe.rb:228`](https://github.com/madbomber/sqa/blob/main/lib/sqa/multi_timeframe.rb#L228)
215
215
 
216
216
  ---
217
217
 
@@ -15,7 +15,7 @@
15
15
  - Pearson correlation
16
16
 
17
17
  !!! abstract "Source Information"
18
- **Defined in:** `lib/sqa/pattern_matcher.rb:24`
18
+ **Defined in:** [`lib/sqa/pattern_matcher.rb:24`](https://github.com/madbomber/sqa/blob/main/lib/sqa/pattern_matcher.rb#L24)
19
19
 
20
20
  **Inherits from:** `Object`
21
21
 
@@ -29,7 +29,7 @@ Returns the value of attribute stock.
29
29
 
30
30
 
31
31
  ??? info "Source Location"
32
- `lib/sqa/pattern_matcher.rb:25`
32
+ [`lib/sqa/pattern_matcher.rb:25`](https://github.com/madbomber/sqa/blob/main/lib/sqa/pattern_matcher.rb#L25)
33
33
 
34
34
  ---
35
35
 
@@ -41,7 +41,7 @@ Returns the value of attribute prices.
41
41
 
42
42
 
43
43
  ??? info "Source Location"
44
- `lib/sqa/pattern_matcher.rb:25`
44
+ [`lib/sqa/pattern_matcher.rb:25`](https://github.com/madbomber/sqa/blob/main/lib/sqa/pattern_matcher.rb#L25)
45
45
 
46
46
  ---
47
47
 
@@ -63,7 +63,7 @@ Initialize pattern matcher
63
63
  a new instance of PatternMatcher
64
64
 
65
65
  ??? info "Source Location"
66
- `lib/sqa/pattern_matcher.rb:32`
66
+ [`lib/sqa/pattern_matcher.rb:32`](https://github.com/madbomber/sqa/blob/main/lib/sqa/pattern_matcher.rb#L32)
67
67
 
68
68
  ---
69
69
 
@@ -88,7 +88,7 @@ Find similar historical patterns to current pattern
88
88
  Similar patterns with metadata
89
89
 
90
90
  ??? info "Source Location"
91
- `lib/sqa/pattern_matcher.rb:46`
91
+ [`lib/sqa/pattern_matcher.rb:46`](https://github.com/madbomber/sqa/blob/main/lib/sqa/pattern_matcher.rb#L46)
92
92
 
93
93
  ---
94
94
 
@@ -112,7 +112,7 @@ Predict future price movement based on similar patterns
112
112
  Forecast with confidence intervals
113
113
 
114
114
  ??? info "Source Location"
115
- `lib/sqa/pattern_matcher.rb:107`
115
+ [`lib/sqa/pattern_matcher.rb:107`](https://github.com/madbomber/sqa/blob/main/lib/sqa/pattern_matcher.rb#L107)
116
116
 
117
117
  ---
118
118
 
@@ -134,7 +134,7 @@ Detect chart patterns (head & shoulders, double top, etc.)
134
134
  Detected patterns
135
135
 
136
136
  ??? info "Source Location"
137
- `lib/sqa/pattern_matcher.rb:141`
137
+ [`lib/sqa/pattern_matcher.rb:141`](https://github.com/madbomber/sqa/blob/main/lib/sqa/pattern_matcher.rb#L141)
138
138
 
139
139
  ---
140
140
 
@@ -157,7 +157,7 @@ Cluster patterns by similarity
157
157
  Clusters of similar patterns
158
158
 
159
159
  ??? info "Source Location"
160
- `lib/sqa/pattern_matcher.rb:163`
160
+ [`lib/sqa/pattern_matcher.rb:163`](https://github.com/madbomber/sqa/blob/main/lib/sqa/pattern_matcher.rb#L163)
161
161
 
162
162
  ---
163
163
 
@@ -179,7 +179,7 @@ Calculate pattern strength/quality
179
179
  Pattern quality metrics
180
180
 
181
181
  ??? info "Source Location"
182
- `lib/sqa/pattern_matcher.rb:214`
182
+ [`lib/sqa/pattern_matcher.rb:214`](https://github.com/madbomber/sqa/blob/main/lib/sqa/pattern_matcher.rb#L214)
183
183
 
184
184
  ---
185
185
 
@@ -1,7 +1,7 @@
1
1
  # 📦 SQA::PluginManager
2
2
 
3
3
  !!! abstract "Source Information"
4
- **Defined in:** `lib/sqa/plugin_manager.rb:7`
4
+ **Defined in:** [`lib/sqa/plugin_manager.rb:7`](https://github.com/madbomber/sqa/blob/main/lib/sqa/plugin_manager.rb#L7)
5
5
 
6
6
  **Inherits from:** `Object`
7
7
 
@@ -15,7 +15,7 @@ Returns the value of attribute registered_properties.
15
15
 
16
16
 
17
17
  ??? info "Source Location"
18
- `lib/sqa/plugin_manager.rb:11`
18
+ [`lib/sqa/plugin_manager.rb:11`](https://github.com/madbomber/sqa/blob/main/lib/sqa/plugin_manager.rb#L11)
19
19
 
20
20
  ---
21
21
 
@@ -31,7 +31,7 @@ Sets the attribute registered_properties
31
31
 
32
32
 
33
33
  ??? info "Source Location"
34
- `lib/sqa/plugin_manager.rb:11`
34
+ [`lib/sqa/plugin_manager.rb:11`](https://github.com/madbomber/sqa/blob/main/lib/sqa/plugin_manager.rb#L11)
35
35
 
36
36
  ---
37
37
 
@@ -43,7 +43,7 @@ name (Symbol)
43
43
 
44
44
 
45
45
  ??? info "Source Location"
46
- `lib/sqa/plugin_manager.rb:15`
46
+ [`lib/sqa/plugin_manager.rb:15`](https://github.com/madbomber/sqa/blob/main/lib/sqa/plugin_manager.rb#L15)
47
47
 
48
48
  ---
49
49
 
@@ -1,7 +1,7 @@
1
1
  # 📦 SQA::Portfolio
2
2
 
3
3
  !!! abstract "Source Information"
4
- **Defined in:** `lib/sqa/portfolio.rb:7`
4
+ **Defined in:** [`lib/sqa/portfolio.rb:7`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L7)
5
5
 
6
6
  **Inherits from:** `Object`
7
7
 
@@ -19,7 +19,7 @@ Load portfolio from CSV file
19
19
 
20
20
 
21
21
  ??? info "Source Location"
22
- `lib/sqa/portfolio.rb:236`
22
+ [`lib/sqa/portfolio.rb:236`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L236)
23
23
 
24
24
  ---
25
25
 
@@ -33,7 +33,7 @@ Returns the value of attribute positions.
33
33
 
34
34
 
35
35
  ??? info "Source Location"
36
- `lib/sqa/portfolio.rb:8`
36
+ [`lib/sqa/portfolio.rb:8`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L8)
37
37
 
38
38
  ---
39
39
 
@@ -49,7 +49,7 @@ Sets the attribute positions
49
49
 
50
50
 
51
51
  ??? info "Source Location"
52
- `lib/sqa/portfolio.rb:8`
52
+ [`lib/sqa/portfolio.rb:8`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L8)
53
53
 
54
54
  ---
55
55
 
@@ -61,7 +61,7 @@ Returns the value of attribute trades.
61
61
 
62
62
 
63
63
  ??? info "Source Location"
64
- `lib/sqa/portfolio.rb:8`
64
+ [`lib/sqa/portfolio.rb:8`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L8)
65
65
 
66
66
  ---
67
67
 
@@ -77,7 +77,7 @@ Sets the attribute trades
77
77
 
78
78
 
79
79
  ??? info "Source Location"
80
- `lib/sqa/portfolio.rb:8`
80
+ [`lib/sqa/portfolio.rb:8`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L8)
81
81
 
82
82
  ---
83
83
 
@@ -89,7 +89,7 @@ Returns the value of attribute cash.
89
89
 
90
90
 
91
91
  ??? info "Source Location"
92
- `lib/sqa/portfolio.rb:8`
92
+ [`lib/sqa/portfolio.rb:8`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L8)
93
93
 
94
94
  ---
95
95
 
@@ -105,7 +105,7 @@ Sets the attribute cash
105
105
 
106
106
 
107
107
  ??? info "Source Location"
108
- `lib/sqa/portfolio.rb:8`
108
+ [`lib/sqa/portfolio.rb:8`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L8)
109
109
 
110
110
  ---
111
111
 
@@ -117,7 +117,7 @@ Returns the value of attribute initial_cash.
117
117
 
118
118
 
119
119
  ??? info "Source Location"
120
- `lib/sqa/portfolio.rb:8`
120
+ [`lib/sqa/portfolio.rb:8`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L8)
121
121
 
122
122
  ---
123
123
 
@@ -133,7 +133,7 @@ Sets the attribute initial_cash
133
133
 
134
134
 
135
135
  ??? info "Source Location"
136
- `lib/sqa/portfolio.rb:8`
136
+ [`lib/sqa/portfolio.rb:8`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L8)
137
137
 
138
138
  ---
139
139
 
@@ -145,7 +145,7 @@ Returns the value of attribute commission.
145
145
 
146
146
 
147
147
  ??? info "Source Location"
148
- `lib/sqa/portfolio.rb:8`
148
+ [`lib/sqa/portfolio.rb:8`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L8)
149
149
 
150
150
  ---
151
151
 
@@ -161,7 +161,7 @@ Sets the attribute commission
161
161
 
162
162
 
163
163
  ??? info "Source Location"
164
- `lib/sqa/portfolio.rb:8`
164
+ [`lib/sqa/portfolio.rb:8`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L8)
165
165
 
166
166
  ---
167
167
 
@@ -177,7 +177,7 @@ Sets the attribute commission
177
177
  a new instance of Portfolio
178
178
 
179
179
  ??? info "Source Location"
180
- `lib/sqa/portfolio.rb:41`
180
+ [`lib/sqa/portfolio.rb:41`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L41)
181
181
 
182
182
  ---
183
183
 
@@ -200,9 +200,23 @@ Buy shares of a stock
200
200
 
201
201
 
202
202
  The executed trade
203
-
203
+ !!! example "Usage Examples"
204
+
205
+ ```ruby
206
+ portfolio = SQA::Portfolio.new(initial_cash: 10_000, commission: 1.0)
207
+ trade = portfolio.buy('AAPL', shares: 10, price: 150.0)
208
+ trade.action # => :buy
209
+ trade.total # => 1500.0
210
+ portfolio.cash # => 8499.0 (10_000 - 1500 - 1.0 commission)
211
+ ```
212
+
213
+ ```ruby
214
+ portfolio.buy('AAPL', shares: 10, price: 150.0)
215
+ portfolio.buy('MSFT', shares: 5, price: 300.0)
216
+ portfolio.positions.size # => 2
217
+ ```
204
218
  ??? info "Source Location"
205
- `lib/sqa/portfolio.rb:55`
219
+ [`lib/sqa/portfolio.rb:55`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L55)
206
220
 
207
221
  ---
208
222
 
@@ -225,9 +239,23 @@ Sell shares of a stock
225
239
 
226
240
 
227
241
  The executed trade
228
-
242
+ !!! example "Usage Examples"
243
+
244
+ ```ruby
245
+ portfolio = SQA::Portfolio.new(initial_cash: 10_000, commission: 1.0)
246
+ portfolio.buy('AAPL', shares: 10, price: 150.0)
247
+ trade = portfolio.sell('AAPL', shares: 10, price: 160.0)
248
+ trade.total # => 1600.0
249
+ portfolio.cash # => 8498.0 + 1599.0 = 10097.0 (after commissions)
250
+ ```
251
+
252
+ ```ruby
253
+ portfolio.buy('AAPL', shares: 100, price: 150.0)
254
+ portfolio.sell('AAPL', shares: 50, price: 160.0) # Sell half
255
+ portfolio.position('AAPL').shares # => 50
256
+ ```
229
257
  ??? info "Source Location"
230
- `lib/sqa/portfolio.rb:98`
258
+ [`lib/sqa/portfolio.rb:98`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L98)
231
259
 
232
260
  ---
233
261
 
@@ -249,7 +277,7 @@ Get current position for a ticker
249
277
  The position or nil if not found
250
278
 
251
279
  ??? info "Source Location"
252
- `lib/sqa/portfolio.rb:135`
280
+ [`lib/sqa/portfolio.rb:135`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L135)
253
281
 
254
282
  ---
255
283
 
@@ -267,7 +295,7 @@ Get all current positions
267
295
  Hash of ticker => Position
268
296
 
269
297
  ??? info "Source Location"
270
- `lib/sqa/portfolio.rb:141`
298
+ [`lib/sqa/portfolio.rb:141`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L141)
271
299
 
272
300
  ---
273
301
 
@@ -287,9 +315,22 @@ Calculate total portfolio value
287
315
 
288
316
 
289
317
  Total portfolio value (cash + positions)
318
+ !!! example "Usage Examples"
290
319
 
320
+ ```ruby
321
+ portfolio = SQA::Portfolio.new(initial_cash: 10_000)
322
+ portfolio.buy('AAPL', shares: 10, price: 150.0)
323
+ portfolio.buy('MSFT', shares: 5, price: 300.0)
324
+
325
+ current_prices = { 'AAPL' => 160.0, 'MSFT' => 310.0 }
326
+ portfolio.value(current_prices) # => 10_000 - 1500 - 1500 + 1600 + 1550 = 10_150
327
+ ```
328
+
329
+ ```ruby
330
+ portfolio.value # Uses purchase prices if no current prices provided
331
+ ```
291
332
  ??? info "Source Location"
292
- `lib/sqa/portfolio.rb:148`
333
+ [`lib/sqa/portfolio.rb:148`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L148)
293
334
 
294
335
  ---
295
336
 
@@ -311,7 +352,7 @@ Calculate total profit/loss across all positions
311
352
  Total P&L
312
353
 
313
354
  ??? info "Source Location"
314
- `lib/sqa/portfolio.rb:160`
355
+ [`lib/sqa/portfolio.rb:160`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L160)
315
356
 
316
357
  ---
317
358
 
@@ -333,7 +374,7 @@ Calculate profit/loss percentage
333
374
  P&L percentage
334
375
 
335
376
  ??? info "Source Location"
336
- `lib/sqa/portfolio.rb:167`
377
+ [`lib/sqa/portfolio.rb:167`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L167)
337
378
 
338
379
  ---
339
380
 
@@ -355,7 +396,7 @@ Calculate total return (including dividends if tracked)
355
396
  Total return as decimal (e.g., 0.15 for 15%)
356
397
 
357
398
  ??? info "Source Location"
358
- `lib/sqa/portfolio.rb:175`
399
+ [`lib/sqa/portfolio.rb:175`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L175)
359
400
 
360
401
  ---
361
402
 
@@ -373,7 +414,7 @@ Get trade history
373
414
  Array of all trades
374
415
 
375
416
  ??? info "Source Location"
376
- `lib/sqa/portfolio.rb:182`
417
+ [`lib/sqa/portfolio.rb:182`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L182)
377
418
 
378
419
  ---
379
420
 
@@ -393,9 +434,25 @@ Get summary statistics
393
434
 
394
435
 
395
436
  Summary statistics
437
+ !!! example "Usage Examples"
396
438
 
439
+ ```ruby
440
+ portfolio = SQA::Portfolio.new(initial_cash: 10_000, commission: 1.0)
441
+ portfolio.buy('AAPL', shares: 10, price: 150.0)
442
+ portfolio.sell('AAPL', shares: 5, price: 160.0)
443
+
444
+ summary = portfolio.summary({ 'AAPL' => 165.0 })
445
+ summary[:initial_cash] # => 10_000.0
446
+ summary[:current_cash] # => 8798.0
447
+ summary[:positions_count] # => 1
448
+ summary[:total_value] # => 9623.0
449
+ summary[:profit_loss_percent] # => -3.77%
450
+ summary[:total_trades] # => 2
451
+ summary[:buy_trades] # => 1
452
+ summary[:sell_trades] # => 1
453
+ ```
397
454
  ??? info "Source Location"
398
- `lib/sqa/portfolio.rb:189`
455
+ [`lib/sqa/portfolio.rb:189`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L189)
399
456
 
400
457
  ---
401
458
 
@@ -411,7 +468,7 @@ Save portfolio to CSV file
411
468
 
412
469
 
413
470
  ??? info "Source Location"
414
- `lib/sqa/portfolio.rb:206`
471
+ [`lib/sqa/portfolio.rb:206`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L206)
415
472
 
416
473
  ---
417
474
 
@@ -427,7 +484,7 @@ Save trade history to CSV file
427
484
 
428
485
 
429
486
  ??? info "Source Location"
430
- `lib/sqa/portfolio.rb:217`
487
+ [`lib/sqa/portfolio.rb:217`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L217)
431
488
 
432
489
  ---
433
490
 
@@ -4,7 +4,7 @@
4
4
  Represents a single position in the portfolio
5
5
 
6
6
  !!! abstract "Source Information"
7
- **Defined in:** `lib/sqa/portfolio.rb:11`
7
+ **Defined in:** [`lib/sqa/portfolio.rb:11`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L11)
8
8
 
9
9
  **Inherits from:** `Struct`
10
10
 
@@ -28,7 +28,7 @@ Sets the attribute ticker
28
28
  the newly set value
29
29
 
30
30
  ??? info "Source Location"
31
- `lib/sqa/portfolio.rb:11`
31
+ [`lib/sqa/portfolio.rb:11`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L11)
32
32
 
33
33
  ---
34
34
 
@@ -46,7 +46,7 @@ Returns the value of attribute ticker
46
46
  the current value of ticker
47
47
 
48
48
  ??? info "Source Location"
49
- `lib/sqa/portfolio.rb:11`
49
+ [`lib/sqa/portfolio.rb:11`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L11)
50
50
 
51
51
  ---
52
52
 
@@ -68,7 +68,7 @@ Sets the attribute shares
68
68
  the newly set value
69
69
 
70
70
  ??? info "Source Location"
71
- `lib/sqa/portfolio.rb:11`
71
+ [`lib/sqa/portfolio.rb:11`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L11)
72
72
 
73
73
  ---
74
74
 
@@ -86,7 +86,7 @@ Returns the value of attribute shares
86
86
  the current value of shares
87
87
 
88
88
  ??? info "Source Location"
89
- `lib/sqa/portfolio.rb:11`
89
+ [`lib/sqa/portfolio.rb:11`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L11)
90
90
 
91
91
  ---
92
92
 
@@ -108,7 +108,7 @@ Sets the attribute avg_cost
108
108
  the newly set value
109
109
 
110
110
  ??? info "Source Location"
111
- `lib/sqa/portfolio.rb:11`
111
+ [`lib/sqa/portfolio.rb:11`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L11)
112
112
 
113
113
  ---
114
114
 
@@ -126,7 +126,7 @@ Returns the value of attribute avg_cost
126
126
  the current value of avg_cost
127
127
 
128
128
  ??? info "Source Location"
129
- `lib/sqa/portfolio.rb:11`
129
+ [`lib/sqa/portfolio.rb:11`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L11)
130
130
 
131
131
  ---
132
132
 
@@ -148,7 +148,7 @@ Sets the attribute total_cost
148
148
  the newly set value
149
149
 
150
150
  ??? info "Source Location"
151
- `lib/sqa/portfolio.rb:11`
151
+ [`lib/sqa/portfolio.rb:11`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L11)
152
152
 
153
153
  ---
154
154
 
@@ -166,7 +166,7 @@ Returns the value of attribute total_cost
166
166
  the current value of total_cost
167
167
 
168
168
  ??? info "Source Location"
169
- `lib/sqa/portfolio.rb:11`
169
+ [`lib/sqa/portfolio.rb:11`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L11)
170
170
 
171
171
  ---
172
172
 
@@ -176,7 +176,7 @@ Returns the value of attribute total_cost
176
176
 
177
177
 
178
178
  ??? info "Source Location"
179
- `lib/sqa/portfolio.rb:12`
179
+ [`lib/sqa/portfolio.rb:12`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L12)
180
180
 
181
181
  ---
182
182
 
@@ -186,7 +186,7 @@ Returns the value of attribute total_cost
186
186
 
187
187
 
188
188
  ??? info "Source Location"
189
- `lib/sqa/portfolio.rb:16`
189
+ [`lib/sqa/portfolio.rb:16`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L16)
190
190
 
191
191
  ---
192
192
 
@@ -196,7 +196,7 @@ Returns the value of attribute total_cost
196
196
 
197
197
 
198
198
  ??? info "Source Location"
199
- `lib/sqa/portfolio.rb:20`
199
+ [`lib/sqa/portfolio.rb:20`](https://github.com/madbomber/sqa/blob/main/lib/sqa/portfolio.rb#L20)
200
200
 
201
201
  ---
202
202