It is possible to see and edit the query syntax that runs these
analog queries by selecting the Show Query in Query
Builder ![]()
button.
The following variables which are listed at the beginning of the query can be modified to customize the Best Match Analog. The variables with ** can be set to more than 1 symbol.
PatternSymbol** = Current Time-Series Symbol
AnalogSymbol** = Historical Time-Series Symbol to match to PatternSymbol for the correlation
PatternDatapoint = Column/Calculation for PatternSymbol
AnalogDatapoint = Column/Calculation for AnalogSymbol
CorrelationTimePeriod** = Number of days for the correlation
PatternStartDate = How far back in Time Series to look for a Pattern Match
PatternEndDate = Last day for Pattern Time Series - construct_date ( 0, 0, 0 ) is current date
CorrelationNeutralDays = Number of days of no correlation before or after
Sometimes it is beneficial to test correlations against multiple instruments. For example you can compare the recent price pattern for the NASDAQ index to the historical prices for Amex, Dow Jones Industrial Average, S&P 500, & Russell 2000. The “PatternSymbol” will be set to NASD and all four of the indices will be listed for the “AnalogSymbol”. You can also edit the correlation time period. So for this query, “CorrelationTimePeriod” and “CorrelationNeutralDays” are set to 50. This will take just the last 50 days of NASDAQ instead of 65 days used in the queries above.
LET
PatternSymbol = NASD
LET
AnalogSymbol = XAX, DJIA, SPX, RUT
LET
ATTR PatternDatapoint = BAR of PatternSymbol
ATTR AnalogDatapoint = BAR of AnalogSymbol
LET
ATTR CorrelationTimePeriod = 50
INITIALIZE
PatternStartDate = construct_date ( 1, 1, 1990 )
AND
PatternEndDate = construct_date ( 0, 0, 0 )
AND
CorrelationNeutralDays = 50 The results show the best analog match for each of the symbols listed.

You can take a closer look at each result by selecting the Options button at the bottom of the Graph window and selecting 1X1 in the Graphs per Page pull-down menu.
Another option for running the Best Match Analog over multiple symbols at once is to set “AnalogSymbol” to a file that has a list of symbols in it. If you had a file saved as list.trade with the following content you can set the variable to the file name as shown below.

LET
PatternSymbol = NASD
LET
AnalogSymbol = FILE "~/user/list.trade"Alternatively, it is possible to set “AnalogSymbol” to a category in the MIM database. This allows you to run the query over all of the children in that category. For example, if you wanted to compare the NASDAQ index to all equities that trade on the NASDAQ exchange you can set the variables like so.
LET
PatternSymbol = NASD
LET
AnalogSymbol = TopRelation:Equities:GlobalInsight:Nasdaq:TickersIf you want to compare NASDAQ 100 index to all the constituents of the NASDAQ 100 then you can set the variables like this.
LET
PatternSymbol = NASD
LET
AnalogSymbol = TopRelation:Equities:UnitedStates:Constituents:Nasdaq:Index_NASD100Up to this point all of the examples have correlated the most recent 50 or 65-day price movement. However, it is possible to modify the Best Match Analog query to use a historical time period instead of the most recent. You might want to do this if you find a good analog match and then wish to continue to watch the analog as time passes. For example, if you found a good correlation for Natural Gas Futures contract on 6/1/2006 and you wanted to check on the progress to see if the trend continued to match, you can run the analog again for that date and see how the price behaved afterwards. The variable “PatternEndDate” is set to construct_date (0, 0, 0) which refers to the last trading day. If you edit this to a historical date, this resets the ending date for the correlation period. In this example you are correlating the 50-day period prior to and including 7/1/2007.
LET
PatternSymbol = NG
LET
AnalogSymbol = NG
LET
ATTR PatternDatapoint = BAR of PatternSymbol
ATTR AnalogDatapoint = BAR of AnalogSymbol
LET
ATTR CorrelationTimePeriod = 50
INITIALIZE
PatternStartDate = construct_date ( 1, 1, 1990 )
AND
PatternEndDate = construct_date ( 7, 1, 2007 )
AND
CorrelationNeutralDays = 50 This allows you to compare the movement after the analog match. This way it is possible to see if the pattern continued to be correlated.

The following variables which are listed at the beginning of the query can be modified to customize the Threshold Analog. Most of the variables in both the Best Match and Threshold Analog queries function the same way. The variables with ** can be set to more than 1 symbol.
PatternSymbol** = Current Time Series Symbol
AnalogSymbol** = Historical Time Series Symbol to match to PatternSymbol for the correlation
PatternDatapoint = Column/Calculation for PatternSymbol
AnalogDatapoint = Column/Calculation for AnalogSymbol
CorrelationTimePeriod** = Number of days for the correlation
CorrelationThreshold ** = Correlation must be greater than this value to show results
PatternStartDate = How far back in Time Series to look for a Pattern Match
PatternEndDate = Last day for Pattern Time Series - construct_date ( 0, 0, 0 ) is current date
CorrelationNeutralDays = Number of days of no correlation before or after
CorrelationTimePeriodView = Number of days to view the correlation results
In addition to the variables that can be modified in the Best Match Analog, is the “CorrelationThreshold”. This allows the user to modify the threshold at which the correlation percentage must exceed. For example if you wish to see only results where there is at least a 95% match, you would set the variable to .94. The setting below would query for any match that was more than 94%.
LET
ATTR CorrelationThreshold = 0.94 The “CorrelationTimePeriodView” variable allows you to show a different amount of time in the graph than the Correlation time period. For instance, if the query is run with a 65-day correlation, the Best Match analog will always show you what happened 65 days before and after the correlation match. However, with the Threshold Analog, you can run a 65-day correlation but have the graph display a longer or shorter time period by editing this field.