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,6 +145,7 @@
</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>
<b-list-group-item <b-list-group-item
v-for="[key, strat] in Object.entries(backtestHistory)" v-for="[key, strat] in Object.entries(backtestHistory)"
:key="key" :key="key"
@ -153,6 +154,7 @@
> >
{{ key }} {{ strat.total_trades }} {{ formatPercent(strat.profit_total) }} {{ key }} {{ strat.total_trades }} {{ formatPercent(strat.profit_total) }}
</b-list-group-item> </b-list-group-item>
</b-list-group>
</div> </div>
<BacktestResultView :strategy="strategy" :backtest-result="selectedBacktestResult" /> <BacktestResultView :strategy="strategy" :backtest-result="selectedBacktestResult" />
</div> </div>
@ -172,6 +174,8 @@
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"
> >
<p>Graph will always show the latest values for the selected strategy.</p>
<div class="container-fluid row text-center">
<PairSummary <PairSummary
class="col-md-2" class="col-md-2"
:pairlist="selectedBacktestResult.pairlist" :pairlist="selectedBacktestResult.pairlist"
@ -191,6 +195,7 @@
</CandleChartContainer> </CandleChartContainer>
</div> </div>
</div> </div>
</div>
</template> </template>
<script lang="ts"> <script lang="ts">
@ -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 {