bug fix
This commit is contained in:
parent
894b8da72d
commit
fef5dc9410
@ -1431,7 +1431,7 @@ class BacktestingEngine(object):
|
||||
self.writeCtaLog(u'{0}文件不存在'.format(filepath))
|
||||
return ticks
|
||||
dt = None
|
||||
csvReadFile = file(filepath, 'rb')
|
||||
csvReadFile = open(filepath, 'rb')
|
||||
|
||||
reader = csv.DictReader(csvReadFile, delimiter=",")
|
||||
self.writeCtaLog(u'加载{0}'.format(filepath))
|
||||
@ -1624,7 +1624,7 @@ class BacktestingEngine(object):
|
||||
self.writeCtaLog(u'{0}文件不存在'.format(filepath))
|
||||
return ticks
|
||||
dt = None
|
||||
csvReadFile = file(filepath, 'rb')
|
||||
csvReadFile = open(filepath, 'rb')
|
||||
df = pd.read_csv(filepath, encoding='gbk',parse_dates=False)
|
||||
df.columns = ['date', 'time', 'lastPrice', 'lastVolume', 'totalInterest', 'position',
|
||||
'bidPrice1', 'bidVolume1', 'bidPrice2', 'bidVolume2', 'bidPrice3', 'bidVolume3',
|
||||
@ -1965,6 +1965,15 @@ class BacktestingEngine(object):
|
||||
#bar.close = float(row['Close'])
|
||||
#bar.volume = float(row['TotalVolume'])#
|
||||
#barEndTime = datetime.strptime(row['Date']+' ' + row['Time'], '%Y/%m/%d %H:%M:%S')
|
||||
if row.get('open',None) is None:
|
||||
continue
|
||||
if row.get('high', None) is None:
|
||||
continue
|
||||
if row.get('low', None) is None:
|
||||
continue
|
||||
if row.get('close', None) is None:
|
||||
continue
|
||||
|
||||
if len(row['open'])==0 or len(row['high'])==0 or len(row['low'])==0 or len(row['close'])==0:
|
||||
continue
|
||||
# 从ricequant导出的csv文件
|
||||
|
@ -957,6 +957,12 @@ class CtaEngine(object):
|
||||
else:
|
||||
symbols = strategy.vtSymbol.split(';')
|
||||
|
||||
# 数字货币 btc_usdt.OKEX
|
||||
#if strategy.vtSymbol.find('.') != -1:
|
||||
# symbol_pairs = strategy.vtSymbol.split('.')
|
||||
# if len(symbol_pairs)==2:
|
||||
# symbols.append(symbol_pairs[0])
|
||||
|
||||
# 判断是否有Leg1Symbol,Leg2Symbol 两个合约属性
|
||||
if hasattr(strategy, 'Leg1Symbol'):
|
||||
if strategy.Leg1Symbol not in symbols:
|
||||
|
@ -2934,7 +2934,7 @@ class CtaLineBar(object):
|
||||
|
||||
def skd_is_low_golden_cross(self, runtime=False, low_skd=None):
|
||||
"""
|
||||
检查是否低位死叉
|
||||
检查是否低位金叉
|
||||
:return:
|
||||
"""
|
||||
if not self.inputSkd or len(self.lineSK) < self.inputSkdLen2:
|
||||
@ -3695,6 +3695,7 @@ class CtaHourBar(CtaLineBar):
|
||||
# 去除分钟和秒数
|
||||
tick.datetime = datetime.strptime(tick.datetime.strftime('%Y-%m-%d %H:00:00'), '%Y-%m-%d %H:%M:%S')
|
||||
tick.time = tick.datetime.strftime('%H:%M:%S')
|
||||
self.last_minute = tick.datetime.minute
|
||||
self.curTradingDay = tick.tradingDay
|
||||
self.writeCtaLog('{} drawLineBar() new_bar,{} curTradingDay:{},tick.tradingDay:{}'
|
||||
.format(self.name, tick.datetime.strftime("%Y-%m-%d %H:%M:%S"), self.curTradingDay,
|
||||
@ -3707,6 +3708,7 @@ class CtaHourBar(CtaLineBar):
|
||||
self.last_minute = tick.datetime.minute
|
||||
|
||||
if self.is_7x24:
|
||||
# 数字货币,用前后时间间隔
|
||||
if (tick.datetime - lastBar.datetime).total_seconds() >= 3600 * self.barTimeInterval:
|
||||
self.writeCtaLog('{} drawLineBar() new_bar,{} - {} > 3600 * {} '
|
||||
.format(self.name, tick.datetime.strftime("%Y-%m-%d %H:%M:%S"), lastBar.datetime.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
@ -3719,7 +3721,8 @@ class CtaHourBar(CtaLineBar):
|
||||
self.curTradingDay = tick.tradingDay
|
||||
else:
|
||||
self.curTradingDay = tick.date
|
||||
|
||||
else:
|
||||
# 国内期货,用bar累加
|
||||
if self.m1_bars_count > 60 * self.barTimeInterval:
|
||||
self.writeCtaLog('{} drawLineBar() new_bar,{} {} > 60 * {} '
|
||||
.format(self.name, tick.datetime.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
|
@ -260,27 +260,28 @@ class CtaTemplate(object):
|
||||
def writeCtaLog(self, content):
|
||||
"""记录CTA日志"""
|
||||
try:
|
||||
content = self.name + ':' + content
|
||||
self.ctaEngine.writeCtaLog(content, strategy_name=self.name)
|
||||
except Exception as ex:
|
||||
content = self.name + ':' + content
|
||||
|
||||
self.ctaEngine.writeCtaLog(content)
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
def writeCtaError(self, content):
|
||||
"""记录CTA出错日志"""
|
||||
try:
|
||||
content = self.name + ':' + content
|
||||
self.ctaEngine.writeCtaError(content, strategy_name=self.name)
|
||||
except Exception as ex:
|
||||
content = self.name + ':' + content
|
||||
self.ctaEngine.writeCtaError(content)
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
def writeCtaWarning(self, content):
|
||||
"""记录CTA告警日志"""
|
||||
try:
|
||||
content = self.name + ':' + content
|
||||
self.ctaEngine.writeCtaWarning(content, strategy_name=self.name)
|
||||
except Exception as ex:
|
||||
content = self.name + ':' + content
|
||||
self.ctaEngine.writeCtaWarning(content)
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
@ -296,15 +297,15 @@ class CtaTemplate(object):
|
||||
# ----------------------------------------------------------------------
|
||||
def writeCtaCritical(self, content):
|
||||
"""记录CTA系统异常日志"""
|
||||
|
||||
content = self.name + ':' + content
|
||||
if not self.backtesting:
|
||||
try:
|
||||
self.ctaEngine.writeCtaCritical(content,strategy_name=self.name)
|
||||
except Exception as ex:
|
||||
content = self.name + ':' + content
|
||||
|
||||
self.ctaEngine.writeCtaCritical(content)
|
||||
else:
|
||||
content = self.name + ':' + content
|
||||
|
||||
self.ctaEngine.writeCtaError(content)
|
||||
|
||||
def sendSignal(self,direction,price, level):
|
||||
@ -486,11 +487,18 @@ class MatrixTemplate(CtaTemplate):
|
||||
return
|
||||
|
||||
if dt.hour == 10:
|
||||
if dt.minute <= 15 or dt.minute >= 30:
|
||||
if self.shortSymbol not in MARKET_ZJ and 15 <= dt.minute < 30:
|
||||
pass
|
||||
else:
|
||||
self.tradeWindow = True
|
||||
return
|
||||
|
||||
if dt.hour == 11 and dt.minute <= 30:
|
||||
if dt.hour == 11 and dt.minute < 30:
|
||||
self.tradeWindow = True
|
||||
return
|
||||
|
||||
# 中金
|
||||
if self.shortSymbol not in MARKET_ZJ and dt.hour == 13:
|
||||
self.tradeWindow = True
|
||||
return
|
||||
|
||||
@ -499,7 +507,7 @@ class MatrixTemplate(CtaTemplate):
|
||||
return
|
||||
|
||||
if dt.hour == 14:
|
||||
if dt.minute <= 55:
|
||||
if dt.minute <= 59:
|
||||
self.tradeWindow = True
|
||||
return
|
||||
|
||||
@ -514,12 +522,12 @@ class MatrixTemplate(CtaTemplate):
|
||||
|
||||
# 上期 贵金属, 次日凌晨2:30
|
||||
if self.shortSymbol in NIGHT_MARKET_SQ1:
|
||||
if dt.hour == 22 or dt.hour == 23 or dt.hour == 0 or dt.hour == 1:
|
||||
if dt.hour in [22,23,0,1] :
|
||||
self.tradeWindow = True
|
||||
return
|
||||
|
||||
if dt.hour == 2:
|
||||
if dt.minute <= 1: # 收市前29分钟
|
||||
if dt.minute <= 29: # 收市前29分钟
|
||||
self.tradeWindow = True
|
||||
return
|
||||
if dt.minute > 24: # 夜盘平仓
|
||||
@ -529,12 +537,7 @@ class MatrixTemplate(CtaTemplate):
|
||||
|
||||
# 上期 有色金属,黑色金属,沥青 次日01:00
|
||||
if self.shortSymbol in NIGHT_MARKET_SQ2:
|
||||
if dt.hour in [22, 23]:
|
||||
self.tradeWindow = True
|
||||
return
|
||||
|
||||
if dt.hour == 0:
|
||||
if dt.minute <= 31: # 收市前29分钟
|
||||
if dt.hour in [22, 23,0]:
|
||||
self.tradeWindow = True
|
||||
return
|
||||
|
||||
@ -548,7 +551,7 @@ class MatrixTemplate(CtaTemplate):
|
||||
if self.shortSymbol in NIGHT_MARKET_SQ3:
|
||||
|
||||
if dt.hour == 22:
|
||||
if dt.minute <= 31: # 收市前29分钟
|
||||
if dt.minute <= 59: # 收市前29分钟
|
||||
self.tradeWindow = True
|
||||
return
|
||||
|
||||
@ -562,7 +565,7 @@ class MatrixTemplate(CtaTemplate):
|
||||
return
|
||||
|
||||
if dt.hour == 23:
|
||||
if dt.minute <= 1: # 收市前29分钟
|
||||
if dt.minute <= 29: # 收市 23:30分钟
|
||||
self.tradeWindow = True
|
||||
return
|
||||
if dt.minute > 24: # 夜盘平仓
|
||||
|
Loading…
Reference in New Issue
Block a user