Browse Source

短线胜率

master
lizhixin 4 years ago
parent
commit
54ab80cddf
  1. 2
      src/assets/sass/black-dashboard/custom/_sidebar-and-main-panel.scss
  2. 4
      src/assets/sass/black-dashboard/custom/_variables.scss
  3. 14
      src/layout/dashboard/DashboardLayout.vue
  4. 2
      src/pages/Account/index.vue
  5. 4
      src/pages/Robot/index.vue
  6. 239
      src/pages/WinRate/index.vue
  7. 6
      src/router/routes.js

2
src/assets/sass/black-dashboard/custom/_sidebar-and-main-panel.scss

@ -18,7 +18,7 @@
}
.sidebar,
.off-canvas-sidebar{
@include linear-gradient($primary-states, $primary);
@include linear-gradient($primary-states, $primary-states);
height: calc(100vh - 90px);
width: 230px;
position: fixed;

4
src/assets/sass/black-dashboard/custom/_variables.scss

@ -111,7 +111,7 @@ $vue: #42b883 !default;
// gradient
$default-states: #263148 !default;
$primary-states: #ba54f5 !default;
$primary-states: #333D54 !default;
$success-states: #0098f0 !default;
$info-states: #3358f4 !default;
$warning-states: #ff6491 !default;
@ -119,7 +119,7 @@ $danger-states: #ec250d !default;
$black-states: #1d253b !default;
$vue-states: #389466 !default;
$background-black: #1e1e2f !default;
$background-black: #2d3548 !default;
$background-states-black: #1e1e24 !default;
// opacity

14
src/layout/dashboard/DashboardLayout.vue

@ -1,6 +1,6 @@
<template>
<div class="wrapper">
<side-bar>
<side-bar :backgroundColor="'#333D54'">
<template slot="links">
<sidebar-link
to="/robot"
@ -12,6 +12,12 @@
:name="'账号管理'"
icon="tim-icons icon-single-02"
/>
<sidebar-link
to="/winRate"
:name="'短线胜率测试'"
icon="tim-icons icon-single-02"
/>
<!-- <sidebar-link to="/icons" :name="$t('sidebar.icons')" icon="tim-icons icon-atom"/>
<sidebar-link to="/maps" :name="$t('sidebar.maps')" icon="tim-icons icon-pin"/>
<sidebar-link to="/notifications" :name="$t('sidebar.notifications')" icon="tim-icons icon-bell-55"/>
@ -52,3 +58,9 @@ export default {
}
};
</script>
<style>
.off-canvas-sidebar {
background: linear-gradient(0deg, #333 0%, #333 100%) !important;
}
</style>

2
src/pages/Account/index.vue

@ -64,7 +64,7 @@
</card>
</modal>
<base-button type="info" @click="modal.visible = true"
<base-button @click="modal.visible = true"
>添加账号</base-button
>

4
src/pages/Robot/index.vue

@ -78,9 +78,7 @@
</card>
</modal>
<base-button type="info" @click="modal.visible = true"
>添加机器人</base-button
>
<base-button @click="modal.visible = true">添加机器人</base-button>
<custom-base-table
:data="tableData"

239
src/pages/WinRate/index.vue

@ -0,0 +1,239 @@
<template>
<card>
<base-button @click="excelImport">导入Excel</base-button>
<span v-if="name" class="ml-4">导入成功{{ name }}</span>
<div class="row">
<div class="col-md-1">
<base-radio name="radio0" class="mb-3" key="radio0" v-model="radio">
固定止盈占比
</base-radio>
</div>
<div class="col-md-3">
<base-input
placeholder="固定止盈占比"
v-model="form.deadProfitRatio"
></base-input>
</div>
</div>
<div class="row">
<div class="col-md-1">
<base-radio name="radio1" class="mb-3" key="radio1" v-model="radio">
盈亏占比
</base-radio>
</div>
<div class="col-md-3">
<base-input
placeholder="盈亏占比"
v-model="form.profitRatio"
></base-input>
</div>
</div>
<base-input
placeholder="滑点比例设置"
label="滑点设置(影响买入价格) 单位:%"
v-model="form.sliderRatio"
></base-input>
<base-button @click="winRateTest">胜率测试</base-button>
<base-input
label="交易次数"
v-model="result.tradeCount"
disabled
></base-input>
<base-input label="交易胜率" v-model="result.winRate" disabled></base-input>
<base-input
label="交易败率"
v-model="result.loseRate"
disabled
></base-input>
</card>
</template>
<script>
import BaseRadio from "../../components/BaseRadio";
import Excel from "../../utils/ExcelUtils";
export default {
components: { BaseRadio },
data() {
return {
radio: "radio0",
name: "",
form: { deadProfitRatio: 0.3, sliderRatio: 0 },
data: [],
result: {}
};
},
methods: {
excelImport() {
let that = this;
Excel.importExcel(data => {
console.log(data);
that.name = data[0].name;
that.data = data[0].data;
});
},
validateForm() {
return new Promise((rs, rj) => {
if (this.radio == "radio0") {
if (!this.form.deadProfitRatio) {
this.sMessage("danger", "未填写固定止盈比");
return;
}
} else {
if (!this.form.profitRatio) {
this.sMessage("danger", "未填写止盈占比");
return;
}
}
if (!this.form.sliderRatio && this.form.sliderRatio != 0) {
this.sMessage("danger", "未填写滑点比例");
return;
}
rs();
});
},
//time open high low close
winRateTest() {
this.validateForm().then(rs => {
let tradeCount = 0;
let win = 0;
let lose = 0;
for (let i = 0; i < this.data.length; i++) {
if (this.isSignal(this.data[i])) {
let { up, low } = this.isSignal(this.data[i]);
if (!up && !low) {
//doing nothing
} else {
tradeCount++;
if (up) {
let buyPrice =
this.data[i][4] * (1 + this.form.sliderRatio / 100); // *
let stopLost = this.data[i][3]; //
let stopWin;
//
if (this.radio == "radio0")
stopWin =
buyPrice * (this.form.deadProfitRatio / 100) + buyPrice;
else
stopWin =
(buyPrice - stopLost) * (this.form.profitRatio / 100) +
buyPrice;
console.log(buyPrice, stopWin, stopLost);
let result = this.reachEnd(
0,
i + 1,
stopWin,
stopLost,
this.data[i][0]
);
if (result == 1) win++;
if (result == -1) lose++;
}
if (low) {
let buyPrice =
this.data[i][4] * (1 - this.form.sliderRatio / 100); // *
let stopLost = this.data[i][2]; //
let stopWin;
//
if (this.radio == "radio0")
stopWin =
buyPrice - buyPrice * (this.form.deadProfitRatio / 100);
else
stopWin =
buyPrice -
(buyPrice - stopLost) * (this.form.profitRatio / 100);
console.log(buyPrice, stopWin, stopLost);
let result = this.reachEnd(
1,
i + 1,
stopWin,
stopLost,
this.data[i][0]
);
if (result == 1) win++;
if (result == -1) lose++;
}
}
}
}
this.result = {
tradeCount,
winRate: ((win / tradeCount) * 100).toFixed(2),
loseRate: ((lose / tradeCount) * 100).toFixed(2)
};
console.log(tradeCount, win);
});
},
//
isSignal(data) {
if (data[5] == 1 || data[6] == 1) {
return { up: data[5] == 1, low: data[6] == 1 };
} else {
return false;
}
},
// type: 0 1
reachEnd(type, index, stopWin, stopLost, timeStamp) {
let result = 0;
if (type == 0) {
console.log(
`=====================================================(${timeStamp})做多信号开始===止盈${stopWin}====止损${stopLost}========================================`
);
//
for (let i = index; i < this.data.length; i++) {
if (this.data[i][2] > stopWin) {
console.log(`---->触发止盈点`, this.data[i]);
result = 1;
break;
} else if (this.data[i][3] < stopLost) {
console.log(`---->触发止损点`, this.data[i]);
result = -1;
break;
} else {
console.log(`->未触发止盈止损点`, this.data[i]);
}
}
} else {
console.log(
`=====================================================(${timeStamp})做空信号开始===止盈${stopWin}====止损${stopLost}========================================`
);
//
for (let i = index; i < this.data.length; i++) {
if (this.data[i][3] < stopWin) {
console.log(`---->触发止盈点`, this.data[i]);
result = 1;
break;
} else if (this.data[i][2] > stopLost) {
console.log(`---->触发止损点`, this.data[i]);
result = -1;
break;
} else {
console.log(`->未触发止盈止损点`, this.data[i]);
}
}
}
console.log(
`=====================================================信号交易结束===止盈${stopWin}====止损${stopLost}========================================`
);
return result;
},
reachFail() {},
// showNotification
sMessage(type, message) {
this.$notify({
type: type,
message,
timeout: 1800
});
}
}
};
</script>
<style></style>

6
src/router/routes.js

@ -13,6 +13,7 @@ import NotFound from "@/pages/NotFoundPage.vue";
const Robot = () => import("@/pages/Robot");
const Account = () => import("@/pages/Account");
const Edit = () => import("@/pages/Robot/edit.vue");
const WinRate = () => import("@/pages/WinRate");
const routes = [
{
@ -30,6 +31,11 @@ const routes = [
name: "edit",
component: Edit
},
{
path: "winRate",
name: "winRate",
component: WinRate
},
{
path: "account",
name: "account",

Loading…
Cancel
Save