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

Re: BOLLINGER



PureBytes Links

Trading Reference Links

At 11:35 PM -0400 5/25/99, Clint Chastain wrote:

>Speaking of correlation, I seem to recall having heard that the corelation
>function/indicator included with TS4 in inaccurate or wrong.
>
>Is this correct? If yes, has got a proper working version?

The Correlation code included TS4 is not the normal Pearson Correlation
coefficient. It may be good for something but if so, I have not discovered
what.

Attached is an old post from another list of several years back that
includes code for the Pearson Correlation code written by Bob Brickey of
Scientific Approaches.

Bob Fulks

--------


To: SciLink Mail List <SciLink@xxxxxxxxxx>
Subject: Pearson Correlation Code for TradeStation
Date: Wed, 18 Dec 96 00:10:59 -0500
From: Scientific Approaches <sci@xxxxxxxxxx>

I have written a simple TradeStation function that calculates the Pearson r
Coefficient of Correlation.  At least I think it does.  I just wrote it a
few minutes ago and haven't tested it carefully.  Use it at your own risk.

I also wrote a simple correlation indicator to plot correlation values
returned by the function.  You are free to do anything with either you want,
so long as I get lots of credit if they help you and none of the blame if
they don't.

They are not designed to show the relative lead or lag between markets, like
the charts on Blackboard 1.  Instead the indicator plots the real-time
Coefficient of Correlation between markets displayed as Data 1 and Data 2.
Indicator inputs are provided to change those assignments if you want.  A
length (Len) input also is provided to set the number of chart bars
overwhich correlation is determined.  Reference lines are plotted at 1, 0
and -1, which, of course, represent perfect correlation, no correlation, and
perfect negative correlation.  I set the correlation plot to red and the
reference lines to light gray on my test charts.  You can set them to any
colors you like.

I posted a couple of examples on Blackboard 2.  Figure 1 shows the recent
correlation between TBond futures and S&P 500 futures.  Figure 2 shows the
recent correlation between soybean futures and soybean oil futures.   The
length argument was set to 30 trading days in both cases, so the plots show
Coefficients of Correlation for the preceding 30 trading days, or about six
weeks (rather than for a year or ten years as shown on Blackboard 1).  You
may want to use longer or shorter calculation periods, depending upon the
time interval overwhich you are interested in knowing the correlation.

Neither the function nor indicator can be used with tick charts, but they
will work with any chart bar duration (the bar duration in data 1 and data 2
must be the same).

I customarily put my initials at the beginning of the names of TradeStation
functions, indicators and systems I write, so they group together in
listings and so I can know immediately whether I wrote them or not.  I
didn't bother to rename these.  You are free to give them any names you like
.

I have put a TradeStation Version 4 transfer file named PCC.ELA in the
/scilink/software/ directory of the ftp site.  I also have pasted the source
code below for the benefit of those who prefer to transfer via the Windows
clipboard.  That is the method I prefer, because I don't trust TradeStation
to not overwrite existing code following a bad experience long ago.

-------------

{ rpbPearson Function
  Calculates Pearson's Correlation Coefficient r.
  Created 12/17/96
}
Inputs: V1(NumericSeries), V2(NumericSeries), Len(Numeric); Vars: V1m(0),
V2m(0), n(0), S1(0), S2(0);

   V1m = Average(V1, Len);
   V2m = Average(V2, Len);

   S1 = 0;

   For n = 0 to Len - 1 begin
      S1 = S1 + (V1[n] - V1m) * (V2[n] - V2m);
   End;

   S2 = (Len * StdDev(V1, Len) * StdDev(V2, Len));

   if S2 = 0 then begin
      rpbPearson = 0;
      end
   else begin
      rpbPearson = S1 / S2;
   end;

-------------

{ rpbPearson Indicator
  Plots Pearson's Correlation Coefficient r.
  Created 12/17/96
}
Inputs: V1(Close of Data1), V2(Close of Data2), Len(30);

Plot1(rpbPearson(V1, V2, Len), "CC");
Plot2(1, "1");
Plot3(0, "0");
Plot4(-1, "-1");

-------------

The indicator can be used for many things other than just determining
correlation between markets.  Have you ever wondered about the correlation
between market price changes one day and the next, or correlations between
opening gaps and daily change, or between various indicators, or between
other such things?  Have you wondered if those correlations are the same in
all markets?  Here is a tool that can be used to explore many things with a
little imagination.

You may want change the plot reference lines for some applications.  If you
are comparing two things that correlate very closely, the correlation will
be near a positive one most of time.  You can change reference line
positions to expand the plot (because of auto-scaling), so small correlation
differences will be visible.

Don't stay up all night playing with it...

  -Bob Brickey
   Scientific Approaches
   sci@xxxxxxxxxx

http://www.markbrown.com