@Channelchan
2018-12-10T15:19:58.000000Z
字数 3775
阅读 58120
下载链接: http://glogg.bonnefon.org/download.html
print & self.writeLog('%s'%())
需要打印关键词方便在日志中进行检索与管理
将实盘日志字符串转为数据并做成表格核对
with open("vt_20181023.log","r",encoding="utf-8") as f:
content = f.readlines()
data = []
for logRow in content:
if logRow.find("CTA_STRATEGY Mas_Strategy:eos_quarter:OKEX_WUon_1min_bar")>=0:
result = logRow.split("CTA_STRATEGY Mas_Strategy:eos_quarter:OKEX_WUon_1min_bar")[-1]
data.append(result)
import pandas as pd
from datetime import datetime
checkDict = {'datetime':[], 'cross':[], 'trend':[], 'wave':[]}
#checkDict = {'datetime':[],'close':[],'cross':[],'trend':[],'wave':[],'n':[]}
for row in data:
dateTime = row[row.find('time')+5:row.find('date')+26]
rigthTime = datetime.strptime(dateTime, "%Y-%m-%d %H:%M:%S")
checkDict['datetime'].append(rigthTime)
#checkBtDict['close'].append(float(row[row.find('close')+6:].split(',')[0]))
checkDict['cross'].append((row[row.find('cross')+6:].split(',')[0]))
checkDict['trend'].append((row[row.find('trend')+6:].split(',')[0]))
checkDict['wave'].append((row[row.find('wave')+5:].split('\n')[0]))
#checkBtDict['n'].append(float(row[row.find("n")+1:].split(':')[-1]))
realCheck = pd.DataFrame(checkDict)
realCheckDf = realCheck.set_index('datetime')
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 |
将回测日志关键的信号输出与实盘合成表格进行检查
checkBtDict = {'datetime':[],'close':[],'cross':[],'trend':[],'wave':[],'n':[]}
import pandas as pd
btLog = pd.read_csv('BacktestLog.csv')
btData = []
for i, value in btLog.iterrows():
if value.values[0].find("Mas_Strategy:eos_quarter:OKEXon_1min_bar")>=0:
result = value.values[0].split("Mas_Strategy:eos_quarter:OKEXon_1min_bar")[-1]
btData.append(result)
from datetime import datetime
for row in btData:
dateTime = row[row.find('time')+5:25]
rigthTime = datetime.strptime(dateTime, "%Y-%m-%d %H:%M:%S")
checkBtDict['datetime'].append(rigthTime)
checkBtDict['close'].append(float(row[row.find('close')+6:].split(',')[0]))
checkBtDict['cross'].append(float(row[row.find('cross')+6:].split(',')[0]))
checkBtDict['trend'].append(float(row[row.find('trend')+6:].split(',')[0]))
checkBtDict['wave'].append(float(row[row.find("wave")+5:].split(',')[0]))
checkBtDict['n'].append(float(row[row.find("n")+1:].split(':')[-1]))
checkBtData = pd.DataFrame(checkBtDict)
checkBtDd = checkBtData.set_index('datetime')
FinalDf = pd.concat([checkBtDd, realCheckDf], axis=1).dropna()
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 |
FinalDf.to_excel('CheckSignal.xlsx')