mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-26 21:15:15 +00:00
Improve memory structure for backtest result
This commit is contained in:
parent
46ca166863
commit
094208cfd2
|
@ -3,14 +3,15 @@
|
|||
<h3>Available results:</h3>
|
||||
<b-list-group class="ms-2">
|
||||
<b-list-group-item
|
||||
v-for="[key, strat] in Object.entries(backtestHistory)"
|
||||
v-for="[key, result] in Object.entries(backtestHistory)"
|
||||
:key="key"
|
||||
button
|
||||
:active="key === selectedBacktestResultKey"
|
||||
class="d-flex justify-content-between align-items-center py-1 pe-1"
|
||||
@click="setBacktestResult(key)"
|
||||
>
|
||||
{{ key }} {{ strat.total_trades }} {{ formatPercent(strat.profit_total) }}
|
||||
{{ key }} {{ result.strategy.total_trades }}
|
||||
{{ formatPercent(result.strategy.profit_total) }}
|
||||
<b-button
|
||||
class="ms-2"
|
||||
size="sm"
|
||||
|
@ -26,12 +27,12 @@
|
|||
|
||||
<script setup lang="ts">
|
||||
import { formatPercent } from '@/shared/formatters';
|
||||
import { StrategyBacktestResult } from '@/types';
|
||||
import { BacktestResultInMemory } from '@/types';
|
||||
|
||||
defineProps({
|
||||
backtestHistory: {
|
||||
required: true,
|
||||
type: Object as () => Record<string, StrategyBacktestResult>,
|
||||
type: Object as () => Record<string, BacktestResultInMemory>,
|
||||
},
|
||||
selectedBacktestResultKey: { required: false, default: '', type: String },
|
||||
});
|
||||
|
|
|
@ -43,6 +43,7 @@ import {
|
|||
PairlistEvalResponse,
|
||||
PairlistsPayload,
|
||||
PairlistsResponse,
|
||||
BacktestResultInMemory,
|
||||
} from '@/types';
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
import { defineStore } from 'pinia';
|
||||
|
@ -102,7 +103,7 @@ export function createBotSubStore(botId: string, botName: string) {
|
|||
backtestTradeCount: 0,
|
||||
backtestResult: undefined as BacktestResult | undefined,
|
||||
selectedBacktestResultKey: '',
|
||||
backtestHistory: {} as Record<string, StrategyBacktestResult>,
|
||||
backtestHistory: {} as Record<string, BacktestResultInMemory>,
|
||||
backtestHistoryList: [] as BacktestHistoryEntry[],
|
||||
sysInfo: {} as SysInfoResponse,
|
||||
};
|
||||
|
@ -114,7 +115,8 @@ export function createBotSubStore(botId: string, botName: string) {
|
|||
stakeCurrencyDecimals: (state) => state.botState?.stake_currency_decimals || 3,
|
||||
canRunBacktest: (state) => state.botState?.runmode === RunModes.WEBSERVER,
|
||||
isWebserverMode: (state) => state.botState?.runmode === RunModes.WEBSERVER,
|
||||
selectedBacktestResult: (state) => state.backtestHistory[state.selectedBacktestResultKey],
|
||||
selectedBacktestResult: (state) =>
|
||||
state.backtestHistory[state.selectedBacktestResultKey]?.strategy || {},
|
||||
shortAllowed: (state) => state.botState?.short_allowed || false,
|
||||
openTradeCount: (state) => state.openTrades.length,
|
||||
isTrading: (state) =>
|
||||
|
@ -898,11 +900,16 @@ export function createBotSubStore(botId: string, botName: string) {
|
|||
this.backtestResult = backtestResult;
|
||||
// TODO: Properly identify duplicates to avoid pushing the same multiple times
|
||||
Object.entries(backtestResult.strategy).forEach(([key, strat]) => {
|
||||
console.log(key, strat);
|
||||
const metadata = backtestResult.metadata[key];
|
||||
console.log(key, strat, metadata);
|
||||
|
||||
const stratKey = `${key}_${strat.total_trades}_${strat.profit_total.toFixed(3)}`;
|
||||
const btResult: BacktestResultInMemory = {
|
||||
metadata,
|
||||
strategy: strat,
|
||||
};
|
||||
// this.backtestHistory[stratKey] = strat;
|
||||
this.backtestHistory = { ...this.backtestHistory, ...{ [stratKey]: strat } };
|
||||
this.backtestHistory = { ...this.backtestHistory, ...{ [stratKey]: btResult } };
|
||||
this.selectedBacktestResultKey = stratKey;
|
||||
});
|
||||
},
|
||||
|
|
|
@ -188,6 +188,14 @@ export interface BacktestMetadata {
|
|||
run_id: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the in-memory result of a backtest.
|
||||
*/
|
||||
export interface BacktestResultInMemory {
|
||||
strategy: StrategyBacktestResult;
|
||||
metadata: BacktestMetadata;
|
||||
}
|
||||
|
||||
export interface BacktestResult {
|
||||
strategy: Record<string, StrategyBacktestResult>;
|
||||
strategy_comparison: Array<Record<string, string | number>>;
|
||||
|
|
Loading…
Reference in New Issue
Block a user