Class: SQA::Backtest::Results
- Inherits:
-
Object
- Object
- SQA::Backtest::Results
- Defined in:
- lib/sqa/backtest.rb
Overview
Represents the results of a backtest
Instance Attribute Summary collapse
-
#annualized_return ⇒ Object
Returns the value of attribute annualized_return.
-
#average_loss ⇒ Object
Returns the value of attribute average_loss.
-
#average_win ⇒ Object
Returns the value of attribute average_win.
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#final_value ⇒ Object
Returns the value of attribute final_value.
-
#initial_capital ⇒ Object
Returns the value of attribute initial_capital.
-
#losing_trades ⇒ Object
Returns the value of attribute losing_trades.
-
#max_drawdown ⇒ Object
Returns the value of attribute max_drawdown.
-
#profit_factor ⇒ Object
Returns the value of attribute profit_factor.
-
#sharpe_ratio ⇒ Object
Returns the value of attribute sharpe_ratio.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#total_return ⇒ Object
Returns the value of attribute total_return.
-
#total_trades ⇒ Object
Returns the value of attribute total_trades.
-
#win_rate ⇒ Object
Returns the value of attribute win_rate.
-
#winning_trades ⇒ Object
Returns the value of attribute winning_trades.
Instance Method Summary collapse
-
#initialize ⇒ Results
constructor
A new instance of Results.
- #summary ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ Results
Returns a new instance of Results.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sqa/backtest.rb', line 17 def initialize @total_return = 0.0 @annualized_return = 0.0 @sharpe_ratio = 0.0 @max_drawdown = 0.0 @total_trades = 0 @winning_trades = 0 @losing_trades = 0 @win_rate = 0.0 @average_win = 0.0 @average_loss = 0.0 @profit_factor = 0.0 end |
Instance Attribute Details
#annualized_return ⇒ Object
Returns the value of attribute annualized_return.
12 13 14 |
# File 'lib/sqa/backtest.rb', line 12 def annualized_return @annualized_return end |
#average_loss ⇒ Object
Returns the value of attribute average_loss.
12 13 14 |
# File 'lib/sqa/backtest.rb', line 12 def average_loss @average_loss end |
#average_win ⇒ Object
Returns the value of attribute average_win.
12 13 14 |
# File 'lib/sqa/backtest.rb', line 12 def average_win @average_win end |
#end_date ⇒ Object
Returns the value of attribute end_date.
12 13 14 |
# File 'lib/sqa/backtest.rb', line 12 def end_date @end_date end |
#final_value ⇒ Object
Returns the value of attribute final_value.
12 13 14 |
# File 'lib/sqa/backtest.rb', line 12 def final_value @final_value end |
#initial_capital ⇒ Object
Returns the value of attribute initial_capital.
12 13 14 |
# File 'lib/sqa/backtest.rb', line 12 def initial_capital @initial_capital end |
#losing_trades ⇒ Object
Returns the value of attribute losing_trades.
12 13 14 |
# File 'lib/sqa/backtest.rb', line 12 def losing_trades @losing_trades end |
#max_drawdown ⇒ Object
Returns the value of attribute max_drawdown.
12 13 14 |
# File 'lib/sqa/backtest.rb', line 12 def max_drawdown @max_drawdown end |
#profit_factor ⇒ Object
Returns the value of attribute profit_factor.
12 13 14 |
# File 'lib/sqa/backtest.rb', line 12 def profit_factor @profit_factor end |
#sharpe_ratio ⇒ Object
Returns the value of attribute sharpe_ratio.
12 13 14 |
# File 'lib/sqa/backtest.rb', line 12 def sharpe_ratio @sharpe_ratio end |
#start_date ⇒ Object
Returns the value of attribute start_date.
12 13 14 |
# File 'lib/sqa/backtest.rb', line 12 def start_date @start_date end |
#total_return ⇒ Object
Returns the value of attribute total_return.
12 13 14 |
# File 'lib/sqa/backtest.rb', line 12 def total_return @total_return end |
#total_trades ⇒ Object
Returns the value of attribute total_trades.
12 13 14 |
# File 'lib/sqa/backtest.rb', line 12 def total_trades @total_trades end |
#win_rate ⇒ Object
Returns the value of attribute win_rate.
12 13 14 |
# File 'lib/sqa/backtest.rb', line 12 def win_rate @win_rate end |
#winning_trades ⇒ Object
Returns the value of attribute winning_trades.
12 13 14 |
# File 'lib/sqa/backtest.rb', line 12 def winning_trades @winning_trades end |
Instance Method Details
#summary ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sqa/backtest.rb', line 51 def summary " Backtest Results\n ================\n Period: \#{start_date} to \#{end_date}\n Initial Capital: $\#{initial_capital.round(2)}\n Final Value: $\#{final_value.round(2)}\n\n Performance Metrics:\n - Total Return: \#{(total_return * 100).round(2)}%\n - Annualized Return: \#{(annualized_return * 100).round(2)}%\n - Sharpe Ratio: \#{sharpe_ratio.round(2)}\n - Maximum Drawdown: \#{(max_drawdown * 100).round(2)}%\n\n Trade Statistics:\n - Total Trades: \#{total_trades}\n - Winning Trades: \#{winning_trades}\n - Losing Trades: \#{losing_trades}\n - Win Rate: \#{(win_rate * 100).round(2)}%\n - Average Win: $\#{average_win.round(2)}\n - Average Loss: $\#{average_loss.round(2)}\n - Profit Factor: \#{profit_factor.round(2)}\n SUMMARY\nend\n" |
#to_h ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sqa/backtest.rb', line 31 def to_h { total_return: total_return, annualized_return: annualized_return, sharpe_ratio: sharpe_ratio, max_drawdown: max_drawdown, total_trades: total_trades, winning_trades: winning_trades, losing_trades: losing_trades, win_rate: win_rate, average_win: average_win, average_loss: average_loss, profit_factor: profit_factor, start_date: start_date, end_date: end_date, initial_capital: initial_capital, final_value: final_value } end |