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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +92 -1
- data/README.md +4 -0
- data/Rakefile +52 -10
- data/docs/IMPROVEMENT_PLAN.md +531 -0
- data/docs/advanced/index.md +1 -13
- 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/strategy-flow.svg +78 -0
- data/docs/assets/images/system-architecture.svg +150 -0
- data/docs/concepts/index.md +292 -19
- data/docs/getting-started/index.md +1 -14
- data/docs/index.md +26 -23
- data/docs/llms.txt +109 -0
- data/docs/strategies/kbs.md +15 -14
- 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/data.rb +13 -1
- data/lib/sqa/data_frame.rb +168 -26
- data/lib/sqa/errors.rb +79 -17
- 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 +169 -15
- data/lib/sqa/strategy.rb +62 -4
- data/lib/sqa/ticker.rb +106 -48
- data/lib/sqa/version.rb +1 -1
- data/lib/sqa.rb +4 -4
- data/mkdocs.yml +68 -81
- metadata +89 -21
- data/docs/README.md +0 -43
- data/examples/sinatra_app/Gemfile +0 -42
- data/examples/sinatra_app/Gemfile.lock +0 -268
- data/examples/sinatra_app/QUICKSTART.md +0 -169
- data/examples/sinatra_app/README.md +0 -471
- data/examples/sinatra_app/RUNNING_WITHOUT_TALIB.md +0 -90
- data/examples/sinatra_app/TROUBLESHOOTING.md +0 -95
- data/examples/sinatra_app/app.rb +0 -404
- data/examples/sinatra_app/config.ru +0 -5
- data/examples/sinatra_app/public/css/style.css +0 -723
- data/examples/sinatra_app/public/debug_macd.html +0 -82
- data/examples/sinatra_app/public/js/app.js +0 -107
- data/examples/sinatra_app/start.sh +0 -53
- 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 -831
- 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,31 @@
|
|
|
1
|
+
# 📦 ApiError
|
|
2
|
+
|
|
3
|
+
!!! note "Description"
|
|
4
|
+
Raised when an external API returns an error response.
|
|
5
|
+
Automatically logs the error using debug_me before raising.
|
|
6
|
+
|
|
7
|
+
!!! abstract "Source Information"
|
|
8
|
+
**Defined in:** `lib/sqa/errors.rb:67`
|
|
9
|
+
|
|
10
|
+
**Inherits from:** `RuntimeError`
|
|
11
|
+
|
|
12
|
+
## 🏭 Class Methods
|
|
13
|
+
|
|
14
|
+
### `.raise(why)`
|
|
15
|
+
|
|
16
|
+
Raises an ApiError with debug logging.
|
|
17
|
+
|
|
18
|
+
!!! info "Parameters"
|
|
19
|
+
|
|
20
|
+
| Name | Type | Description |
|
|
21
|
+
|------|------|-------------|
|
|
22
|
+
| `why` | `String` | The error message from the API |
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
??? info "Source Location"
|
|
26
|
+
`lib/sqa/errors.rb:72`
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 📝 Attributes
|
|
31
|
+
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# 📚 API Reference
|
|
2
|
+
|
|
3
|
+
Complete API documentation for all SQA classes and modules.
|
|
4
|
+
|
|
5
|
+
!!! tip "Auto-Generated Documentation"
|
|
6
|
+
This documentation is automatically generated from YARD comments in the source code.
|
|
7
|
+
Last updated: 2025-11-24 14:46:25
|
|
8
|
+
|
|
9
|
+
## 🎯 SQA
|
|
10
|
+
|
|
11
|
+
### [📦 **Backtest**](sqa_backtest.md)
|
|
12
|
+
|
|
13
|
+
### [📦 **BadParameterError**](sqa_badparametererror.md)
|
|
14
|
+
|
|
15
|
+
!!! abstract ""
|
|
16
|
+
Raised when a method parameter is invalid.
|
|
17
|
+
|
|
18
|
+
### [📦 **Config**](sqa_config.md)
|
|
19
|
+
|
|
20
|
+
!!! abstract ""
|
|
21
|
+
Configuration class for SQA settings.
|
|
22
|
+
|
|
23
|
+
### [📦 **ConfigurationError**](sqa_configurationerror.md)
|
|
24
|
+
|
|
25
|
+
!!! abstract ""
|
|
26
|
+
Raised when SQA configuration is invalid or missing.
|
|
27
|
+
|
|
28
|
+
### [📦 **DataFetchError**](sqa_datafetcherror.md)
|
|
29
|
+
|
|
30
|
+
!!! abstract ""
|
|
31
|
+
Raised when unable to fetch data from a data source (API, file, etc.).
|
|
32
|
+
|
|
33
|
+
### [📦 **DataFrame**](sqa_dataframe.md)
|
|
34
|
+
|
|
35
|
+
!!! abstract ""
|
|
36
|
+
The website financial.yahoo.com no longer supports an API.
|
|
37
|
+
|
|
38
|
+
### [📦 **Ensemble**](sqa_ensemble.md)
|
|
39
|
+
|
|
40
|
+
!!! abstract ""
|
|
41
|
+
Ensemble - Combine multiple trading strategies
|
|
42
|
+
|
|
43
|
+
### [🔧 **FPOP**](sqa_fpop.md)
|
|
44
|
+
|
|
45
|
+
### [📦 **GeneticProgram**](sqa_geneticprogram.md)
|
|
46
|
+
|
|
47
|
+
### [🔧 **MarketRegime**](sqa_marketregime.md)
|
|
48
|
+
|
|
49
|
+
### [📦 **MultiTimeframe**](sqa_multitimeframe.md)
|
|
50
|
+
|
|
51
|
+
!!! abstract ""
|
|
52
|
+
MultiTimeframe - Analyze patterns across multiple timeframes
|
|
53
|
+
|
|
54
|
+
### [📦 **PatternMatcher**](sqa_patternmatcher.md)
|
|
55
|
+
|
|
56
|
+
!!! abstract ""
|
|
57
|
+
PatternMatcher - Find similar historical patterns
|
|
58
|
+
|
|
59
|
+
### [📦 **PluginManager**](sqa_pluginmanager.md)
|
|
60
|
+
|
|
61
|
+
### [📦 **Portfolio**](sqa_portfolio.md)
|
|
62
|
+
|
|
63
|
+
### [📦 **PortfolioOptimizer**](sqa_portfoliooptimizer.md)
|
|
64
|
+
|
|
65
|
+
!!! abstract ""
|
|
66
|
+
PortfolioOptimizer - Multi-objective portfolio optimization
|
|
67
|
+
|
|
68
|
+
### [📦 **RiskManager**](sqa_riskmanager.md)
|
|
69
|
+
|
|
70
|
+
!!! abstract ""
|
|
71
|
+
RiskManager - Comprehensive risk management and position sizing
|
|
72
|
+
|
|
73
|
+
### [🔧 **SeasonalAnalyzer**](sqa_seasonalanalyzer.md)
|
|
74
|
+
|
|
75
|
+
### [📦 **SectorAnalyzer**](sqa_sectoranalyzer.md)
|
|
76
|
+
|
|
77
|
+
### [📦 **Stock**](sqa_stock.md)
|
|
78
|
+
|
|
79
|
+
!!! abstract ""
|
|
80
|
+
Represents a stock with price history, metadata, and technical analysis capabilities.
|
|
81
|
+
|
|
82
|
+
### [📦 **Strategy**](sqa_strategy.md)
|
|
83
|
+
|
|
84
|
+
!!! abstract ""
|
|
85
|
+
This module needs to be extend'ed within
|
|
86
|
+
|
|
87
|
+
### [📦 **StrategyGenerator**](sqa_strategygenerator.md)
|
|
88
|
+
|
|
89
|
+
### [📦 **Stream**](sqa_stream.md)
|
|
90
|
+
|
|
91
|
+
### [📦 **Ticker**](sqa_ticker.md)
|
|
92
|
+
|
|
93
|
+
!!! abstract ""
|
|
94
|
+
sqa/lib/sqa/ticker.rb
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
## 📦 SQA::GeneticProgram
|
|
98
|
+
|
|
99
|
+
### [📦 **Individual**](sqa_geneticprogram_individual.md)
|
|
100
|
+
|
|
101
|
+
!!! abstract ""
|
|
102
|
+
Represents an individual trading strategy with specific parameters
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
## 📦 Top Level
|
|
106
|
+
|
|
107
|
+
### [📦 **AlphaVantageAPI**](alphavantageapi.md)
|
|
108
|
+
|
|
109
|
+
### [📦 **ApiError**](apierror.md)
|
|
110
|
+
|
|
111
|
+
!!! abstract ""
|
|
112
|
+
Raised when an external API returns an error response.
|
|
113
|
+
|
|
114
|
+
### [📦 **NotImplemented**](notimplemented.md)
|
|
115
|
+
|
|
116
|
+
!!! abstract ""
|
|
117
|
+
Raised when a feature is not yet implemented.
|
|
118
|
+
|
|
119
|
+
### [🔧 **SQA**](sqa.md)
|
|
120
|
+
|
|
121
|
+
!!! abstract ""
|
|
122
|
+
Knowledge-Based Strategy using RETE Forward Chaining
|
|
123
|
+
|
|
124
|
+
### [📦 **String**](string.md)
|
|
125
|
+
|
|
126
|
+
!!! abstract ""
|
|
127
|
+
File: string.rb
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
## 📦 SQA::Backtest
|
|
131
|
+
|
|
132
|
+
### [📦 **Results**](sqa_backtest_results.md)
|
|
133
|
+
|
|
134
|
+
!!! abstract ""
|
|
135
|
+
Represents the results of a backtest
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
## 📦 SQA::Portfolio
|
|
139
|
+
|
|
140
|
+
### [📦 **Position**](sqa_portfolio_position.md)
|
|
141
|
+
|
|
142
|
+
!!! abstract ""
|
|
143
|
+
Represents a single position in the portfolio
|
|
144
|
+
|
|
145
|
+
### [📦 **Trade**](sqa_portfolio_trade.md)
|
|
146
|
+
|
|
147
|
+
!!! abstract ""
|
|
148
|
+
Represents a single trade
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
## 📊 SQA::Strategy
|
|
152
|
+
|
|
153
|
+
### [📦 **BollingerBands**](sqa_strategy_bollingerbands.md)
|
|
154
|
+
|
|
155
|
+
!!! abstract ""
|
|
156
|
+
Bollinger Bands trading strategy
|
|
157
|
+
|
|
158
|
+
### [🔧 **Common**](sqa_strategy_common.md)
|
|
159
|
+
|
|
160
|
+
### [📦 **Consensus**](sqa_strategy_consensus.md)
|
|
161
|
+
|
|
162
|
+
### [📦 **EMA**](sqa_strategy_ema.md)
|
|
163
|
+
|
|
164
|
+
### [📦 **KBS**](sqa_strategy_kbs.md)
|
|
165
|
+
|
|
166
|
+
### [📦 **MACD**](sqa_strategy_macd.md)
|
|
167
|
+
|
|
168
|
+
!!! abstract ""
|
|
169
|
+
MACD (Moving Average Convergence Divergence) crossover strategy
|
|
170
|
+
|
|
171
|
+
### [📦 **MP**](sqa_strategy_mp.md)
|
|
172
|
+
|
|
173
|
+
### [📦 **MR**](sqa_strategy_mr.md)
|
|
174
|
+
|
|
175
|
+
### [📦 **RSI**](sqa_strategy_rsi.md)
|
|
176
|
+
|
|
177
|
+
### [📦 **Random**](sqa_strategy_random.md)
|
|
178
|
+
|
|
179
|
+
### [📦 **SMA**](sqa_strategy_sma.md)
|
|
180
|
+
|
|
181
|
+
### [📦 **Stochastic**](sqa_strategy_stochastic.md)
|
|
182
|
+
|
|
183
|
+
!!! abstract ""
|
|
184
|
+
Stochastic Oscillator crossover strategy
|
|
185
|
+
|
|
186
|
+
### [📦 **VolumeBreakout**](sqa_strategy_volumebreakout.md)
|
|
187
|
+
|
|
188
|
+
!!! abstract ""
|
|
189
|
+
Volume Breakout strategy
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
## 📦 SQA::DataFrame
|
|
193
|
+
|
|
194
|
+
### [📦 **AlphaVantage**](sqa_dataframe_alphavantage.md)
|
|
195
|
+
|
|
196
|
+
### [📦 **Data**](sqa_dataframe_data.md)
|
|
197
|
+
|
|
198
|
+
!!! abstract ""
|
|
199
|
+
Data class to store stock metadata
|
|
200
|
+
|
|
201
|
+
### [📦 **YahooFinance**](sqa_dataframe_yahoofinance.md)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
## 📊 SQA::StrategyGenerator
|
|
205
|
+
|
|
206
|
+
### [📦 **Pattern**](sqa_strategygenerator_pattern.md)
|
|
207
|
+
|
|
208
|
+
!!! abstract ""
|
|
209
|
+
Represents a discovered indicator pattern
|
|
210
|
+
|
|
211
|
+
### [📦 **PatternContext**](sqa_strategygenerator_patterncontext.md)
|
|
212
|
+
|
|
213
|
+
!!! abstract ""
|
|
214
|
+
Pattern Context - metadata about when/where pattern is valid
|
|
215
|
+
|
|
216
|
+
### [📦 **ProfitablePoint**](sqa_strategygenerator_profitablepoint.md)
|
|
217
|
+
|
|
218
|
+
!!! abstract ""
|
|
219
|
+
Represents a profitable trade opportunity discovered in historical data
|
|
220
|
+
|
|
221
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# 📦 NotImplemented
|
|
2
|
+
|
|
3
|
+
!!! note "Description"
|
|
4
|
+
Raised when a feature is not yet implemented.
|
|
5
|
+
Automatically logs using debug_me before raising.
|
|
6
|
+
|
|
7
|
+
!!! abstract "Source Information"
|
|
8
|
+
**Defined in:** `lib/sqa/errors.rb:84`
|
|
9
|
+
|
|
10
|
+
**Inherits from:** `RuntimeError`
|
|
11
|
+
|
|
12
|
+
## 🏭 Class Methods
|
|
13
|
+
|
|
14
|
+
### `.raise()`
|
|
15
|
+
|
|
16
|
+
Raises a NotImplemented error with debug logging.
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
??? info "Source Location"
|
|
22
|
+
`lib/sqa/errors.rb:88`
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 📝 Attributes
|
|
27
|
+
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# 🔧 SQA
|
|
2
|
+
|
|
3
|
+
!!! note "Description"
|
|
4
|
+
Knowledge-Based Strategy using RETE Forward Chaining
|
|
5
|
+
|
|
6
|
+
This strategy uses a rule-based system with the RETE algorithm for
|
|
7
|
+
forward-chaining inference. It allows defining complex trading rules
|
|
8
|
+
that react to market conditions.
|
|
9
|
+
|
|
10
|
+
The strategy asserts facts about market conditions (RSI, trends, volume, etc.)
|
|
11
|
+
and fires rules when patterns are matched.
|
|
12
|
+
|
|
13
|
+
DSL Keywords:
|
|
14
|
+
- on : Assert a condition (fact must exist)
|
|
15
|
+
- without : Negated condition (fact must NOT exist)
|
|
16
|
+
- perform : Define action to execute when rule fires
|
|
17
|
+
- execute : Alias for perform
|
|
18
|
+
- action : Alias for perform
|
|
19
|
+
|
|
20
|
+
Example:
|
|
21
|
+
strategy = SQA::Strategy::KBS.new
|
|
22
|
+
|
|
23
|
+
# Capture kb for use in perform blocks
|
|
24
|
+
kb = strategy.kb
|
|
25
|
+
|
|
26
|
+
# Define custom rules using the DSL
|
|
27
|
+
strategy.add_rule :buy_oversold_uptrend do
|
|
28
|
+
on :rsi, { level: :oversold }
|
|
29
|
+
on :trend, { direction: :up }
|
|
30
|
+
without :position
|
|
31
|
+
|
|
32
|
+
perform do
|
|
33
|
+
kb.assert(:signal, { action: :buy, confidence: :high })
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Execute strategy
|
|
38
|
+
signal = strategy.trade(vector)
|
|
39
|
+
|
|
40
|
+
Note: Use 'kb.assert' (not just 'assert') in perform blocks to access the knowledge base.
|
|
41
|
+
|
|
42
|
+
!!! abstract "Source Information"
|
|
43
|
+
**Defined in:** `lib/sqa/gp.rb:34`
|
|
44
|
+
|
|
45
|
+
## 🏭 Class Methods
|
|
46
|
+
|
|
47
|
+
### `.config=(value)`
|
|
48
|
+
|
|
49
|
+
Sets the attribute config
|
|
50
|
+
|
|
51
|
+
!!! info "Parameters"
|
|
52
|
+
|
|
53
|
+
| Name | Type | Description |
|
|
54
|
+
|------|------|-------------|
|
|
55
|
+
| `value` | `Any` | the value to set the attribute config to. |
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
??? info "Source Location"
|
|
59
|
+
`lib/sqa/init.rb:22`
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
### `.init(argv = ARGV)`
|
|
64
|
+
|
|
65
|
+
Initializes the SQA library.
|
|
66
|
+
Should be called once at application startup.
|
|
67
|
+
|
|
68
|
+
!!! info "Parameters"
|
|
69
|
+
|
|
70
|
+
| Name | Type | Description |
|
|
71
|
+
|------|------|-------------|
|
|
72
|
+
| `argv` | `Array<String>, String` | Command line arguments (default: ARGV) |
|
|
73
|
+
!!! success "Returns"
|
|
74
|
+
|
|
75
|
+
**Type:** `SQA::Config`
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
The configuration instance
|
|
80
|
+
!!! example "Usage Examples"
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
SQA.init
|
|
84
|
+
SQA.init("--debug --verbose")
|
|
85
|
+
```
|
|
86
|
+
??? info "Source Location"
|
|
87
|
+
`lib/sqa/init.rb:34`
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
### `.av_api_key()`
|
|
92
|
+
|
|
93
|
+
Returns the Alpha Vantage API key.
|
|
94
|
+
Reads from AV_API_KEY or ALPHAVANTAGE_API_KEY environment variables.
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
!!! success "Returns"
|
|
98
|
+
|
|
99
|
+
**Type:** `String`
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
The API key
|
|
104
|
+
|
|
105
|
+
??? info "Source Location"
|
|
106
|
+
`lib/sqa/init.rb:61`
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
### `.av_api_key=(key)`
|
|
111
|
+
|
|
112
|
+
Sets the Alpha Vantage API key.
|
|
113
|
+
|
|
114
|
+
!!! info "Parameters"
|
|
115
|
+
|
|
116
|
+
| Name | Type | Description |
|
|
117
|
+
|------|------|-------------|
|
|
118
|
+
| `key` | `String` | The API key to set |
|
|
119
|
+
!!! success "Returns"
|
|
120
|
+
|
|
121
|
+
**Type:** `String`
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
The key that was set
|
|
126
|
+
|
|
127
|
+
??? info "Source Location"
|
|
128
|
+
`lib/sqa/init.rb:70`
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
### `.av()`
|
|
133
|
+
|
|
134
|
+
Legacy accessor for backward compatibility with SQA.av.key usage.
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
!!! success "Returns"
|
|
138
|
+
|
|
139
|
+
**Type:** `SQA`
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
Self, to allow SQA.av.key calls
|
|
144
|
+
|
|
145
|
+
??? info "Source Location"
|
|
146
|
+
`lib/sqa/init.rb:77`
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
### `.key()`
|
|
151
|
+
|
|
152
|
+
Returns the API key for compatibility with old SQA.av.key usage.
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
!!! success "Returns"
|
|
156
|
+
|
|
157
|
+
**Type:** `String`
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
The API key
|
|
162
|
+
|
|
163
|
+
??? info "Source Location"
|
|
164
|
+
`lib/sqa/init.rb:85`
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
### `.debug?()`
|
|
169
|
+
|
|
170
|
+
Returns whether debug mode is enabled.
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
!!! success "Returns"
|
|
174
|
+
|
|
175
|
+
**Type:** `Boolean`
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
true if debug mode is on
|
|
180
|
+
|
|
181
|
+
??? info "Source Location"
|
|
182
|
+
`lib/sqa/init.rb:91`
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
### `.verbose?()`
|
|
187
|
+
|
|
188
|
+
Returns whether verbose mode is enabled.
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
!!! success "Returns"
|
|
192
|
+
|
|
193
|
+
**Type:** `Boolean`
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
true if verbose mode is on
|
|
198
|
+
|
|
199
|
+
??? info "Source Location"
|
|
200
|
+
`lib/sqa/init.rb:95`
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
### `.homify(filepath)`
|
|
205
|
+
|
|
206
|
+
Expands ~ to user's home directory in filepath.
|
|
207
|
+
|
|
208
|
+
!!! info "Parameters"
|
|
209
|
+
|
|
210
|
+
| Name | Type | Description |
|
|
211
|
+
|------|------|-------------|
|
|
212
|
+
| `filepath` | `String` | Path potentially containing ~ |
|
|
213
|
+
!!! success "Returns"
|
|
214
|
+
|
|
215
|
+
**Type:** `String`
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
Path with ~ expanded
|
|
220
|
+
|
|
221
|
+
??? info "Source Location"
|
|
222
|
+
`lib/sqa/init.rb:101`
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
### `.data_dir()`
|
|
227
|
+
|
|
228
|
+
Returns the data directory as a Pathname.
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
!!! success "Returns"
|
|
232
|
+
|
|
233
|
+
**Type:** `Pathname`
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
Data directory path
|
|
238
|
+
|
|
239
|
+
??? info "Source Location"
|
|
240
|
+
`lib/sqa/init.rb:106`
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
### `.config()`
|
|
245
|
+
|
|
246
|
+
Returns the current configuration.
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
!!! success "Returns"
|
|
250
|
+
|
|
251
|
+
**Type:** `SQA::Config`
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
Configuration instance
|
|
256
|
+
|
|
257
|
+
??? info "Source Location"
|
|
258
|
+
`lib/sqa/init.rb:111`
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## 📝 Attributes
|
|
263
|
+
|
|
264
|
+
### 🔄 `config` <small>read/write</small>
|
|
265
|
+
|
|
266
|
+
Returns the current configuration.
|
|
267
|
+
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# 📦 SQA::Backtest
|
|
2
|
+
|
|
3
|
+
!!! abstract "Source Information"
|
|
4
|
+
**Defined in:** `lib/sqa/backtest.rb:7`
|
|
5
|
+
|
|
6
|
+
**Inherits from:** `Object`
|
|
7
|
+
|
|
8
|
+
## 🔨 Instance Methods
|
|
9
|
+
|
|
10
|
+
### `#stock()`
|
|
11
|
+
|
|
12
|
+
Returns the value of attribute stock.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
??? info "Source Location"
|
|
18
|
+
`lib/sqa/backtest.rb:8`
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
### `#strategy()`
|
|
23
|
+
|
|
24
|
+
Returns the value of attribute strategy.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
??? info "Source Location"
|
|
30
|
+
`lib/sqa/backtest.rb:8`
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
### `#portfolio()`
|
|
35
|
+
|
|
36
|
+
Returns the value of attribute portfolio.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
??? info "Source Location"
|
|
42
|
+
`lib/sqa/backtest.rb:8`
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
### `#results()`
|
|
47
|
+
|
|
48
|
+
Returns the value of attribute results.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
??? info "Source Location"
|
|
54
|
+
`lib/sqa/backtest.rb:8`
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
### `#equity_curve()`
|
|
59
|
+
|
|
60
|
+
Returns the value of attribute equity_curve.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
??? info "Source Location"
|
|
66
|
+
`lib/sqa/backtest.rb:8`
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
### `#initialize(stock:, strategy:, start_date: = nil, end_date: = nil, initial_capital: = 10_000.0, commission: = 0.0, position_size: = :all_cash)`
|
|
71
|
+
|
|
72
|
+
Initialize a backtest
|
|
73
|
+
|
|
74
|
+
!!! info "Parameters"
|
|
75
|
+
|
|
76
|
+
| Name | Type | Description |
|
|
77
|
+
|------|------|-------------|
|
|
78
|
+
| `stock` | `SQA::Stock` | Stock to backtest |
|
|
79
|
+
| `strategy` | `SQA::Strategy, Proc` | Strategy or callable that returns :buy, :sell, or :hold |
|
|
80
|
+
| `start_date` | `Date, String` | Start date for backtest |
|
|
81
|
+
| `end_date` | `Date, String` | End date for backtest |
|
|
82
|
+
| `initial_capital` | `Float` | Starting capital |
|
|
83
|
+
| `commission` | `Float` | Commission per trade |
|
|
84
|
+
| `position_size` | `Symbol, Float` | :all_cash or fraction of portfolio per trade |
|
|
85
|
+
!!! success "Returns"
|
|
86
|
+
|
|
87
|
+
**Type:** `Backtest`
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
a new instance of Backtest
|
|
92
|
+
|
|
93
|
+
??? info "Source Location"
|
|
94
|
+
`lib/sqa/backtest.rb:85`
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
### `#run()`
|
|
99
|
+
|
|
100
|
+
Run the backtest
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
!!! success "Returns"
|
|
104
|
+
|
|
105
|
+
**Type:** `Results`
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
Backtest results
|
|
110
|
+
|
|
111
|
+
??? info "Source Location"
|
|
112
|
+
`lib/sqa/backtest.rb:102`
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 📝 Attributes
|
|
117
|
+
|
|
118
|
+
### 👁️ `stock` <small>read-only</small>
|
|
119
|
+
|
|
120
|
+
Returns the value of attribute stock.
|
|
121
|
+
|
|
122
|
+
### 👁️ `strategy` <small>read-only</small>
|
|
123
|
+
|
|
124
|
+
Returns the value of attribute strategy.
|
|
125
|
+
|
|
126
|
+
### 👁️ `portfolio` <small>read-only</small>
|
|
127
|
+
|
|
128
|
+
Returns the value of attribute portfolio.
|
|
129
|
+
|
|
130
|
+
### 👁️ `results` <small>read-only</small>
|
|
131
|
+
|
|
132
|
+
Returns the value of attribute results.
|
|
133
|
+
|
|
134
|
+
### 👁️ `equity_curve` <small>read-only</small>
|
|
135
|
+
|
|
136
|
+
Returns the value of attribute equity_curve.
|
|
137
|
+
|