Why the strategy backtest performance will difference that when you modify the ticker/sid order sequence ?
example like the sequence compare to original sequence:
context.tickers = ['xli','xlk', 'xlb', 'xlp', 'xly', 'xlv','xlf', 'xle', 'xlu']
context.sids = [ sid(19657),sid(19658),
sid(19654), sid(19659),
sid(19662), sid(19661),
sid(19656),sid(19655), sid(19660) ]
I found the context.data.cov() will arrange the ticker by alphabet sequence,
so in following code ,the problem will occur in pimv to match the context.tickers dictionary,
How should we could to avoid the situation ?
pimv = { e:pimv[i,0] for i,e in enumerate(context.tickers) }
the log for print context.data.cov() :
2005-07-05handle_data:39INFOrecalibrating...
2005-07-05PRINT('context.data.cov()=', '\n', xlb xle xlf xli xlk xlp xlu xlv xly
xlb 0.000129 0.000096 0.000055 0.000074 0.000058 0.000041 0.000052 0.000039 0.000064
xle 0.000096 0.000212 0.000038 0.000056 0.000042 0.000026 0.000057 0.000023 0.000045
xlf 0.000055 0.000038 0.000059 0.000048 0.000045 0.000031 0.000041 0.000032 0.000047
xli 0.000074 0.000056 0.000048 0.000065 0.000053 0.000036 0.000042 0.000036 0.000055
xlk 0.000058 0.000042 0.000045 0.000053 0.000073 0.000035 0.000037 0.000034 0.000054
xlp 0.000041 0.000026 0.000031 0.000036 0.000035 0.000034 0.000026 0.000029 0.000037
xlu 0.000052 0.000057 0.000041 0.000042 0.000037 0.000026 0.000065 0.000023 0.000036
xlv 0.000039 0.000023 0.000032 0.000036 0.000034 0.000029 0.000023 0.000046 0.000034
xly 0.000064 0.000045 0.000047 0.000055 0.000054 0.000037 0.000036 0.000034 0.000062)
UPDATE: I had try add sorted function, not sure this is right or not!
pimv = { e:pimv[i,0] for i,e in enumerate(sorted(context.tickers)) }