selected backtest result in store

This commit is contained in:
Matthias 2021-01-15 20:41:32 +01:00
parent 2cc7c88975
commit 980edc2333
4 changed files with 49 additions and 30 deletions

View File

@ -23,6 +23,7 @@ import {
Lock, Lock,
RunModes, RunModes,
TradeResponse, TradeResponse,
StrategyBacktestResult,
} from '@/types'; } from '@/types';
import { import {
@ -48,6 +49,7 @@ export enum BotStoreGetters {
isTrading = 'isTrading', isTrading = 'isTrading',
isWebserverMode = 'isWebserverMode', isWebserverMode = 'isWebserverMode',
refreshRequired = 'refreshRequired', refreshRequired = 'refreshRequired',
selectedBacktestResult = 'selectedBacktestResult',
} }
export default { export default {
@ -110,6 +112,9 @@ export default {
[BotStoreGetters.refreshRequired](state: FtbotStateType): boolean { [BotStoreGetters.refreshRequired](state: FtbotStateType): boolean {
return state.refreshRequired; return state.refreshRequired;
}, },
[BotStoreGetters.selectedBacktestResult](state): StrategyBacktestResult {
return state.backtestHistory[state.selectedBacktestResultKey];
},
}, },
mutations: { mutations: {
updateRefreshRequired(state: FtbotStateType, refreshRequired: boolean) { updateRefreshRequired(state: FtbotStateType, refreshRequired: boolean) {
@ -190,7 +195,7 @@ export default {
storeCustomPlotConfig(plotConfig); storeCustomPlotConfig(plotConfig);
state.availablePlotConfigNames = getAllPlotConfigNames(); state.availablePlotConfigNames = getAllPlotConfigNames();
}, },
updateBacktestRunning(state, running: boolean) { updateBacktestRunning(state: FtbotStateType, running: boolean) {
state.backtestRunning = running; state.backtestRunning = running;
}, },
updateBacktestResult(state, backtestResult: BacktestResult) { updateBacktestResult(state, backtestResult: BacktestResult) {
@ -199,8 +204,12 @@ export default {
Object.entries(backtestResult.strategy).forEach(([key, strat]) => { Object.entries(backtestResult.strategy).forEach(([key, strat]) => {
const xxx = `${key}_${strat.total_trades}_${strat.profit_total.toFixed(3)}`; const xxx = `${key}_${strat.total_trades}_${strat.profit_total.toFixed(3)}`;
state.backtestHistory[xxx] = strat; state.backtestHistory[xxx] = strat;
state.selectedBacktestResultKey = xxx;
}); });
}, },
setBacktestResultKey(state: FtbotStateType, key: string) {
state.selectedBacktestResultKey = key;
},
}, },
actions: { actions: {
ping({ commit, rootState }) { ping({ commit, rootState }) {

View File

@ -44,6 +44,7 @@ export interface FtbotStateType {
currentLocks?: LockResponse; currentLocks?: LockResponse;
backtestRunning: boolean; backtestRunning: boolean;
backtestResult?: BacktestResult; backtestResult?: BacktestResult;
selectedBacktestResultKey: string;
backtestHistory: Record<string, BacktestResult>; backtestHistory: Record<string, BacktestResult>;
} }
const state: FtbotStateType = { const state: FtbotStateType = {
@ -76,6 +77,7 @@ const state: FtbotStateType = {
// backtesting // backtesting
backtestRunning: false, backtestRunning: false,
backtestResult: undefined, backtestResult: undefined,
selectedBacktestResultKey: '',
backtestHistory: {}, backtestHistory: {},
}; };

View File

@ -96,7 +96,7 @@ export interface StrategyBacktestResult {
/** Start time of the backtest run */ /** Start time of the backtest run */
backtest_run_start_ts: number; backtest_run_start_ts: number;
/** ENd time of the backtest run */ /** End time of the backtest run */
backtest_run_end_ts: number; backtest_run_end_ts: number;
} }

View File

@ -145,14 +145,16 @@
</div> </div>
<div v-if="hasBacktestResult && btFormMode == 'results'" class="text-center w-100 mt-2"> <div v-if="hasBacktestResult && btFormMode == 'results'" class="text-center w-100 mt-2">
<div class="d-flex"> <div class="d-flex">
<b-list-group-item <b-list-group>
v-for="[key, strat] in Object.entries(backtestHistory)" <b-list-group-item
:key="key" v-for="[key, strat] in Object.entries(backtestHistory)"
button :key="key"
class="d-flex justify-content-between align-items-center py-1" button
> class="d-flex justify-content-between align-items-center py-1"
{{ key }} {{ strat.total_trades }} {{ formatPercent(strat.profit_total) }} >
</b-list-group-item> {{ key }} {{ strat.total_trades }} {{ formatPercent(strat.profit_total) }}
</b-list-group-item>
</b-list-group>
</div> </div>
<BacktestResultView :strategy="strategy" :backtest-result="selectedBacktestResult" /> <BacktestResultView :strategy="strategy" :backtest-result="selectedBacktestResult" />
</div> </div>
@ -172,23 +174,26 @@
v-if="hasBacktestResult && btFormMode == 'visualize'" v-if="hasBacktestResult && btFormMode == 'visualize'"
class="container-fluid row text-center w-100 mt-2" class="container-fluid row text-center w-100 mt-2"
> >
<PairSummary <p>Graph will always show the latest values for the selected strategy.</p>
class="col-md-2" <div class="container-fluid row text-center">
:pairlist="selectedBacktestResult.pairlist" <PairSummary
:trades="selectedBacktestResult.trades" class="col-md-2"
sort-method="profit" :pairlist="selectedBacktestResult.pairlist"
/> :trades="selectedBacktestResult.trades"
<CandleChartContainer sort-method="profit"
:available-pairs="selectedBacktestResult.pairlist" />
:historic-view="!!true" <CandleChartContainer
:timeframe="timeframe" :available-pairs="selectedBacktestResult.pairlist"
:plot-config="selectedPlotConfig" :historic-view="!!true"
:timerange="timerange" :timeframe="timeframe"
:strategy="strategy" :plot-config="selectedPlotConfig"
:trades="selectedBacktestResult.trades" :timerange="timerange"
class="col-md-10 candle-chart-container" :strategy="strategy"
> :trades="selectedBacktestResult.trades"
</CandleChartContainer> class="col-md-10 candle-chart-container"
>
</CandleChartContainer>
</div>
</div> </div>
</div> </div>
</template> </template>
@ -215,6 +220,7 @@ import {
import { getCustomPlotConfig, getPlotConfigName } from '@/shared/storage'; import { getCustomPlotConfig, getPlotConfigName } from '@/shared/storage';
import { formatPercent } from '@/shared/formatters'; import { formatPercent } from '@/shared/formatters';
import { BotStoreGetters } from '@/store/modules/ftbot';
const ftbot = namespace('ftbot'); const ftbot = namespace('ftbot');
@Component({ @Component({
@ -274,6 +280,8 @@ export default class Backtesting extends Vue {
@ftbot.State backtestHistory!: StrategyBacktestResult[]; @ftbot.State backtestHistory!: StrategyBacktestResult[];
@ftbot.Getter [BotStoreGetters.selectedBacktestResult]!: StrategyBacktestResult;
@ftbot.State history; @ftbot.State history;
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
@ -297,9 +305,9 @@ export default class Backtesting extends Vue {
return Object.keys(this.backtestResult).length !== 0; return Object.keys(this.backtestResult).length !== 0;
} }
get selectedBacktestResult(): StrategyBacktestResult { // get selectedBacktestResult(): StrategyBacktestResult {
return this.backtestResult.strategy[this.strategy] || {}; // return this.backtestResult.strategy[this.strategy] || {};
} // }
get timeframe(): string { get timeframe(): string {
try { try {