This function returns the correlation value of two IPV series. The series are date synched, to remove holidays or other missing data, so each record compared between the series have the same date. The CorrelationLogSynch function uses the log of the (rate of) change between the elements in the series, whereas the CorrelationLog function uses just the rate of change between the elements in the series. To avoid computing the Log of a negative number, us the "uc" parameter if the back adjusted futures data might go negative.

 

Because these are date synched, these Synch functions only work with auto indexed IPV series.

Syntax:

CorrelationSynch( series1, series2, sampleSize, offset1, offset2, "uc" )

 

Parameter:

Description:

series1

Series element/property value of the first series.

series2

Series element/property value of the second series.

sampleSize

Number of bars over which to measure the correlation coefficient.

offset1

Offset value for the first series.

offset2

Offset value for the second series.

"uc"

Use the unadjusted close as the rate of change divisor, in case the adjusted price goes negative.

 

Example:

'  Run the correlation process once a month

'  Can run every day or bar if desired.
If Month( test.currentDate ) <> lastMonth THEN
 
  '  Reset/Clear previous correlations information
  instrument.ResetCloselyCorrelated
  instrument.ResetLooselyCorrelated
 
  '  Loop through all symbols in the portfolio so
  '  their correlation can be evaluated.
  For index = 1 TO system.totalInstruments STEP 1
 
    '  Load the next instrument
     inst.LoadSymbol( index )
 
    '  Get the correlation between the two instruments
    '  over the last correlationPeriod days
    If instrument.bar > correlationPeriod * SynchCorrelationBuffer AND
        inst.bar > correlationPeriod * SynchCorrelationBuffer THEN
 
        '  Calculate Log value of Synch'd  comparison record
        correlationValue = CorrelationSynch( instrument.close, inst.close, correlationPeriod )
    ELSE
        '  Clear the working variable when conditions don't match
        correlationValue = 0
    ENDIF
 
    '  Determine if the value is closely or loosely
    '  correlated before adding it to correlation matrix
    If correlationValue > closeThreshold THEN
        '  Add Loaded Symbol to Closely Correlated record series
        instrument.AddCloselyCorrelated( inst.symbol )
    ELSE
        '  Add Loaded Symbol to Loosely Correlated record series
        If correlationValue > looseThreshold THEN
          instrument.AddLooselyCorrelated( inst.symbol )
        ENDIF
    ENDIF
  Next '  index
 
  ' Save the month so we know when it changes
  lastMonth = Month( test.currentDate )
ENDIF '  Month( test.currentDate ) <> lastMonth

Returns:

 

 

Links:

Correlation Properties, CorrelationLog, CorrelationSynch, CorrelationLogSynch, MaxSynchBars

See Also:

Mathematical Functions, Series Functions,

 


Edit Time: 9/25/2017 09:09:58 AM


Topic ID#: 232

 

Created with Help & Manual 7 and styled with Premium Pack Version 2.80 © by EC Software