策略类中在def init 之前定义的list变量和在init中定义的list变量的区别是什么?
在def init 之前定义的list变量:
class stocktestStrategy(CtaTemplate):
"""基于布林通道的交易策略"""
className = 'stocktestStrategy'
author = u'dofish'
actionMark=[]
如果有两个策略使用同一个策略类:
actionMark会应为一个策略改变而同时改变
log:
{'Tora.10':
(u'TickTest1111', 0, '510050', 'startegy in order', 'Tora.10', ['Tora.10', 0])
(u'TickTest1111', 0, '510050', 'startegy in order', 'Tora.10', ['Tora.10', 0])
(0, '601009', 46800L, [], 4, u'TickTest222', ['Tora.10', 0])
(0, '601009', 46800L, ['Tora.10'], 5, u'TickTest1111', ['Tora.10', 0])
(0, '510050', 305900L, [], 4, u'TickTest222', ['Tora.10', 0])
{'Tora.10':
log中
在 init 中定义的变量list:
def __init__(self, ctaEngine, setting):
"""Constructor"""
super(stocktestStrategy, self).__init__(ctaEngine, setting)
self.actionMark = [0,0]
两个同类策略就不会有干扰
log:
{'Tora.30':
(u'TickTest1111', 0, '510050', 'startegy in order', 'Tora.30', ['Tora.30', 0])
(u'TickTest1111', 0, '510050', 'startegy in order', 'Tora.30', ['Tora.30', 0])
no tick data return
(0, '510050', 1725100L, ['Tora.30'], 5, u'TickTest1111', ['Tora.30', 0])
(0, '601009', 13800L, [], 4, u'TickTest222', [0, 0])
(0, '601009', 13800L, ['Tora.30'], 6, u'TickTest1111', ['Tora.30', 0])
而其他类型变量没有发现这种问题,只有list是发现是这样