Pair trading - exit based on P/L of PAIR rather than individual positions?
Author: icolville@colvillenet.com
Creation Date: 2/20/2010 3:39 AM
profile picture

icolville@colvillenet.com

#1
I'm trying to code a stop loss exit that will exit both sides of the pair if the net loss on the PAIR (not just one of the positions) is above a certain level. I'm stumped. Its easy to exit a single side/positions using the usual functions but I have no idea how sum the profit/loss of both sides of pair and use that as the determinant for exiting the trade. Any suggestions?
profile picture

Eugene

#2
When trading a market neutral strategy, one has 2 "legs" open at the same time: LastPosition (or in other words, Positions[Position.Count-1]) and the penultimate position i.e. Positions[Position.Count-2]. Position properties can be accessed to calculate some combined metric for the pair.
profile picture

ss161

#3
parts of this may be of some use. it's not exactly what you are looking for.
CODE:
Please log in to see this code.

profile picture

alvincho

#4
I want to try to use Wealth-Lab 5 as a pair trading system. I am not sure if it can be done. My plan is to use symbol as pair ("INTL-AMD" as a single instrument) and a provider to combine static and real-time data for these symbols.

Any suggestion?
profile picture

Eugene

#5
Take a look in Strategies and Trading, there's a pair trading strategy uploaded, for example.

I'm not sure what you're after with a single instrument e.g. "INTL-AMD", can you elaborate?
profile picture

ss161

#6
QUOTE:
I am not sure if it can be done.

Not easily, but it is doable in my opinion (assuming that hard-coding two symbols into a strategy is not what you are looking to do). I've experimented with three or four approaches w/ varying success.

one approach would be to create an ascii dataset with the pair-name, the price history, and any other relevant metrics, then whenever a signal is generated, buy/sell the actual individual pair symbols via some sort of encapsulation object (like the one above) in order to easily track the p&l & win/loss rate of the pair. The only real downside to this approach is that i've found ascii datasources to be so slow that i can't use them. Wealth-lab provides a great feature that caches the data into a binary format upon first use, but unfortunately, for data that is constantly changing, you never really get the benefit of the caching. it would be great if we could generate already cached datasets.

a second approach i've used is to create a wl4 binary dataset and remap the open high low close volume fields with the values of the fields i care about. i almost always keep close and open the same (in this case, the close/open of the pair) but will remap the high low and volume to be other fields since i rarely trade off of them.

if you'd like to discuss any further, feel free to contact me as follows: steve at AlgorithmicTradingPartners dot com.
profile picture

vitordantas

#7
Hi, I´ve read the EUGENE pair trading strategy, created my own pair trading script and have some doubts :
1) Is created an instance of the script for every symbol in the selected dataset ??? Any idea how to work around that ?Or else i would Ex. Buy the same pair n times. . .

2) Can i access realtime data through script ???

Thank´s Vitor
profile picture

Eugene

#8
1) If I deciphered it correctly, see WL Wiki FAQ: My code with DataSetSymbols runs incorrectly or can't run on more than a few symbols (scroll to the very end).

2) It's not required, as you can find in this FAQ: Is it necessary to have access to intra-bar tick data to daytrade with Wealth-Lab?, yet possible through the use of DataSeries.PartialValue (QuickRef it for more).



profile picture

vitordantas

#9
Hi Eugene thank´s for the prompt answers. The Question 1 was exactly that. Thank´s alot, solve it .
The second i was interested in symbol BID/Ask so i might introduce some logic to minimize to execute one leg and let part of the other open . . .. And try to minimize slippage.

Thank you one more time !!
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).