From b1266bd4f65ea4dc79d6acfe08594e19c923167d Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 20 Jul 2023 20:47:30 +0200 Subject: [PATCH] Add winrate to backtest results closes #1372 --- src/components/ftbot/BacktestResultView.vue | 26 ++++++++++++++------- src/types/backtest.ts | 3 +++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/components/ftbot/BacktestResultView.vue b/src/components/ftbot/BacktestResultView.vue index 67b55a45..019dca81 100644 --- a/src/components/ftbot/BacktestResultView.vue +++ b/src/components/ftbot/BacktestResultView.vue @@ -79,6 +79,7 @@ import { formatPercent, formatPrice, humanizeDurationFromSeconds, + isNotUndefined, } from '@/shared/formatters'; import { TableField, TableItem } from 'bootstrap-vue-next'; @@ -115,6 +116,10 @@ const worstPair = computed((): string => { return `${value.pair} ${formatPercent(value.profit_ratio, 2)}`; }); +const pairSummary = computed(() => { + return props.backtestResult.results_per_pair[props.backtestResult.results_per_pair.length - 1]; +}); + const backtestResultStats = computed(() => { // Transpose Result into readable format const shortMetrics = @@ -198,14 +203,19 @@ const backtestResultStats = computed(() => { { metric: 'Win/Draw/Loss', - value: `${ - props.backtestResult.results_per_pair[props.backtestResult.results_per_pair.length - 1].wins - } / ${ - props.backtestResult.results_per_pair[props.backtestResult.results_per_pair.length - 1] - .draws - } / ${ - props.backtestResult.results_per_pair[props.backtestResult.results_per_pair.length - 1] - .losses + value: `${pairSummary.value.wins} / ${pairSummary.value.draws} / ${ + pairSummary.value.losses + } ${ + isNotUndefined(pairSummary.value.winrate) + ? '(WR: ' + + formatPercent( + props.backtestResult.results_per_pair[ + props.backtestResult.results_per_pair.length - 1 + ].winrate ?? 0, + 2, + ) + + ')' + : '' }`, }, { diff --git a/src/types/backtest.ts b/src/types/backtest.ts index 48fbfa24..b306cad2 100644 --- a/src/types/backtest.ts +++ b/src/types/backtest.ts @@ -32,6 +32,7 @@ export interface PairResult { profit_total: number; trades: number; wins: number; + winrate?: number; } export interface ExitReasonResults { @@ -48,6 +49,7 @@ export interface ExitReasonResults { profit_total_pct: number; trades: number; wins: number; + winrate?: number; } // Generated by https://quicktype.io @@ -59,6 +61,7 @@ export interface PeriodicStat { wins: number; draws: number; loses: number; + winrate?: number; } export interface PeriodicBreakdown {