[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: PairTrading on Amibroker



PureBytes Links

Trading Reference Links

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 amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@xxx> 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@xxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> 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 amibroker@xxxxxxxxxxxxxxx, "ang_60" <ima_cons@> wrote:
> >>
> >> --- In amibroker@xxxxxxxxxxxxxxx, "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

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/