Merge pull request #1059 from freqtrade/freqai_backtest

Freqai backtest
This commit is contained in:
Matthias 2022-12-23 19:50:56 +01:00 committed by GitHub
commit 317823a59c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 131 additions and 1 deletions

View File

@ -0,0 +1,43 @@
<template>
<div>
<div class="w-100 d-flex">
<b-form-select
id="freqaiModel-select"
v-model="locFreqaiModel"
:options="botStore.activeBot.freqaiModelList"
>
</b-form-select>
<div class="ms-2">
<b-button @click="botStore.activeBot.getFreqAIModelList">&#x21bb;</b-button>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { useBotStore } from '@/stores/ftbotwrapper';
import { computed, onMounted } from 'vue';
const props = defineProps({
modelValue: { type: String, required: true },
});
const emit = defineEmits(['update:modelValue']);
const botStore = useBotStore();
const locFreqaiModel = computed({
get() {
return props.modelValue;
},
set(freqaiModel: string) {
emit('update:modelValue', freqaiModel);
},
});
onMounted(() => {
if (botStore.activeBot.freqaiModelList.length === 0) {
botStore.activeBot.getFreqAIModelList();
}
});
</script>
<style></style>

View File

@ -41,6 +41,7 @@ import { showAlert } from './alerts';
import { useWebSocket } from '@vueuse/core';
import { FTWsMessage, FtWsMessageTypes } from '@/types/wsMessageTypes';
import { showNotification } from '@/shared/notifications';
import { FreqAIModelListResult } from '../types/types';
export function createBotSubStore(botId: string, botName: string) {
const userService = useUserService(botId);
@ -81,6 +82,7 @@ export function createBotSubStore(botId: string, botName: string) {
historyStatus: LoadingStatus.loading,
strategyPlotConfig: undefined as PlotConfig | undefined,
strategyList: [] as string[],
freqaiModelList: [] as string[],
strategy: {} as StrategyResult,
pairlist: [] as string[],
currentLocks: undefined as LockResponse | undefined,
@ -432,6 +434,16 @@ export function createBotSubStore(botId: string, botName: string) {
return Promise.reject(error);
}
},
async getFreqAIModelList() {
try {
const { data } = await api.get<FreqAIModelListResult>('/freqaimodels');
this.freqaiModelList = data.freqaimodels;
return Promise.resolve(data);
} catch (error) {
console.error(error);
return Promise.reject(error);
}
},
async getAvailablePairs(payload: AvailablePairPayload) {
try {
const { data } = await api.get<AvailablePairResult>('/available_pairs', {

View File

@ -11,6 +11,11 @@ export interface BacktestPayload {
stake_amount?: string;
dry_run_wallet?: number;
enable_protections?: boolean;
backtest_cache?: string;
freqaimodel?: string;
freqai?: {
identifier: string;
};
}
export interface PairResult {

View File

@ -175,6 +175,10 @@ export interface StrategyResult {
code: string;
}
export interface FreqAIModelListResult {
freqaimodels: string[];
}
export interface AvailablePairPayload {
timeframe?: string;
stake_currency?: string;

View File

@ -101,7 +101,7 @@
<span>Strategy</span>
<StrategySelect v-model="strategy"></StrategySelect>
</div>
<b-card bg-variant="light" :disabled="botStore.activeBot.backtestRunning">
<b-card :disabled="botStore.activeBot.backtestRunning">
<!-- Backtesting parameters -->
<b-form-group
label-cols-lg="2"
@ -194,6 +194,54 @@
v-model="enableProtections"
></b-form-checkbox>
</b-form-group>
<b-form-group
v-if="botStore.activeBot.botApiVersion >= 2.22"
label-cols-sm="5"
label="Cache Backtest results:"
label-align-sm="right"
label-for="enable-cache"
>
<b-form-checkbox id="enable-cache" v-model="allowCache"></b-form-checkbox>
</b-form-group>
<template v-if="botStore.activeBot.botApiVersion >= 2.22">
<b-form-group
label-cols-sm="5"
label="Enable FreqAI:"
label-align-sm="right"
label-for="enable-freqai"
>
<template #label>
<div class="d-flex justify-content-center">
<span class="me-2">Enable FreqAI:</span>
<InfoBox
hint="Assumes freqAI configuration is setup in the configuration, and the strategy is a freqAI strategy. Will fail if that's not the case."
/>
</div>
</template>
<b-form-checkbox id="enable-freqai" v-model="freqAI.enabled"></b-form-checkbox>
</b-form-group>
<b-form-group
label-cols-sm="5"
label="FreqAI identifier:"
label-align-sm="right"
label-for="freqai-identifier"
>
<b-form-input
id="freqai-identifier"
v-model="freqAI.identifier"
placeholder="Use config default"
></b-form-input>
</b-form-group>
<b-form-group
v-if="freqAI.enabled"
label-cols-sm="5"
label="FreqAI Model"
label-align-sm="right"
label-for="freqai-model"
>
<FreqaiModelSelect id="freqai-model" v-model="freqAI.model"></FreqaiModelSelect>
</b-form-group>
</template>
<!-- <b-form-group label-cols-sm="5" label="Fee:" label-align-sm="right" label-for="fee">
<b-form-input
@ -277,10 +325,12 @@ import TimeRangeSelect from '@/components/ftbot/TimeRangeSelect.vue';
import BacktestResultView from '@/components/ftbot/BacktestResultView.vue';
import BacktestResultSelect from '@/components/ftbot/BacktestResultSelect.vue';
import StrategySelect from '@/components/ftbot/StrategySelect.vue';
import FreqaiModelSelect from '@/components/ftbot/FreqaiModelSelect.vue';
import TimeframeSelect from '@/components/ftbot/TimeframeSelect.vue';
import BacktestHistoryLoad from '@/components/ftbot/BacktestHistoryLoad.vue';
import BacktestGraphsView from '@/components/ftbot/BacktestGraphsView.vue';
import BacktestResultChart from '@/components/ftbot/BacktestResultChart.vue';
import InfoBox from '@/components/general/InfoBox.vue';
import { BacktestPayload } from '@/types';
@ -308,8 +358,14 @@ const selectedTimeframe = ref('');
const selectedDetailTimeframe = ref('');
const timerange = ref('');
const showLeftBar = ref(false);
const freqAI = ref({
enabled: false,
model: '',
identifier: '',
});
const enableProtections = ref(false);
const stakeAmountUnlimited = ref(false);
const allowCache = ref(true);
const maxOpenTrades = ref('');
const stakeAmount = ref('');
const startingCapital = ref('');
@ -367,6 +423,16 @@ const clickBacktest = () => {
// eslint-disable-next-line @typescript-eslint/camelcase
btPayload.timeframe_detail = selectedDetailTimeframe.value;
}
if (!allowCache.value) {
// eslint-disable-next-line @typescript-eslint/camelcase
btPayload.backtest_cache = 'none';
}
if (freqAI.value.enabled) {
btPayload.freqaimodel = freqAI.value.model;
if (freqAI.value.identifier !== '') {
btPayload.freqai = { identifier: freqAI.value.identifier };
}
}
botStore.activeBot.startBacktest(btPayload);
};