You run that not on single system but on WATCH List consisting of two symbols, namely A and B.
Best regards, Tomasz Janeczko amibroker.com ----- Original Message ----- From: "janhausd" <[email protected]> To: <[email protected]> Sent: Friday, January 30, 2009 8:33 PM Subject: [amibroker] Re: PairTrading on Amibroker > Hi Tomasz, > > Thank you for your insight, and I can see from your code how it will > work. My question then for you is how this type of spread strategy > will be back-tested? If I utilize the code you provided and > optimize/run it on symbol A it will just give me all the entries and > exits for symbol A, maximizing for results that will provide the > greatest profit or whatever metric for symbol A, and vice versa for > symbol B. However, the real optimal result of the spread trade is > likely neither the optimal result for A nor that for B because markets > are not wholly efficient. So in this case, how do you optimize for a > pair trading strategy where the goal is to maximize the simultaneous > entry of long A short B for entry and short A long B for exit? I think > foreign() and some synthetic (composite) will still be required, no? > > > --- In [email protected], "Tomasz Janeczko" <gro...@...> wrote: >> >> Hello, >> >> Marcin is solving strictly technical problems. >> So he gave you technical answer, without actually >> taking care if it is philosophically correct way to do things. >> >> Yes if you are using artificial price, they won't work without >> turning bounds checking off, but that's not the preferred way to go. >> Preferred way is not to create illusion (i.e. artificial prices) >> but to reproduce actual trading. >> >> So, instead of creating artificial spread symbols, >> you should just go long (for example) 500 shares of symbol A >> and short 40 shares of symbol B. >> >> And it is very easy to do and was explained on this list MANY times. >> >> YourSystemEntrySignal = .... >> YourSystemExitSignal = .... >> >> if( Name() == "SymbolA" ) >> { >> Buy = YourSystemEntrySignal; >> Sell = YourSystemExitSignal; >> >> SetPositionSize( 500, spsShares ); >> } >> >> if( Name() == "SymbolB" ) >> { >> Short = YourSystemEntrySignal; >> Cover = YourSystemExitSignal; >> >> SetPositionSize( 40, spsShares ); >> } >> >> Note that you are entering LONG trade on A and SHORT trade on B > using same signal. >> >> Best regards, >> Tomasz Janeczko >> amibroker.com >> ----- Original Message ----- >> From: "janhausd" <janh...@...> >> To: <[email protected]> >> Sent: Friday, January 30, 2009 7:18 PM >> Subject: [amibroker] Re: PairTrading on Amibroker >> >> >> > Hi Tomasz, >> > >> > I had sent several emails to Ami support, and this advice was included >> > on one of the responses. Regarding the pairs trading, perhaps I should >> > explain what I am doing a bit better, it's a spread trade, which >> > involves normalizing two instruments based on some formula. What I >> > actually am doing is creating a formula, for example, 5 * SymbolA - >> > 0.4 * SymbolB = spread price. Buy @ this spread price (buy A, sell B) >> > when condition Z is met, sell (sell A, buy B) when condition Y is met. >> > I had thought most ppl trade pairs this way, but perhaps this isn't >> > the case. >> > >> > Like Angelo, I couldn't figure out a good way to represent the >> > entering one symbol and exiting the other in backtesting, so I used >> > foreign() to create the synthetic, and based the buy/sells and >> > buy/sell prices on the synthetic. When I backtest, I found that both >> > of these options are necessary for me otherwise 1. the synthetic price >> > I generate won't work since it may be beyond the bounds of the HL >> > range, and when I get in at some synthetic price, i.e. 300, and if >> > ruinstop isn't disabled, I get stopped out at price 0 or something >> > very small like that, perhaps due to data holes. >> > >> > I had sent an email to support asking for the best way to go about >> > backtesting such a spread strategy, but did not receive any response. >> > If you have any better suggestions, I've eager to hear them! >> > >> > --- In [email protected], "Tomasz Janeczko" <groups@> wrote: >> >> >> >> Hello, >> >> >> >> It's very important to include >> >> > SetOption("priceBoundChecking",False); >> >> > SetOption("DisableRuinStop",True); >> >> >> >> WRONG! >> >> >> >> This should never be used for pairs trading. >> >> If you need that it means that you code is wrong >> >> (you are attempting to set prices outside H-L range which >> >> is huge mistake). >> >> >> >> Pairs trading should always respect normal prices >> >> and you should use Foreign only for calculations >> >> and NEVER for setting actual trade price entry. >> >> >> >> >> >> Best regards, >> >> Tomasz Janeczko >> >> amibroker.com >> >> ----- Original Message ----- >> >> From: "janhausd" <janhaus@> >> >> To: <[email protected]> >> >> Sent: Friday, January 30, 2009 5:11 PM >> >> Subject: [amibroker] Re: PairTrading on Amibroker >> >> >> >> >> >> > I'm looking for the same thing, Angelo, I wish there was more > inbuilt >> >> > support in Ami for pair trading/testing :) The way I'm dealing > with >> >> > it for now is to utilize foreign() calls, which can be agonizingly >> >> > slow for large amounts of data, and test the strategy based on the >> >> > synthetic/pair, where you enter/exit based on the synthetic > price and >> >> > all statistics based on that. Also, It's very important to include >> >> > SetOption("priceBoundChecking",False); >> >> > SetOption("DisableRuinStop",True); >> >> > >> >> > Without disableruinstop, it seems anytime when there's enough > data to >> >> > enter/exit one leg but no data at the same time for the other > security >> >> > you hedge with, the backtester will kick you out of the > position with >> >> > some ridiculous price, and your results will be entirely incorrect. >> >> > Without priceboundchecking, you may not be able to generate the >> >> > synthetic pair value if the pricing is off. It took several > emails to >> >> > Ami support and browsing for posts here for me to figure out > these two >> >> > options were necessary for backtesting my setup, wish I'd known >> >> > earlier :) If you or anybody else has any better ideas, I'm all > up for >> >> > it... >> >> > >> >> > --- In [email protected], "ang_60" <ima_cons@> wrote: >> >> >> >> >> >> --- In [email protected], "janhausd" <janhaus@> wrote: >> >> >> > >> >> >> > Hi Angelo, >> >> >> > >> >> >> > I have in fact just recently contacted Herman regarding this >> > subject, >> >> >> > since running that code on my data resulted in mismatching >> >> >> > correlations, where Correl(A,B) was not equal to Correl(B,A) > due to >> >> >> > the Foreign() function and data holes between A and B. The >> > result is >> >> >> > actually somewhat similar to the the picture herman posted > in that >> >> >> > link, where you see that the correlation between AAPL,ALTR is >> > -0.624, >> >> >> > whereas ALTR,AAPL is 0.421, except when I ran the code, all > of the >> >> >> > pairs mismatched and not just the ones on the outer edge of the >> >> >> > correlation square. Anyway, if you have data without mismatching >> >> >> > times, this shouldn't be a problem :) >> >> >> > >> >> >> >> >> >> >> >> >> Thanks jan, >> >> >> >> >> >> this problem is clear to me now. >> >> >> >> >> >> I'm on my way to build a pair system on amibroker, using as a >> > template >> >> >> the code posted by TJ on this list some time ago. >> >> >> >> >> >> My code is pretty simple and open a position for symbol1, and - >> > at the >> >> >> same time - an opposite position for symbol2. >> >> >> >> >> >> Of course ,in the report this trade is counted as "two" and this >> > makes >> >> >> unuseful of all the statistics based on the total nauber of trades >> >> >> (e.g. percent winners... profit per trade... ). >> >> >> >> >> >> As anyone thought of a way of telling Amibroker that - in this >> >> >> particular case - the 2 trades representing both leg of the pair >> >> >> should be counted as one? >> >> >> >> >> > >> >> > >> >> > >> >> > ------------------------------------ >> >> > >> >> > **** IMPORTANT **** >> >> > This group is for the discussion between users only. >> >> > This is *NOT* technical support channel. >> >> > >> >> > ********************* >> >> > TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail >> > directly to >> >> > SUPPORT {at} amibroker.com >> >> > ********************* >> >> > >> >> > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG: >> >> > http://www.amibroker.com/devlog/ >> >> > >> >> > For other support material please check also: >> >> > http://www.amibroker.com/support.html >> >> > >> >> > ********************************* >> >> > Yahoo! Groups Links >> >> > >> >> > >> >> > >> >> >> > >> > >> > >> > ------------------------------------ >> > >> > **** IMPORTANT **** >> > This group is for the discussion between users only. >> > This is *NOT* technical support channel. >> > >> > ********************* >> > TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail > directly to >> > SUPPORT {at} amibroker.com >> > ********************* >> > >> > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG: >> > http://www.amibroker.com/devlog/ >> > >> > For other support material please check also: >> > http://www.amibroker.com/support.html >> > >> > ********************************* >> > Yahoo! Groups Links >> > >> > >> > >> > > > > ------------------------------------ > > **** IMPORTANT **** > This group is for the discussion between users only. > This is *NOT* technical support channel. > > ********************* > TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to > SUPPORT {at} amibroker.com > ********************* > > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG: > http://www.amibroker.com/devlog/ > > For other support material please check also: > http://www.amibroker.com/support.html > > ********************************* > Yahoo! Groups Links > > >
