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

RE: [amibroker] Pair Trading



PureBytes Links

Trading Reference Links

Hi dom,

 

i have found the informatios below in the help. Maybe this is what you search.

 

Regards

 

 

Thomas Zmuck

www.tradingbasis.com

 

 

 

 

 

CORRELATION
- correlation

Statistical functions
(AFL 1.4)

 

SYNTAX

correlation( ARRAY1, ARRAY2, periods )

RETURNS

ARRAY

FUNCTION

Calculates correlation between ARRAY1 and ARRAY2 using periods range

EXAMPLE

correlation( close, ref( close, -5 ), 5 ); - this calculates correlation between close price and and close price 5 days back

SEE ALSO

 

References:

The CORRELATION function is used in the following formulas in AFL on-line library:

 

More information:

Updated on-line reference

 

 

 

Best regards

 

 

 

Thomas Zmuck

 

www.tradingbasis.com

 

 

-----Original Message-----
From: dom1_1998 [mailto:Dom2000@xxxxxxxxxxx]
Sent: Tuesday, February 15, 2005 1:42 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Pair Trading

 

 

 

I copied this post from another site.  I also did a check on Amibroker

.chm on "pair trading" but couldn't find anything close to this method.

I'm not sure if our "Correlation or RSquared" formulas are the same thing.

 

It calculates the correlation of any two stocks, and finds the max

negative correlation, then long one and short another.

 

For example, if one stock A showed price movement of 8%, 10%, 13% and

17% over four period.

 

step 1, calculate the mean of these returns.

  mean(A) = (8+10+13+17)/4 =12

 

step 2, calculate the deviation.

  period 1: 8-12=-4

  p2: 10-12=-2

  p3: 13-12=1

  p4: 17-12=5

 

step 3, square the deviations.

  get 16, 4, 1, 25

 

step 4, sum the squared deviations and divide by (n-1)

  variance(A) = (16+4+1+25)/(4-1)=15.33

 

step 5, take the square root of the variance to calculate standard

deviation.

  standard deviation(A)=sqrt(15.33)=3.92

 

 

Suppose a stock B returns 1%, 2%, 4%, 5% at the same period, with

same procedure, we get the standard deviation(B)=1.83, mean is 3

 

 

Calculate the covariance of stock A and B:

the formular is (Sum(A-MEANa)*(B-MEANb))/(n-1).

i.e. (8-12)*(1-3)+(10-12)*(2-3)+..+..=21

      21/(4-1)=7

 

Finally, the correlation coefficient is 7/(3.92*1.83)=.976

The number ranges from -1 to 1. If stock B's return is 5%,4%,2%,1%

(reversed), the coefficient should be -.976. Choose the two with the

coefficient as near as -1. Long one and short another, but be sure

not to take the wrong direction. :-)

 

dom

 

 

 

 

 

------------------------ Yahoo! Groups Sponsor --------------------~-->

What would our lives be like without music, dance, and theater?

Donate or volunteer in the arts today at Network for Good!

http://us.click.yahoo.com/Tcy2bD/SOnJAA/cosFAA/GHeqlB/TM

--------------------------------------------------------------------~->

 

Check AmiBroker web page at:

http://www.amibroker.com/

 

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html

Yahoo! Groups Links

 

<*> To visit your group on the web, go to:

    http://groups.yahoo.com/group/amibroker/

 

<*> 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/

 

 

 

 



Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html



Yahoo! Groups Sponsor
ADVERTISEMENT


Yahoo! Groups Links