7 changed files with 263 additions and 8 deletions
@ -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> |
Loading…
Reference in new issue