[关闭]
@Channelchan 2018-12-10T15:19:58.000000Z 字数 3775 阅读 58120

实盘与回测复盘校对

下载glogg: 高效的日志管理工具

下载链接: http://glogg.bonnefon.org/download.html
gglog.png-97.7kB

回测中打印关键信息,检查策略回测是否按照对的逻辑执行

print & self.writeLog('%s'%())

  1. 数据数组(将回测数据画出来检查是否有缺失)
  2. 策略信号(打印指标数值)
  3. 止损止盈(出场执行类型)
  4. 加仓减仓(持仓字典检查是否有多空同时持有与异常下单)
  5. 交割单与成交价(检查是否有按照市价成交)

实盘中打印信号与仓位信息,检查实盘是否与回测的下单一致

需要打印关键词方便在日志中进行检索与管理

  1. 数据数组的长度
  2. 指标数值的计算
  3. 信号下单时间点与价位
  4. 止损止盈的滑点大小
  5. 加仓减仓的执行逻辑

实盘信号检测

将实盘日志字符串转为数据并做成表格核对

  1. with open("vt_20181023.log","r",encoding="utf-8") as f:
  2. content = f.readlines()
  3. data = []
  4. for logRow in content:
  5. if logRow.find("CTA_STRATEGY Mas_Strategy:eos_quarter:OKEX_WUon_1min_bar")>=0:
  6. result = logRow.split("CTA_STRATEGY Mas_Strategy:eos_quarter:OKEX_WUon_1min_bar")[-1]
  7. data.append(result)
  1. import pandas as pd
  2. from datetime import datetime
  1. checkDict = {'datetime':[], 'cross':[], 'trend':[], 'wave':[]}
  2. #checkDict = {'datetime':[],'close':[],'cross':[],'trend':[],'wave':[],'n':[]}
  3. for row in data:
  4. dateTime = row[row.find('time')+5:row.find('date')+26]
  5. rigthTime = datetime.strptime(dateTime, "%Y-%m-%d %H:%M:%S")
  6. checkDict['datetime'].append(rigthTime)
  7. #checkBtDict['close'].append(float(row[row.find('close')+6:].split(',')[0]))
  8. checkDict['cross'].append((row[row.find('cross')+6:].split(',')[0]))
  9. checkDict['trend'].append((row[row.find('trend')+6:].split(',')[0]))
  10. checkDict['wave'].append((row[row.find('wave')+5:].split('\n')[0]))
  11. #checkBtDict['n'].append(float(row[row.find("n")+1:].split(':')[-1]))
  1. realCheck = pd.DataFrame(checkDict)
  1. realCheckDf = realCheck.set_index('datetime')
  1. realCheckDf
cross trend wave
datetime
2018-10-23 09:33:00 0 0 0
2018-10-23 09:34:00 0 0 0
2018-10-23 09:35:00 0 0 0
2018-10-23 09:36:00 0 0 0
2018-10-23 09:37:00 0 0 0
2018-10-23 09:38:00 0 0 0
... ... ... ...
2018-10-24 20:48:00 1 1 -1
2018-10-24 20:49:00 1 1 -1
2018-10-24 20:50:00 1 1 -1
2018-10-24 20:51:00 1 1 -1
2018-10-24 20:52:00 1 1 -1
2018-10-24 20:53:00 1 1 -1
2018-10-24 20:54:00 1 1 -1
2018-10-24 20:55:00 1 1 -1
2018-10-24 20:56:00 1 1 -1
2018-10-24 20:57:00 1 1 -1

回测信号检查

将回测日志关键的信号输出与实盘合成表格进行检查

  1. checkBtDict = {'datetime':[],'close':[],'cross':[],'trend':[],'wave':[],'n':[]}
  1. import pandas as pd
  2. btLog = pd.read_csv('BacktestLog.csv')
  3. btData = []
  4. for i, value in btLog.iterrows():
  5. if value.values[0].find("Mas_Strategy:eos_quarter:OKEXon_1min_bar")>=0:
  6. result = value.values[0].split("Mas_Strategy:eos_quarter:OKEXon_1min_bar")[-1]
  7. btData.append(result)
  1. from datetime import datetime
  2. for row in btData:
  3. dateTime = row[row.find('time')+5:25]
  4. rigthTime = datetime.strptime(dateTime, "%Y-%m-%d %H:%M:%S")
  5. checkBtDict['datetime'].append(rigthTime)
  6. checkBtDict['close'].append(float(row[row.find('close')+6:].split(',')[0]))
  7. checkBtDict['cross'].append(float(row[row.find('cross')+6:].split(',')[0]))
  8. checkBtDict['trend'].append(float(row[row.find('trend')+6:].split(',')[0]))
  9. checkBtDict['wave'].append(float(row[row.find("wave")+5:].split(',')[0]))
  10. checkBtDict['n'].append(float(row[row.find("n")+1:].split(':')[-1]))
  1. checkBtData = pd.DataFrame(checkBtDict)
  1. checkBtDd = checkBtData.set_index('datetime')
  1. FinalDf = pd.concat([checkBtDd, realCheckDf], axis=1).dropna()
  1. FinalDf
close cross n trend wave cross trend wave
datetime
2018-10-23 09:33:00 5.439 1.0 0.0 1.0 -1.0 0 0 0
2018-10-23 09:34:00 5.441 1.0 0.0 1.0 -1.0 0 0 0
2018-10-23 09:35:00 5.440 1.0 0.0 1.0 -1.0 0 0 0
2018-10-23 09:36:00 5.439 1.0 0.0 1.0 -1.0 0 0 0
2018-10-23 09:37:00 5.437 1.0 0.0 1.0 -1.0 0 0 0
2018-10-23 09:38:00 5.436 1.0 0.0 1.0 -1.0 0 0 0
2018-10-23 09:39:00 5.436 1.0 0.0 1.0 -1.0 0 0 0
2018-10-23 09:40:00 5.436 1.0 0.0 1.0 -1.0 0 0 0
2018-10-23 09:41:00 5.435 1.0 0.0 1.0 -1.0 0 0 0
2018-10-23 09:42:00 5.432 1.0 0.0 1.0 -1.0 0 0 0
2018-10-23 09:43:00 5.431 1.0 0.0 1.0 -1.0 0 0 0
2018-10-23 09:44:00 5.433 1.0 0.0 1.0 -1.0 0 0 0
... ... ... ... ... ... ... ... ...
2018-10-24 07:30:00 5.414 1.0 0.0 1.0 -1.0 1 1 -1
2018-10-24 07:31:00 5.415 1.0 0.0 1.0 -1.0 1 1 -1
2018-10-24 07:32:00 5.415 1.0 0.0 1.0 -1.0 1 1 -1
2018-10-24 07:33:00 5.415 1.0 0.0 1.0 -1.0 1 1 -1
2018-10-24 07:34:00 5.416 1.0 0.0 1.0 -1.0 1 1 -1
2018-10-24 07:35:00 5.416 1.0 0.0 1.0 -1.0 1 1 -1
2018-10-24 07:36:00 5.415 1.0 0.0 1.0 -1.0 1 1 -1
2018-10-24 07:37:00 5.415 1.0 0.0 1.0 -1.0 1 1 -1
2018-10-24 07:38:00 5.414 1.0 0.0 1.0 -1.0 1 1 -1
2018-10-24 07:39:00 5.414 1.0 0.0 1.0 -1.0 1 1 -1
  1. FinalDf.to_excel('CheckSignal.xlsx')
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注