frequi_origin/src/views/Backtesting.vue

128 lines
3.7 KiB
Vue
Raw Normal View History

2020-07-26 11:44:34 +00:00
<template>
<div class="container-fluid">
2020-07-27 05:19:45 +00:00
<h2>Backtesting</h2>
2020-07-26 17:36:47 +00:00
<div class="row ml-1">
2020-08-08 18:21:47 +00:00
<div class="row col-mb-6 mr-2">
2020-07-26 17:36:47 +00:00
<TimeRangeSelect v-model="timerange"></TimeRangeSelect>
2020-08-08 18:21:47 +00:00
<StrategyList v-model="strategy" class="col-md-2"></StrategyList>
2020-07-26 17:36:47 +00:00
</div>
2020-07-26 11:44:34 +00:00
</div>
2020-07-26 17:35:56 +00:00
<div class="row">
<b-button variant="primary" :disabled="backtestRunning" @click="clickBacktest">
Start backtest
</b-button>
<b-button variant="primary" :disabled="backtestRunning" @click="pollBacktest">
Load backtest result
</b-button>
</div>
<div v-if="hasBacktestResult" class="text-center w-100 mt-2">
2020-07-27 05:19:45 +00:00
<b-tabs content-class="mt-3" class="mt-3">
<b-tab title="Textbased Result" active>
<BacktestResultView :strategy="strategy" :backtest-result="selectedBacktestResult" />
</b-tab>
<b-tab title="Graph" lazy>
2020-09-12 17:21:35 +00:00
<CandleChartContainer
:available-pairs="selectedBacktestResult.pairlist"
:historic-view="!!true"
2020-07-27 05:19:45 +00:00
:timeframe="timeframe"
:plot-config="selectedPlotConfig"
:timerange="timerange"
:strategy="strategy"
2020-07-27 05:19:45 +00:00
:trades="selectedBacktestResult.trades"
class="candle-chart-container"
2020-07-27 05:19:45 +00:00
>
2020-09-12 17:21:35 +00:00
</CandleChartContainer>
2020-07-27 05:19:45 +00:00
</b-tab>
</b-tabs>
2020-07-26 17:35:56 +00:00
</div>
2020-07-26 11:44:34 +00:00
</div>
</template>
<script lang="ts">
import { Component, Vue, Watch } from 'vue-property-decorator';
import { namespace } from 'vuex-class';
import TimeRangeSelect from '@/components/ftbot/TimeRangeSelect.vue';
2020-07-26 17:35:56 +00:00
import BacktestResultView from '@/components/ftbot/BacktestResultView.vue';
2020-09-12 17:21:35 +00:00
import CandleChartContainer from '@/components/charts/CandleChartContainer.vue';
2020-08-08 18:21:47 +00:00
import StrategyList from '@/components/ftbot/StrategyList.vue';
2020-07-26 17:35:56 +00:00
2020-07-27 05:19:45 +00:00
import {
BacktestPayload,
BacktestResult,
PairHistoryPayload,
PlotConfig,
StrategyBacktestResult,
} from '@/types';
import { getCustomPlotConfig, getPlotConfigName } from '@/shared/storage';
2020-07-26 11:44:34 +00:00
const ftbot = namespace('ftbot');
@Component({
2020-09-12 17:21:35 +00:00
components: { BacktestResultView, TimeRangeSelect, CandleChartContainer, StrategyList },
2020-07-26 11:44:34 +00:00
})
2020-07-26 17:35:56 +00:00
export default class Backtesting extends Vue {
pollInterval: number | null = null;
2020-07-26 11:44:34 +00:00
2020-07-26 17:35:56 +00:00
strategy = 'BinHV45';
2020-07-27 05:19:45 +00:00
selectedPlotConfig: PlotConfig = getCustomPlotConfig(getPlotConfigName());
2020-07-26 11:44:34 +00:00
@ftbot.State backtestRunning!: boolean;
2020-07-26 17:35:56 +00:00
@ftbot.State backtestResult!: BacktestResult;
2020-07-27 05:19:45 +00:00
@ftbot.State history;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@ftbot.Action public getPairHistory!: (payload: PairHistoryPayload) => void;
2020-07-26 11:44:34 +00:00
timerange = '';
2020-07-26 17:35:56 +00:00
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@ftbot.Action startBacktest!: (payload: BacktestPayload) => void;
2020-07-26 11:44:34 +00:00
@ftbot.Action pollBacktest!: () => void;
2020-07-26 17:35:56 +00:00
get hasBacktestResult() {
return Object.keys(this.backtestResult).length !== 0;
}
2020-07-27 05:19:45 +00:00
get selectedBacktestResult(): StrategyBacktestResult {
return this.backtestResult.strategy[this.strategy] || {};
}
2020-08-08 18:21:47 +00:00
get timeframe(): string {
try {
return this.backtestResult.strategy[this.strategy].timeframe;
} catch (err) {
return '';
}
}
2020-07-26 11:44:34 +00:00
clickBacktest() {
console.log('Backtesting');
const btPayload: BacktestPayload = {
2020-07-26 17:35:56 +00:00
strategy: this.strategy,
2020-07-26 11:44:34 +00:00
timerange: this.timerange,
};
this.startBacktest(btPayload);
}
@Watch('backtestRunning')
backtestRunningChanged() {
if (this.backtestRunning === true) {
2020-07-26 17:35:56 +00:00
this.pollInterval = window.setInterval(this.pollBacktest, 1000);
2020-07-26 11:44:34 +00:00
} else if (this.pollInterval) {
clearInterval(this.pollInterval);
this.pollInterval = null;
}
}
}
</script>
<style scoped>
.candle-chart-container {
height: 640px !important;
}
</style>