2020-07-26 11:44:34 +00:00
|
|
|
<template>
|
2020-09-25 04:22:34 +00:00
|
|
|
<div class="container">
|
2020-07-27 05:19:45 +00:00
|
|
|
<h2>Backtesting</h2>
|
2020-09-25 04:22:34 +00:00
|
|
|
<div class="row mx-5 d-flex flex-wrap justify-space-between mb-4">
|
|
|
|
<b-form-radio v-model="btFormMode" name="bt-form-radios" button value="params"
|
|
|
|
>Define Parameters</b-form-radio
|
|
|
|
>
|
|
|
|
<b-form-radio v-model="btFormMode" name="bt-form-radios" button value="strategy"
|
|
|
|
>Select Strategy</b-form-radio
|
|
|
|
>
|
|
|
|
<b-form-radio
|
|
|
|
v-model="btFormMode"
|
|
|
|
name="bt-form-radios"
|
|
|
|
button
|
|
|
|
value="run"
|
|
|
|
:disabled="!canRunBacktest"
|
|
|
|
>Run backtest</b-form-radio
|
|
|
|
>
|
|
|
|
<b-form-radio
|
|
|
|
v-model="btFormMode"
|
|
|
|
name="bt-form-radios"
|
|
|
|
button
|
|
|
|
value="results"
|
|
|
|
:disabled="!hasBacktestResult"
|
|
|
|
>Analyze result</b-form-radio
|
|
|
|
>
|
|
|
|
<b-form-radio
|
|
|
|
v-model="btFormMode"
|
|
|
|
name="bt-form-radios"
|
|
|
|
button
|
|
|
|
value="visualize"
|
|
|
|
:disabled="!hasBacktestResult"
|
|
|
|
>Visualize result</b-form-radio
|
|
|
|
>
|
2020-07-26 11:44:34 +00:00
|
|
|
</div>
|
2020-09-25 04:22:34 +00:00
|
|
|
<div v-if="btFormMode == 'params'" class="row">
|
|
|
|
<TimeRangeSelect v-model="timerange"></TimeRangeSelect>
|
2020-07-26 17:35:56 +00:00
|
|
|
</div>
|
2020-09-25 04:22:34 +00:00
|
|
|
<div v-if="btFormMode == 'params'" class="row">
|
|
|
|
<b-card bg-variant="light" class="w-60">
|
|
|
|
<b-form-group
|
|
|
|
label-cols-lg="2"
|
|
|
|
label="Backtest params"
|
|
|
|
label-size="sm"
|
|
|
|
label-class="font-weight-bold pt-0"
|
|
|
|
class="mb-0"
|
|
|
|
>
|
|
|
|
<b-form-group
|
|
|
|
label-cols-sm="5"
|
|
|
|
label="Timeframe:"
|
|
|
|
label-align-sm="right"
|
|
|
|
label-for="timeframeSelect"
|
|
|
|
>
|
|
|
|
<b-form-select
|
|
|
|
id="timeframe-select"
|
|
|
|
placeholder="Use strategy default"
|
|
|
|
:options="availableTimeframes"
|
|
|
|
></b-form-select>
|
|
|
|
</b-form-group>
|
|
|
|
|
|
|
|
<b-form-group
|
|
|
|
label-cols-sm="5"
|
|
|
|
label="Max open trades:"
|
|
|
|
label-align-sm="right"
|
|
|
|
label-for="max-open-trades"
|
|
|
|
>
|
|
|
|
<b-form-input
|
|
|
|
id="max-open-trades"
|
|
|
|
placeholder="Use strategy default"
|
|
|
|
type="number"
|
|
|
|
></b-form-input>
|
|
|
|
</b-form-group>
|
|
|
|
|
|
|
|
<b-form-group
|
|
|
|
label-cols-sm="5"
|
|
|
|
label="Stake amount:"
|
|
|
|
label-align-sm="right"
|
|
|
|
label-for="stake-amount"
|
2020-07-27 05:19:45 +00:00
|
|
|
>
|
2020-09-25 04:22:34 +00:00
|
|
|
<b-form-input
|
|
|
|
id="stake-amount"
|
|
|
|
type="number"
|
|
|
|
placeholder="Use strategy default"
|
|
|
|
step="0.01"
|
|
|
|
></b-form-input>
|
|
|
|
</b-form-group>
|
|
|
|
|
|
|
|
<b-form-group label-cols-sm="5" label="Fee:" label-align-sm="right" label-for="fee">
|
|
|
|
<b-form-input
|
|
|
|
id="fee"
|
|
|
|
type="number"
|
|
|
|
placeholder="Use exchange default"
|
|
|
|
step="0.01"
|
|
|
|
></b-form-input>
|
|
|
|
</b-form-group>
|
|
|
|
</b-form-group>
|
|
|
|
</b-card>
|
|
|
|
</div>
|
|
|
|
<div v-if="btFormMode == 'strategy'" class="row">
|
|
|
|
<StrategyList v-model="strategy" show-details="true"></StrategyList>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-if="btFormMode == 'run'" class="row container">
|
|
|
|
<div class="row">
|
|
|
|
<h3>Backtesting summary</h3>
|
|
|
|
</div>
|
|
|
|
<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>
|
|
|
|
<b-button variant="primary" :disabled="backtestRunning" @click="removeBacktest">
|
|
|
|
Reset Backtest
|
|
|
|
</b-button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-if="hasBacktestResult && btFormMode == 'results'" class="text-center w-100 mt-2">
|
|
|
|
<BacktestResultView :strategy="strategy" :backtest-result="selectedBacktestResult" />
|
|
|
|
</div>
|
|
|
|
<div v-if="hasBacktestResult && btFormMode == 'visualize'" class="text-center w-100 mt-2">
|
|
|
|
<CandleChartContainer
|
|
|
|
:available-pairs="selectedBacktestResult.pairlist"
|
|
|
|
:historic-view="!!true"
|
|
|
|
:timeframe="timeframe"
|
|
|
|
:plot-config="selectedPlotConfig"
|
|
|
|
:timerange="timerange"
|
|
|
|
:strategy="strategy"
|
|
|
|
:trades="selectedBacktestResult.trades"
|
|
|
|
class="candle-chart-container"
|
|
|
|
>
|
|
|
|
</CandleChartContainer>
|
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-09-25 04:22:34 +00:00
|
|
|
availableTimeframes = [
|
|
|
|
'1m',
|
|
|
|
'3m',
|
|
|
|
'5m',
|
|
|
|
'15m',
|
|
|
|
'30m',
|
|
|
|
'1h',
|
|
|
|
'2h',
|
|
|
|
'4h',
|
|
|
|
'6h',
|
|
|
|
'8h',
|
|
|
|
'12h',
|
|
|
|
'1d',
|
|
|
|
'3d',
|
|
|
|
'1w',
|
|
|
|
'2w',
|
|
|
|
'1M',
|
|
|
|
'1y',
|
|
|
|
];
|
|
|
|
|
|
|
|
strategy = '';
|
|
|
|
|
|
|
|
btFormMode = 'params';
|
2020-07-26 17:35:56 +00:00
|
|
|
|
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-09-18 18:56:20 +00:00
|
|
|
@ftbot.Action removeBacktest!: () => void;
|
|
|
|
|
2020-09-25 04:22:34 +00:00
|
|
|
get canRunBacktest() {
|
|
|
|
// TODO: Analyze if parameters and strategy has been selected.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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>
|
|
|
|
|
2020-09-16 18:28:48 +00:00
|
|
|
<style scoped>
|
|
|
|
.candle-chart-container {
|
|
|
|
height: 640px !important;
|
|
|
|
}
|
|
|
|
</style>
|