Class: SQA::Backtest::Results

Inherits:
Object
  • Object
show all
Defined in:
lib/sqa/backtest.rb

Overview

Represents the results of a backtest

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResults

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_returnObject

Returns the value of attribute annualized_return.



12
13
14
# File 'lib/sqa/backtest.rb', line 12

def annualized_return
  @annualized_return
end

#average_lossObject

Returns the value of attribute average_loss.



12
13
14
# File 'lib/sqa/backtest.rb', line 12

def average_loss
  @average_loss
end

#average_winObject

Returns the value of attribute average_win.



12
13
14
# File 'lib/sqa/backtest.rb', line 12

def average_win
  @average_win
end

#end_dateObject

Returns the value of attribute end_date.



12
13
14
# File 'lib/sqa/backtest.rb', line 12

def end_date
  @end_date
end

#final_valueObject

Returns the value of attribute final_value.



12
13
14
# File 'lib/sqa/backtest.rb', line 12

def final_value
  @final_value
end

#initial_capitalObject

Returns the value of attribute initial_capital.



12
13
14
# File 'lib/sqa/backtest.rb', line 12

def initial_capital
  @initial_capital
end

#losing_tradesObject

Returns the value of attribute losing_trades.



12
13
14
# File 'lib/sqa/backtest.rb', line 12

def losing_trades
  @losing_trades
end

#max_drawdownObject

Returns the value of attribute max_drawdown.



12
13
14
# File 'lib/sqa/backtest.rb', line 12

def max_drawdown
  @max_drawdown
end

#profit_factorObject

Returns the value of attribute profit_factor.



12
13
14
# File 'lib/sqa/backtest.rb', line 12

def profit_factor
  @profit_factor
end

#sharpe_ratioObject

Returns the value of attribute sharpe_ratio.



12
13
14
# File 'lib/sqa/backtest.rb', line 12

def sharpe_ratio
  @sharpe_ratio
end

#start_dateObject

Returns the value of attribute start_date.



12
13
14
# File 'lib/sqa/backtest.rb', line 12

def start_date
  @start_date
end

#total_returnObject

Returns the value of attribute total_return.



12
13
14
# File 'lib/sqa/backtest.rb', line 12

def total_return
  @total_return
end

#total_tradesObject

Returns the value of attribute total_trades.



12
13
14
# File 'lib/sqa/backtest.rb', line 12

def total_trades
  @total_trades
end

#win_rateObject

Returns the value of attribute win_rate.



12
13
14
# File 'lib/sqa/backtest.rb', line 12

def win_rate
  @win_rate
end

#winning_tradesObject

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

#summaryObject



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
  <<~SUMMARY
    Backtest Results
    ================
    Period: #{start_date} to #{end_date}
    Initial Capital: $#{initial_capital.round(2)}
    Final Value: $#{final_value.round(2)}

    Performance Metrics:
    - Total Return: #{(total_return * 100).round(2)}%
    - Annualized Return: #{(annualized_return * 100).round(2)}%
    - Sharpe Ratio: #{sharpe_ratio.round(2)}
    - Maximum Drawdown: #{(max_drawdown * 100).round(2)}%

    Trade Statistics:
    - Total Trades: #{total_trades}
    - Winning Trades: #{winning_trades}
    - Losing Trades: #{losing_trades}
    - Win Rate: #{(win_rate * 100).round(2)}%
    - Average Win: $#{average_win.round(2)}
    - Average Loss: $#{average_loss.round(2)}
    - Profit Factor: #{profit_factor.round(2)}
  SUMMARY
end

#to_hObject



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