Skip to content

Commit

Permalink
sterling ratio is adg / drawdown_worst_mean_1pct
Browse files Browse the repository at this point in the history
  • Loading branch information
enarjord committed Nov 28, 2024
1 parent b954765 commit 6080e30
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions passivbot-rust/src/backtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,29 +1563,21 @@ pub fn analyze_backtest(fills: &[Fill], equities: &Vec<f64>) -> Analysis {
.iter()
.fold(f64::NEG_INFINITY, |a, &b| f64::max(a, b.abs()));

let calmar_ratio = if drawdown_worst != 0.0 {
adg / drawdown_worst
} else {
0.0
};

// Calculate Sterling Ratio (using average of worst N drawdowns)
// Calculate Sterling Ratio (using average of worst 1% drawdowns)
let sterling_ratio = {
let mut sorted_drawdowns = drawdowns.clone();
sorted_drawdowns.sort_by(|a, b| b.abs().partial_cmp(&a.abs()).unwrap_or(Ordering::Equal));
let worst_n = std::cmp::min(10, sorted_drawdowns.len());
let avg_worst_drawdowns = sorted_drawdowns[..worst_n]
.iter()
.map(|x| x.abs())
.sum::<f64>()
/ worst_n as f64;
if avg_worst_drawdowns != 0.0 {
adg / avg_worst_drawdowns // Using raw daily gain instead of annualized
if drawdown_worst_mean_1pct != 0.0 {
adg / drawdown_worst_mean_1pct
} else {
0.0
}
};

let calmar_ratio = if drawdown_worst != 0.0 {
adg / drawdown_worst
} else {
0.0
};

// Calculate equity-balance differences
let mut bal_eq = Vec::with_capacity(equities.len());
let mut fill_iter = fills.iter().peekable();
Expand Down

0 comments on commit 6080e30

Please sign in to comment.