Trades do not make sense after adding dollar hedge
Author: cravens
Creation Date: 9/4/2012 4:18 PM
profile picture

cravens

#1
Hi. I have a simple snippet code that simply shorts NLY when the 5 SMA is below the 15 SMA. I tried to add a feature that also buys an equal dollar amount of SPY as a hedge when the NLY trades are made. The orders no longer make any sense after adding the modifications. Can anyone see where i went wrong? The moving averages are intended to operate on NLY not SPY. This code is intended to operate on daily close data.

Thanks in advance for any advice.

Rob


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

Eugene

#2
QUOTE:
The moving averages are intended to operate on NLY not SPY.

The moving averages will operate on the clicked symbol, whatever it was - NLY, SPY or GOOG. If you intended to hardcode the DataSeries to operate on NLY, make sure you wrap the code in a SetContext/RestoreContext block.
profile picture

cravens

#3
I use the code on a symbol as I always have (i.e., the clicked symbol)

My problem is that i never get consistent trades as I did before adding the SPY short. Did I add the second symbol correctly?

I will add the SetContext/RestoreContext block.
Rob
profile picture

Eugene

#4
What does it mean "consistent", what did it mean "no longer make any sense"? Be precise. What you showed above is a slightly modified code of the "Pairs Trading" strategy. How are executing the Strategy (all settings, backtest mode) and how does that inconsistency can be reproduced exactly?
profile picture

cravens

#5
It ended up being a simple setup problem with the portfolio capital.
Thanks
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).