SetContext / Synchronize in WLP5.0
Author: jaltucher
Creation Date: 8/9/2008 4:53 PM
profile picture

jaltucher

#1
I think there might be a small bug (although I'm happy to be wrong)

CODE:
Please log in to see this code.


works fine when you click on individual symbols.

However, in a simulation, if the simulation starts before some of the symbols then SPY will not get synchonized properly for each symbol.

Example: lets say SOHU triggers its first trade on 9/1/2000 for 10 bars. And then I try to pair it against SPY using SetContext("SPY", true). If the simulation starts on 6/1/1997 then thats when the SPY trade will trigger for 10 bars in the simulation. (but its fine if I just click on SOHU by itself).
profile picture

Eugene

#2
QUOTE:
If the simulation starts on 6/1/1997 then thats when the SPY trade will trigger for 10 bars in the simulation.


Maybe I don't understand the problem here, if SOHU's first trading date was just in July'2000 and SPY has much more history?
profile picture

jaltucher

#3
I'm trading the SOHU / SPY pair.

I use SetContext("SPY", true) to trade the pair when I click on SOHU. It works fine except when I'm in a simulation. Then the synchronize does not work. For instance, if the first trade for SOHU is on 9/1/2000 for 10 bars (lets, say, going long), the code will go short SPY at 9/1/2000 for 10 bars. However, in simulation mode, it will go short SPY at 6/1/1997 because the syncronize is not working.
profile picture

Cone

#4
When you say "simulation mode", do you mean:

1. Multi-symbol backtest (MSB)? i.e., when you select the DataSet before clicking "Go", or,
2. Portfolio Simulation mode? i.e., as opposed to Raw Profit mode

Let's make sure we're using the same terminology, because things have changed a little in Version 5. Can you please post a sample script to make sure we're seeing the same thing? tia.
profile picture

jaltucher

#5
I'm using the MSB. I select the DataSet and click "Go".

here's the code snippet:

CODE:
Please log in to see this code.


the problem does not occur if I just click on an individual stock. Then SPY and the stock in question will trade on the same dates. but when doing an MSB, they do not trade on the same dates if the symbol, for instance, IPOed after the start date.
profile picture

Cone

#6
I can't duplicate what you're describing. I created a DataSet with one symbol only: SOHU. If I run the following script with "All Data", I get only trades for SOHU and SPY on 10/30/2000 regardless if I run it in MSB or one-symbol mode.
CODE:
Please log in to see this code.

Note - keep in mind that MSB in Version 5 works differently than a Version 4 $imulation. In Version 5, MSB will process all symbols in the DataSet even if creating trades on non-primary symbols. A Version 4 $imulation kicks you out of the simulation after the executing the first symbol for such a script.





profile picture

jaltucher

#7
Try doing the simulation with a dataset that includes not only SOHU but other stocks that were around in 1997. I think the problem is when the simulation starts before a stock (in this case SOHU).
profile picture

Cone

#8
Under those circumstances I would expect trades in SPY based on the other symbols due to the difference between Versions 4 and 5 that I just described. In Version 4, the $imulator would run only on the first symbol in the WatchList and exit, whereas Version 5's MSB mode would run the pairs logic on every symbol (in which case you'll need some good Position.Priority logic to make sure that the pairs trades stay together when cash is limited.)

Try this modification of the script above so that you can see which pair SPY is trading with. (Check the Signal name in for SPY trade.)
CODE:
Please log in to see this code.

profile picture

jaltucher

#9
Yes, i did that. Whats happening is that a SPY trade is triggered corresponding to the SOHU trade but on the wrong date. The SPY series is not getting synchronized to the SOHU series in the simulation. So if the SOHU trade is happening on SOHU's 5th bar, then the SPY trade (that corresponds to the SOHU trade) is happening on the simulation's 5th bar. This doesn't happen when I just click on SOHU (it works correctly) or if I start the simulation to correspond to a date that happens within SOHU's series.
profile picture

jaltucher

#10
I just took your code. Ran a simulation going back ten years on the dataset: SOHU WMT AAPL XOM. The SPY trade that corresponds with SOHU occured on 12/8/1998 (I clicked on Dataset and "Backtest on all symbols.."). All the other trades occured on 6/1/2000. When I just click on SOHU the trade occurs on 10/30/2000 which I guess is when SOHU went public.
profile picture

Cone

#11
Hi James,
I can't put my finger on the precise change, but something must have changed to fix this in 5.1 because I'm not seeing what you're seeing. Come back to this next week after 5.1 is released and let me know if you still see the problem.
profile picture

mikhmv

#12
I have question about setcontext to Cone or Eugene.
In version wl5.0 it is work terrible.
Could you like to check how it is work in WL5.1.
I run strategy on dataset with 10 stocks for testing how it is work. My strategy use different timeframes and I am using QQQQ series.
I changed symbol by SetContext.
in 7 from 10 stocks Bars after command "SetScaleDaily" or "RestoreScale" Bars was return to original stock (selected when i run strategy). It is mean if you will not make additional checks you will trade by same symbol in 7 from 10 cases.
Same things for GetExternalSymbol("QQQQ", true);

Could you like to check it in WL5.1.


profile picture

Cone

#13
The "Remark" for RestoreScale in the QuickRef incorrectly says that, "RestoreContext restores the data scale, but preserves the current context symbol..." when in reality it should say, "RestoreScale restores the data scale, but preserves the current context symbol...."

Assuming you knew that, I could not duplicate your findings with 5.1. For 30 out of 30 symbols, RestoreScale did not switch Bars back to the original stock. Run this -

CODE:
Please log in to see this code.

My results:
AA>>QQQQ>>QQQQ
AIG>>QQQQ>>QQQQ
AXP>>QQQQ>>QQQQ
BA>>QQQQ>>QQQQ
C>>QQQQ>>QQQQ
CAT>>QQQQ>>QQQQ
DD>>QQQQ>>QQQQ
DIS>>QQQQ>>QQQQ
GE>>QQQQ>>QQQQ
GM>>QQQQ>>QQQQ
HD>>QQQQ>>QQQQ
HON>>QQQQ>>QQQQ
HPQ>>QQQQ>>QQQQ
IBM>>QQQQ>>QQQQ
INTC>>QQQQ>>QQQQ
JNJ>>QQQQ>>QQQQ
JPM>>QQQQ>>QQQQ
KO>>QQQQ>>QQQQ
MCD>>QQQQ>>QQQQ
MMM>>QQQQ>>QQQQ
MO>>QQQQ>>QQQQ
MRK>>QQQQ>>QQQQ
MSFT>>QQQQ>>QQQQ
PFE>>QQQQ>>QQQQ
PG>>QQQQ>>QQQQ
T>>QQQQ>>QQQQ
UTX>>QQQQ>>QQQQ
VZ>>QQQQ>>QQQQ
WMT>>QQQQ>>QQQQ
XOM>>QQQQ>>QQQQ
profile picture

mikhmv

#14
Hi Cone,
I will extract code which give errors from strategy tomorrow and will place it here.
Hopefully WL5.1 will not have this errors.
profile picture

mikhmv

#15
Hi Cone,
Try this:
CODE:
Please log in to see this code.

result:
ABK
ABK>>>ABK>>>ABK>>>ABK>>>ABK
AMD>>>AMD>>>AMD>>>ABK>>>ABK
BKUNA>>>BKUNA>>>BKUNA>>>ABK>>>ABK
CROX>>>CROX>>>CROX>>>ABK>>>ABK
FSLR>>>FSLR>>>FSLR>>>ABK>>>ABK
PVA>>>PVA>>>PVA>>>ABK>>>ABK
RHD>>>R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
BKUNA>>>BKUNA>>>BKUNA>>>TSL>>>TSL
CROX>>>CROX>>>CROX>>>TSL>>>TSL
FSLR>>>FSLR>>>FSLR>>>TSL>>>TSL
PVA>>>PVA>>>PVA>>>TSL>>>TSL
RHD>>>RHD>>>RHD>>>TSL>>>TSL
TMA>>>TMA>>>TMA>>>TSL>>>TSL
TSL>>>TSL>>>TSL>>>TSL>>>TSL
profile picture

Cone

#16
Not necessary to try it. You're using GetExternalSymbol after having used SetContext. Although the documentation implies that you'll get an implicit RestoreContext (The Bars object will be returned in the same data scale as the Bars object that the Strategy is currently operating on.), I guess we'll have to make it clearer. Anyway, now you know that:

1. GetExternalSymbol always synch's to the original Bars, and,
2. after calling GetExternalSymbol, you need to SetContext again (if required)

CODE:
Please log in to see this code.
profile picture

mikhmv

#17
Cone thanks, I will try this.
I tried you short test with SetScaleDaily and RestoreScale. It work without error.
but in my strategy it sometimes changed symbol. probably it is depend from something additional.
I use MySetScaleDaily method for changing scale.
CODE:
Please log in to see this code.


I have one more question about size of object which can be placed in GOP (Global object pool). I tried to place QQQQ in minute scale for last 2 years. Something like 192000 bars when i extract it again it was 189000 bars. Can you check it in WL5.1?
profile picture

Eugene

#18
QUOTE:
I tried to place QQQQ in minute scale for last 2 years. Something like 192000 bars when i extract it again it was 189000 bars. Can you check it in WL5.1?

My output is identic on 400K+ 1-minute bars:
CODE:
Please log in to see this code.
QUOTE:
423638
423638
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).