Numpy计算胜率和盈亏

转移数据

直接复制交易结果数据到桌面txt文件:胜率计算.txt

计算胜率和盈亏比

path = '/Users/runyi/Desktop/胜率计算.txt'
import numpy as np
from collections import Counter
data = np.loadtxt(path)
#去0
data_1 = data[data != 0]

earn_times = sum(data_1>0)
earn = sum(data_1[data_1>0])

loss_times = sum(data_1<0)
loss = sum(data_1[data_1<0])

total_times = len(data_1)

ratio = round(sum(data_1>0)/total_times,2)
E_L = round(abs((earn/earn_times)/(loss/loss_times)),2)
print('胜率: ',ratio)
print('盈亏比: ',E_L)

调节参考查询

低于50%时 调大止损 调小止盈
高于70%时 调小止损 调大止盈