📦 SQA::Backtest¶
🔨 Instance Methods¶
#stock()¶
Returns the value of attribute stock.
Source Location
#strategy()¶
Returns the value of attribute strategy.
Source Location
#portfolio()¶
Returns the value of attribute portfolio.
Source Location
#results()¶
Returns the value of attribute results.
Source Location
#equity_curve()¶
Returns the value of attribute equity_curve.
Source Location
#initialize(stock:, strategy:, start_date: = nil, end_date: = nil, initial_capital: = 10_000.0, commission: = 0.0, position_size: = :all_cash)¶
Initialize a backtest
Parameters
| Name | Type | Description |
|---|---|---|
stock |
SQA::Stock |
Stock to backtest |
strategy |
SQA::Strategy, Proc |
Strategy or callable that returns :buy, :sell, or :hold |
start_date |
Date, String |
Start date for backtest |
end_date |
Date, String |
End date for backtest |
initial_capital |
Float |
Starting capital |
commission |
Float |
Commission per trade |
position_size |
Symbol, Float |
:all_cash or fraction of portfolio per trade |
Returns
Type: Backtest
a new instance of Backtest
Source Location
#run()¶
Run the backtest
Returns
Type: Results
Backtest results
Usage Examples
stock = SQA::Stock.new(ticker: 'AAPL')
backtest = SQA::Backtest.new(
stock: stock,
strategy: SQA::Strategy::RSI,
initial_capital: 10_000,
commission: 1.0
)
results = backtest.run
puts results.summary
# => Total Return: 15.5%
# Sharpe Ratio: 1.2
# Max Drawdown: -8.3%
# Win Rate: 65%
Source Location
📝 Attributes¶
👁️ stock read-only¶
Returns the value of attribute stock.
👁️ strategy read-only¶
Returns the value of attribute strategy.
👁️ portfolio read-only¶
Returns the value of attribute portfolio.
👁️ results read-only¶
Returns the value of attribute results.
👁️ equity_curve read-only¶
Returns the value of attribute equity_curve.