Logo

MovingINFORATIO

Updated 2024-03-14 15:04:09.907000

Syntax

SELECT [westclintech].[wct].[MovingINFORATIO](
  <@R, float,>
 ,<@Rb, float,>
 ,<@Scale, float,>
 ,<@Prices, bit,>
 ,<@Offset, int,>
 ,<@RowNum, int,>
 ,<@Id, tinyint,>
 ,<@Exact, bit,>)

Description

Use the scalar function MovingINFORATIO to calculate the information ratio from column values in an ordered resultant table without the need for a self-join. The information ratio is calculated for each value from the first value in the window to the last value in the window. If the column values are presented to the function out of order, an error message will be generated.

The information ratio is calculated as the mean difference of the returns and a benchmark return divided by the standard deviation of the differences multiplied by the square root of a scaling factor. For daily returns the scale factor might be 252; for weekly returns 52; for monthly returns 12. The standard deviation is the sample standard deviation.

\operatorname{INFORATIO}=\frac{\bar{R}-\bar{R_b}}{\sigma_{R-R_b}}\ast\sqrt{scale}

Arguments

@Id

a unique identifier for the MovingINFORATIO calculation. @Id allows you to specify multiple information ratios within a resultant table. @Id is an expression of type tinyint or of a type that can be implicitly converted to tinyint.

@Offset

specifies the window size. @Offset is an expression of type int or of a type that can be implicitly converted to int.

@Prices

a bit value identifying whether the supplied @R and @Rb values are prices (or portfolio values) or returns. If @Prices is true, then the returns are calculated. @Prices is an expression of type bit or of a type that can be implicitly converted to bit.

@R

the return or price value; if return values are being supplied, it should the percentage return in floating point format (i.e. 10% = 0.1). @R is an expression of type float or of a type that can be implicitly converted to float.

@Exact

a bit value which tells the function whether or not to return a NULL value if the number of rows in the window is smaller the @Offset value. If @Exact is 'True' and the number of rows in the window is less the @Offset then a NULL is returned. @Exact is an expression of type bit or of a type that can be implicitly converted to bit.

@Scale

the scaling factor used in the calculation. @Scale is an expression of type float or of a type that can be implicitly converted to float.

@Rb

the benchmark return or price; if a benchmark return is being supplied, is should be the percentage in floating point format (i.e. 10% = 0.1). @Rb is an expression of type float or of a type that can be implicitly converted to float.

@RowNum

the number of the row within the group for which the information ratio is being calculated. If @RowNum for the current row in a set is less than or equal to the previous @RowNum and @RowNum is not equal to 1, an error message will be generated. @RowNum is an expression of type int or of a type that can be implicitly converted to int.

Return Type

float

Remarks

If @Scale IS NULL then @Scale is set to 12.

If @Prices IS NULL then @Prices is set to 'False'.

Examples

In this example we have 60 months’ worth of return data for and we want to calculate the information ratio with a window size of 36 rows.

SELECT cast(eom as date) as eom,

       CAST(r as float) as r,

       CAST(rb as float) as rb

INTO #s

FROM

(

    VALUES

        ('2013-12-31', 0.006141, 0.000721),

        ('2013-11-30', 0.004506, 0.000794),

        ('2013-10-31', -0.011454, 0.00082),

        ('2013-09-30', -0.001549, 0.000774),

        ('2013-08-31', 0.00568, 0.000869),

        ('2013-07-31', 0.000241, 0.00087),

        ('2013-06-30', 0.00648, 0.000845),

        ('2013-05-31', 0.005113, 0.000796),

        ('2013-04-30', 0.002461, 0.000832),

        ('2013-03-31', -0.012148, 0.00087),

        ('2013-02-28', -0.005735, 0.000826),

        ('2013-01-31', 0.007749, 0.000806),

        ('2012-12-31', -0.001317, 0.000815),

        ('2012-11-30', -0.000728, 0.000845),

        ('2012-10-31', 0.009667, 0.000775),

        ('2012-09-30', 0.017884, 0.000859),

        ('2012-08-31', 0.011488, 0.000833),

        ('2012-07-31', -0.001725, 0.000813),

        ('2012-06-30', 0.001178, 0.000792),

        ('2012-05-31', -0.000403, 0.00076),

        ('2012-04-30', 0.004734, 0.000849),

        ('2012-03-31', 0.018142, 0.000753),

        ('2012-02-29', 0.0099, 0.000788),

        ('2012-01-31', 0.012923, 0.000801),

        ('2011-12-31', 0.01715, 0.000793),

        ('2011-11-30', -0.005677, 0.000783),

        ('2011-10-31', 0.004575, 0.000764),

        ('2011-09-30', 0.005032, 0.000821),

        ('2011-08-31', 0.015355, 0.000762),

        ('2011-07-31', 0.002744, 0.000737),

        ('2011-06-30', 0.004112, 0.000794),

        ('2011-05-31', 0.007087, 0.000833),

        ('2011-04-30', 0.001757, 0.000818),

        ('2011-03-31', 0.002962, 0.000778),

        ('2011-02-28', 0.001222, 0.000782),

        ('2011-01-31', 0.008292, 0.00078),

        ('2010-12-31', 0.007464, 0.000738),

        ('2010-11-30', 0.009659, 0.00084),

        ('2010-10-31', 0.007148, 0.000693),

        ('2010-09-30', 0.015428, 0.000777),

        ('2010-08-31', 0.006701, 0.000799),

        ('2010-07-31', 0.013108, 0.000785),

        ('2010-06-30', 0.003393, 0.000856),

        ('2010-05-31', 0.009797, 0.000731),

        ('2010-04-30', 0.01416, 0.000718),

        ('2010-03-31', 0.004966, 0.000854),

        ('2010-02-28', -0.001553, 0.000752),

        ('2010-01-31', 0.01009, 0.000804),

        ('2009-12-31', 0.006488, 0.000721),

        ('2009-11-30', 0.001107, 0.00092),

        ('2009-10-31', 0.009641, 0.000774),

        ('2009-09-30', 0.001297, 0.000846),

        ('2009-08-31', 0.001314, 0.000767),

        ('2009-07-31', 0.008622, 0.000815),

        ('2009-06-30', 0.015167, 0.000721),

        ('2009-05-31', -0.002137, 0.0008),

        ('2009-04-30', 0.016035, 0.000798),

        ('2009-03-31', 0.018067, 0.00077),

        ('2009-02-28', 0.013449, 0.000823),

        ('2009-01-31', -0.000029, 0.000852)

) n (eom, r, rb);

SELECT eom,

       r,

       rb,

       wct.MovingINFORATIO(   r,                                    --@R

                              rb,                                   --@Rf

                              12,                                   --@Scale

                              'False',                              --@Prices

                              36,                                   --@Offset

                              ROW_NUMBER() OVER (ORDER BY eom ASC), --@RowNum

                              NULL,                                 --@Id

                              'True'                                --@Exact

                          ) as INFO

FROM #s;

DROP TABLE #s;

This produces the following result.

{"columns":[{"field":"eom","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"r","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"rb","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"INFO"}],"rows":[{"eom":"2009-01-31","r":"-2.9E-05","rb":"0.000852","INFO":"NULL"},{"eom":"2009-02-28","r":"0.013449","rb":"0.000823","INFO":"NULL"},{"eom":"2009-03-31","r":"0.018067","rb":"0.00077","INFO":"NULL"},{"eom":"2009-04-30","r":"0.016035","rb":"0.000798","INFO":"NULL"},{"eom":"2009-05-31","r":"-0.002137","rb":"0.0008","INFO":"NULL"},{"eom":"2009-06-30","r":"0.015167","rb":"0.000721","INFO":"NULL"},{"eom":"2009-07-31","r":"0.008622","rb":"0.000815","INFO":"NULL"},{"eom":"2009-08-31","r":"0.001314","rb":"0.000767","INFO":"NULL"},{"eom":"2009-09-30","r":"0.001297","rb":"0.000846","INFO":"NULL"},{"eom":"2009-10-31","r":"0.009641","rb":"0.000774","INFO":"NULL"},{"eom":"2009-11-30","r":"0.001107","rb":"0.00092","INFO":"NULL"},{"eom":"2009-12-31","r":"0.006488","rb":"0.000721","INFO":"NULL"},{"eom":"2010-01-31","r":"0.01009","rb":"0.000804","INFO":"NULL"},{"eom":"2010-02-28","r":"-0.001553","rb":"0.000752","INFO":"NULL"},{"eom":"2010-03-31","r":"0.004966","rb":"0.000854","INFO":"NULL"},{"eom":"2010-04-30","r":"0.01416","rb":"0.000718","INFO":"NULL"},{"eom":"2010-05-31","r":"0.009797","rb":"0.000731","INFO":"NULL"},{"eom":"2010-06-30","r":"0.003393","rb":"0.000856","INFO":"NULL"},{"eom":"2010-07-31","r":"0.013108","rb":"0.000785","INFO":"NULL"},{"eom":"2010-08-31","r":"0.006701","rb":"0.000799","INFO":"NULL"},{"eom":"2010-09-30","r":"0.015428","rb":"0.000777","INFO":"NULL"},{"eom":"2010-10-31","r":"0.007148","rb":"0.000693","INFO":"NULL"},{"eom":"2010-11-30","r":"0.009659","rb":"0.00084","INFO":"NULL"},{"eom":"2010-12-31","r":"0.007464","rb":"0.000738","INFO":"NULL"},{"eom":"2011-01-31","r":"0.008292","rb":"0.00078","INFO":"NULL"},{"eom":"2011-02-28","r":"0.001222","rb":"0.000782","INFO":"NULL"},{"eom":"2011-03-31","r":"0.002962","rb":"0.000778","INFO":"NULL"},{"eom":"2011-04-30","r":"0.001757","rb":"0.000818","INFO":"NULL"},{"eom":"2011-05-31","r":"0.007087","rb":"0.000833","INFO":"NULL"},{"eom":"2011-06-30","r":"0.004112","rb":"0.000794","INFO":"NULL"},{"eom":"2011-07-31","r":"0.002744","rb":"0.000737","INFO":"NULL"},{"eom":"2011-08-31","r":"0.015355","rb":"0.000762","INFO":"NULL"},{"eom":"2011-09-30","r":"0.005032","rb":"0.000821","INFO":"NULL"},{"eom":"2011-10-31","r":"0.004575","rb":"0.000764","INFO":"NULL"},{"eom":"2011-11-30","r":"-0.005677","rb":"0.000783","INFO":"NULL"},{"eom":"2011-12-31","r":"0.01715","rb":"0.000793","INFO":"3.58503856570884"},{"eom":"2012-01-31","r":"0.012923","rb":"0.000801","INFO":"3.82383934381681"},{"eom":"2012-02-29","r":"0.0099","rb":"0.000788","INFO":"3.81336027480443"},{"eom":"2012-03-31","r":"0.018142","rb":"0.000753","INFO":"3.8117754050257"},{"eom":"2012-04-30","r":"0.004734","rb":"0.000849","INFO":"3.73906105356095"},{"eom":"2012-05-31","r":"-0.000403","rb":"0.00076","INFO":"3.81736208000486"},{"eom":"2012-06-30","r":"0.001178","rb":"0.000792","INFO":"3.64078347149186"},{"eom":"2012-07-31","r":"-0.001725","rb":"0.000813","INFO":"3.36555089288179"},{"eom":"2012-08-31","r":"0.011488","rb":"0.000833","INFO":"3.53859523956385"},{"eom":"2012-09-30","r":"0.017884","rb":"0.000859","INFO":"3.67945590535237"},{"eom":"2012-10-31","r":"0.009667","rb":"0.000775","INFO":"3.67967091074914"},{"eom":"2012-11-30","r":"-0.000728","rb":"0.000845","INFO":"3.61560156829587"},{"eom":"2012-12-31","r":"-0.001317","rb":"0.000815","INFO":"3.39832634900535"},{"eom":"2013-01-31","r":"0.007749","rb":"0.000806","INFO":"3.37419677095366"},{"eom":"2013-02-28","r":"-0.005735","rb":"0.000826","INFO":"3.2028444131869"},{"eom":"2013-03-31","r":"-0.012148","rb":"0.00087","INFO":"2.6387754644457"},{"eom":"2013-04-30","r":"0.002461","rb":"0.000832","INFO":"2.51760823941849"},{"eom":"2013-05-31","r":"0.005113","rb":"0.000796","INFO":"2.46372838791937"},{"eom":"2013-06-30","r":"0.00648","rb":"0.000845","INFO":"2.51076506223729"},{"eom":"2013-07-31","r":"0.000241","rb":"0.00087","INFO":"2.34923346061192"},{"eom":"2013-08-31","r":"0.00568","rb":"0.000869","INFO":"2.33506468325438"},{"eom":"2013-09-30","r":"-0.001549","rb":"0.000774","INFO":"2.13660818458873"},{"eom":"2013-10-31","r":"-0.011454","rb":"0.00082","INFO":"1.73629331839779"},{"eom":"2013-11-30","r":"0.004506","rb":"0.000794","INFO":"1.68126520479592"},{"eom":"2013-12-31","r":"0.006141","rb":"0.000721","INFO":"1.66695161658538"}]}

In this example, we do the same calculation, using price data rather than return data.

SELECT cast(eom as date) as eom
,CAST(pr as money) as pr
,CAST(bmk as money) as bmk
INTO #s
FROM (VALUES
      ('2013-12-31',70.31,104.91),
      ('2013-11-30',69.88,104.83),
      ('2013-10-31',69.56,104.75),
      ('2013-09-30',70.37,104.66),
      ('2013-08-31',70.48,104.58),
      ('2013-07-31',70.08,104.49),
      ('2013-06-30',70.06,104.4),
      ('2013-05-31',69.61,104.31),
      ('2013-04-30',69.26,104.23),
      ('2013-03-31',69.09,104.14),
      ('2013-02-28',69.94,104.05),
      ('2013-01-31',70.34,103.96),
      ('2012-12-31',69.8,103.88),
      ('2012-11-30',69.89,103.8),
      ('2012-10-31',69.94,103.71),
      ('2012-09-30',69.28,103.63),
      ('2012-08-31',68.06,103.54),
      ('2012-07-31',67.28,103.45),
      ('2012-06-30',67.4,103.37),
      ('2012-05-31',67.32,103.29),
      ('2012-04-30',67.35,103.21),
      ('2012-03-31',67.03,103.12),
      ('2012-02-29',65.84,103.04),
      ('2012-01-31',65.19,102.96),
      ('2011-12-31',64.36,102.88),
      ('2011-11-30',63.27,102.8),
      ('2011-10-31',63.64,102.72),
      ('2011-09-30',63.35,102.64),
      ('2011-08-31',63.03,102.55),
      ('2011-07-31',62.08,102.48),
      ('2011-06-30',61.91,102.4),
      ('2011-05-31',61.65,102.32),
      ('2011-04-30',61.22,102.23),
      ('2011-03-31',61.11,102.15),
      ('2011-02-28',60.93,102.07),
      ('2011-01-31',60.86,101.99),
      ('2010-12-31',60.36,101.91),
      ('2010-11-30',59.91,101.84),
      ('2010-10-31',59.34,101.75),
      ('2010-09-30',58.91,101.68),
      ('2010-08-31',58.02,101.6),
      ('2010-07-31',57.63,101.52),
      ('2010-06-30',56.89,101.44),
      ('2010-05-31',56.7,101.36),
      ('2010-04-30',56.15,101.28),
      ('2010-03-31',55.36,101.21),
      ('2010-02-28',55.09,101.12),
      ('2010-01-31',55.17,101.05),
      ('2009-12-31',54.62,100.96),
      ('2009-11-30',54.27,100.89),
      ('2009-10-31',54.21,100.8),
      ('2009-09-30',53.69,100.72),
      ('2009-08-31',53.62,100.64),
      ('2009-07-31',53.55,100.56),
      ('2009-06-30',53.09,100.48),
      ('2009-05-31',52.3,100.4),
      ('2009-04-30',52.41,100.32),
      ('2009-03-31',51.59,100.24),
      ('2009-02-28',50.67,100.17),
      ('2009-01-31',50,100.09),
      ('2008-12-31',50,100)
      )n(eom,pr,bmk);
     
SELECT eom
,pr
,bmk
,wct.MovingInfoRatio(
       pr         --@R
      ,bmk --@Rb
      ,12         --@Scale
      ,'True'     --@Prices
      ,36         --@Offset
      ,ROW_NUMBER() OVER (ORDER BY eom ASC)     --@RowNum
      ,NULL       --@Id
      ,'True'     --@Exact
      ) as INFO
FROM #s;
 
DROP TABLE #s;

This produces the following result.

{"columns":[{"field":"eom","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"pr","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"bmk","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"INFO"}],"rows":[{"eom":"2008-12-31","pr":"50.00","bmk":"100.00","INFO":"NULL"},{"eom":"2009-01-31","pr":"50.00","bmk":"100.09","INFO":"NULL"},{"eom":"2009-02-28","pr":"50.67","bmk":"100.17","INFO":"NULL"},{"eom":"2009-03-31","pr":"51.59","bmk":"100.24","INFO":"NULL"},{"eom":"2009-04-30","pr":"52.41","bmk":"100.32","INFO":"NULL"},{"eom":"2009-05-31","pr":"52.30","bmk":"100.40","INFO":"NULL"},{"eom":"2009-06-30","pr":"53.09","bmk":"100.48","INFO":"NULL"},{"eom":"2009-07-31","pr":"53.55","bmk":"100.56","INFO":"NULL"},{"eom":"2009-08-31","pr":"53.62","bmk":"100.64","INFO":"NULL"},{"eom":"2009-09-30","pr":"53.69","bmk":"100.72","INFO":"NULL"},{"eom":"2009-10-31","pr":"54.21","bmk":"100.80","INFO":"NULL"},{"eom":"2009-11-30","pr":"54.27","bmk":"100.89","INFO":"NULL"},{"eom":"2009-12-31","pr":"54.62","bmk":"100.96","INFO":"NULL"},{"eom":"2010-01-31","pr":"55.17","bmk":"101.05","INFO":"NULL"},{"eom":"2010-02-28","pr":"55.09","bmk":"101.12","INFO":"NULL"},{"eom":"2010-03-31","pr":"55.36","bmk":"101.21","INFO":"NULL"},{"eom":"2010-04-30","pr":"56.15","bmk":"101.28","INFO":"NULL"},{"eom":"2010-05-31","pr":"56.70","bmk":"101.36","INFO":"NULL"},{"eom":"2010-06-30","pr":"56.89","bmk":"101.44","INFO":"NULL"},{"eom":"2010-07-31","pr":"57.63","bmk":"101.52","INFO":"NULL"},{"eom":"2010-08-31","pr":"58.02","bmk":"101.60","INFO":"NULL"},{"eom":"2010-09-30","pr":"58.91","bmk":"101.68","INFO":"NULL"},{"eom":"2010-10-31","pr":"59.34","bmk":"101.75","INFO":"NULL"},{"eom":"2010-11-30","pr":"59.91","bmk":"101.84","INFO":"NULL"},{"eom":"2010-12-31","pr":"60.36","bmk":"101.91","INFO":"NULL"},{"eom":"2011-01-31","pr":"60.86","bmk":"101.99","INFO":"NULL"},{"eom":"2011-02-28","pr":"60.93","bmk":"102.07","INFO":"NULL"},{"eom":"2011-03-31","pr":"61.11","bmk":"102.15","INFO":"NULL"},{"eom":"2011-04-30","pr":"61.22","bmk":"102.23","INFO":"NULL"},{"eom":"2011-05-31","pr":"61.65","bmk":"102.32","INFO":"NULL"},{"eom":"2011-06-30","pr":"61.91","bmk":"102.40","INFO":"NULL"},{"eom":"2011-07-31","pr":"62.08","bmk":"102.48","INFO":"NULL"},{"eom":"2011-08-31","pr":"63.03","bmk":"102.55","INFO":"NULL"},{"eom":"2011-09-30","pr":"63.35","bmk":"102.64","INFO":"NULL"},{"eom":"2011-10-31","pr":"63.64","bmk":"102.72","INFO":"NULL"},{"eom":"2011-11-30","pr":"63.27","bmk":"102.80","INFO":"NULL"},{"eom":"2011-12-31","pr":"64.36","bmk":"102.88","INFO":"3.58676647770117"},{"eom":"2012-01-31","pr":"65.19","bmk":"102.96","INFO":"3.82645525563777"},{"eom":"2012-02-29","pr":"65.84","bmk":"103.04","INFO":"3.81662592575437"},{"eom":"2012-03-31","pr":"67.03","bmk":"103.12","INFO":"3.81942228173519"},{"eom":"2012-04-30","pr":"67.35","bmk":"103.21","INFO":"3.74586731957684"},{"eom":"2012-05-31","pr":"67.32","bmk":"103.29","INFO":"3.82009916798985"},{"eom":"2012-06-30","pr":"67.40","bmk":"103.37","INFO":"3.64300308949477"},{"eom":"2012-07-31","pr":"67.28","bmk":"103.45","INFO":"3.36627840205728"},{"eom":"2012-08-31","pr":"68.06","bmk":"103.54","INFO":"3.54066825327087"},{"eom":"2012-09-30","pr":"69.28","bmk":"103.63","INFO":"3.67913079309479"},{"eom":"2012-10-31","pr":"69.94","bmk":"103.71","INFO":"3.67793484228446"},{"eom":"2012-11-30","pr":"69.89","bmk":"103.80","INFO":"3.61263646816859"},{"eom":"2012-12-31","pr":"69.80","bmk":"103.88","INFO":"3.39845497725758"},{"eom":"2013-01-31","pr":"70.34","bmk":"103.96","INFO":"3.37543427064359"},{"eom":"2013-02-28","pr":"69.94","bmk":"104.05","INFO":"3.19899177463182"},{"eom":"2013-03-31","pr":"69.09","bmk":"104.14","INFO":"2.63763958109604"},{"eom":"2013-04-30","pr":"69.26","bmk":"104.23","INFO":"2.51568680151571"},{"eom":"2013-05-31","pr":"69.61","bmk":"104.31","INFO":"2.46184423321181"},{"eom":"2013-06-30","pr":"70.06","bmk":"104.40","INFO":"2.50798818529081"},{"eom":"2013-07-31","pr":"70.08","bmk":"104.49","INFO":"2.34800967176227"},{"eom":"2013-08-31","pr":"70.48","bmk":"104.58","INFO":"2.33339463359427"},{"eom":"2013-09-30","pr":"70.37","bmk":"104.66","INFO":"2.13498079784971"},{"eom":"2013-10-31","pr":"69.56","bmk":"104.75","INFO":"1.73097464944098"},{"eom":"2013-11-30","pr":"69.88","bmk":"104.83","INFO":"1.67845680576442"},{"eom":"2013-12-31","pr":"70.31","bmk":"104.91","INFO":"1.66280544275062"}]}

In this example we calculate the information ratio for multiple portfolios simultaneously. Notice that we have to use a different value in @Id for each information ratio column in the resultant table.

SELECT CAST(eom as date) as eom,

       CAST(AAA as money) as AAA,

       CAST(BBB as money) as BBB,

       CAST(CCC as money) as CCC,

       CAST(BMK as money) as BMK

INTO #s

FROM

(

    VALUES

        ('2013-12-31', 61.27, 169.65, 97.98, 148.82),

        ('2013-11-30', 61.08, 167.14, 97.7, 148.27),

        ('2013-10-31', 60.88, 165.64, 97.82, 147.47),

        ('2013-09-30', 60.66, 163.21, 97.74, 145.95),

        ('2013-08-31', 60.44, 163.01, 96.64, 143.12),

        ('2013-07-31', 60.25, 165.28, 97.16, 143.6),

        ('2013-06-30', 60.05, 166.37, 96.59, 141.63),

        ('2013-05-31', 59.83, 164.31, 96.67, 141.13),

        ('2013-04-30', 59.6, 164.05, 95.87, 140.78),

        ('2013-03-31', 59.38, 161.58, 95.85, 140.76),

        ('2013-02-28', 59.09, 161.13, 95.94, 140.11),

        ('2013-01-31', 58.9, 159.4, 95.6, 139.16),

        ('2012-12-31', 58.74, 158.12, 94.9, 137.33),

        ('2012-11-30', 58.45, 154.55, 94.15, 136.05),

        ('2012-10-31', 58.26, 155.28, 93.13, 135.79),

        ('2012-09-30', 58.03, 155.16, 91.83, 135.83),

        ('2012-08-31', 57.79, 152.62, 90.8, 135.1),

        ('2012-07-31', 57.63, 151.5, 90.15, 134.01),

        ('2012-06-30', 57.45, 151.46, 89.88, 132.21),

        ('2012-05-31', 57.22, 149.27, 89.41, 131.02),

        ('2012-04-30', 57.07, 147.52, 88.67, 129.33),

        ('2012-03-31', 56.92, 147.29, 88.81, 128.45),

        ('2012-02-29', 56.74, 145.65, 88.25, 127.07),

        ('2012-01-31', 56.46, 142.62, 88.35, 126.12),

        ('2011-12-31', 56.26, 142.36, 88.13, 125.11),

        ('2011-11-30', 56.07, 140.5, 87.64, 123.79),

        ('2011-10-31', 55.87, 139.13, 87.16, 122.94),

        ('2011-09-30', 55.71, 137.5, 86.64, 122.55),

        ('2011-08-31', 55.52, 137.73, 86.79, 121.82),

        ('2011-07-31', 55.34, 135.45, 85.37, 120.17),

        ('2011-06-30', 55.19, 135.27, 85.04, 119.14),

        ('2011-05-31', 55.02, 133.4, 83.79, 118.73),

        ('2011-04-30', 54.84, 133.32, 83.87, 117.49),

        ('2011-03-31', 54.65, 131.37, 83.9, 117.93),

        ('2011-02-28', 54.4, 129.37, 83.65, 116.67),

        ('2011-01-31', 54.28, 128.24, 83.88, 116.53),

        ('2010-12-31', 54.1, 127, 82.83, 115.78),

        ('2010-11-30', 53.93, 125.76, 82.58, 114.58),

        ('2010-10-31', 53.8, 125.95, 82.12, 113.8),

        ('2010-09-30', 53.62, 124.8, 81.19, 113.23),

        ('2010-08-31', 53.38, 121.84, 80.42, 112.69),

        ('2010-07-31', 53.21, 120.64, 80.39, 110.27),

        ('2010-06-30', 53.06, 119.69, 79.47, 109.11),

        ('2010-05-31', 52.91, 121.53, 79.18, 108.52),

        ('2010-04-30', 52.74, 120.49, 78.54, 106.97),

        ('2010-03-31', 52.59, 118.04, 77.17, 106.3),

        ('2010-02-28', 52.45, 115.21, 77.06, 105.28),

        ('2010-01-31', 52.23, 114.18, 76.85, 105.39),

        ('2009-12-31', 52.09, 112.7, 76.73, 105.73),

        ('2009-11-30', 51.91, 110.84, 76.68, 105.42),

        ('2009-10-31', 51.66, 110.09, 76.97, 104.83),

        ('2009-09-30', 51.53, 108.19, 76.67, 104.5),

        ('2009-08-31', 51.4, 107.4, 77.14, 104.42),

        ('2009-07-31', 51.22, 106.72, 76.85, 103.98),

        ('2009-06-30', 51.05, 105.57, 76.62, 102.58),

        ('2009-05-31', 50.88, 105.55, 76.22, 102.99),

        ('2009-04-30', 50.77, 103.41, 75.83, 101.56),

        ('2009-03-31', 50.65, 103.5, 75.88, 101),

        ('2009-02-28', 50.44, 102.87, 76, 101.24),

        ('2009-01-31', 50.34, 101.01, 75.29, 102.25),

        ('2008-12-31', 50.17, 99.92, 75.45, 101.21)

) n (eom, AAA, BBB, CCC, BMK);

SELECT eom,

       wct.MovingINFORATIO(AAA, BMK, 12, 'True', 36, ROW_NUMBER() OVER (ORDER BY 

                 EOM ASC), 1, 'TRUE') as AAA,

       wct.MovingINFORATIO(BBB, BMK, 12, 'True', 36, ROW_NUMBER() OVER (ORDER BY 

                 EOM ASC), 2, 'TRUE') as BBB,

       wct.MovingINFORATIO(CCC, BMK, 12, 'True', 36, ROW_NUMBER() OVER (ORDER BY 

                 EOM ASC), 3, 'TRUE') as CCC

FROM #s;

DROP TABLE #s;

This produces the following result.

{"columns":[{"field":"eom","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"AAA"},{"field":"BBB"},{"field":"CCC"}],"rows":[{"eom":"2008-12-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2009-01-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2009-02-28","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2009-03-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2009-04-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2009-05-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2009-06-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2009-07-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2009-08-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2009-09-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2009-10-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2009-11-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2009-12-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2010-01-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2010-02-28","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2010-03-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2010-04-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2010-05-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2010-06-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2010-07-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2010-08-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2010-09-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2010-10-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2010-11-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2010-12-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2011-01-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2011-02-28","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2011-03-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2011-04-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2011-05-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2011-06-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2011-07-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2011-08-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2011-09-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2011-10-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2011-11-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"eom":"2011-12-31","AAA":"-1.50264335385127","BBB":"1.36339934163092","CCC":"-0.680484554124345"},{"eom":"2012-01-31","AAA":"-1.47405028124021","BBB":"1.28172706095312","CCC":"-0.613067733094883"},{"eom":"2012-02-29","AAA":"-1.84676037014358","BBB":"1.23307512240945","CCC":"-1.0556643740288"},{"eom":"2012-03-31","AAA":"-2.15641678352096","BBB":"1.15476509186243","CCC":"-1.12857934562344"},{"eom":"2012-04-30","AAA":"-2.1739413324635","BBB":"1.16992728545154","CCC":"-1.15148862718521"},{"eom":"2012-05-31","AAA":"-2.17128210170209","BBB":"1.0894336069323","CCC":"-1.10663872200846"},{"eom":"2012-06-30","AAA":"-2.5317422089487","BBB":"1.10289847320593","CCC":"-1.33589225180152"},{"eom":"2012-07-31","AAA":"-2.53188351427334","BBB":"0.96073332708266","CCC":"-1.33562547382318"},{"eom":"2012-08-31","AAA":"-2.62837551419835","BBB":"0.930951955594759","CCC":"-1.34294940890139"},{"eom":"2012-09-30","AAA":"-2.72145792313755","BBB":"0.968198232770012","CCC":"-1.14410892844854"},{"eom":"2012-10-31","AAA":"-2.55195013877502","BBB":"0.85615565913842","CCC":"-0.885800768444971"},{"eom":"2012-11-30","AAA":"-2.49044158602105","BBB":"0.76997655662585","CCC":"-0.63863952256145"},{"eom":"2012-12-31","AAA":"-2.6058963440003","BBB":"0.768909077101311","CCC":"-0.627978199910875"},{"eom":"2013-01-31","AAA":"-3.00315246759007","BBB":"0.571397151287231","CCC":"-0.76868217990417"},{"eom":"2013-02-28","AAA":"-3.35044041416273","BBB":"0.516290645810907","CCC":"-0.86526391043653"},{"eom":"2013-03-31","AAA":"-3.17148170381401","BBB":"0.357226587544548","CCC":"-0.836517628192648"},{"eom":"2013-04-30","AAA":"-2.92585906326791","BBB":"0.363271637643036","CCC":"-1.03293876400083"},{"eom":"2013-05-31","AAA":"-2.71821547287965","BBB":"0.417827941047359","CCC":"-0.856405284557855"},{"eom":"2013-06-30","AAA":"-2.64361364266275","BBB":"0.787047673692989","CCC":"-0.889764187487621"},{"eom":"2013-07-31","AAA":"-2.6529046127412","BBB":"0.537841694271647","CCC":"-1.0024183141239"},{"eom":"2013-08-31","AAA":"-2.35020101018412","BBB":"0.558355847746184","CCC":"-0.836435734282757"},{"eom":"2013-09-30","AAA":"-2.44660010597957","BBB":"0.159096275100095","CCC":"-1.03422090678605"},{"eom":"2013-10-31","AAA":"-2.53463230735959","BBB":"0.162088282377083","CCC":"-1.28325469416878"},{"eom":"2013-11-30","AAA":"-2.48913598084977","BBB":"0.290293376295917","CCC":"-1.35717062783412"},{"eom":"2013-12-31","AAA":"-2.37004988731189","BBB":"0.408487055655326","CCC":"-1.26791636115069"}]}

In this example, we have the same data as in the previous example, except that it is stored in 3rd normal form rather than in the de-normalized form. The benchmark is included in the table with using the symbol BMK. We use the PARTITION clause in order to generate the correct row number within a symbol.

SELECT CAST(eom as date) as eom,

       sym,

       CAST(pr as float) as pr

INTO #s

FROM

(

    VALUES

        ('2013-12-31', 'AAA', 61.27),

        ('2013-11-30', 'AAA', 61.08),

        ('2013-10-31', 'AAA', 60.88),

        ('2013-09-30', 'AAA', 60.66),

        ('2013-08-31', 'AAA', 60.44),

        ('2013-07-31', 'AAA', 60.25),

        ('2013-06-30', 'AAA', 60.05),

        ('2013-05-31', 'AAA', 59.83),

        ('2013-04-30', 'AAA', 59.6),

        ('2013-03-31', 'AAA', 59.38),

        ('2013-02-28', 'AAA', 59.09),

        ('2013-01-31', 'AAA', 58.9),

        ('2012-12-31', 'AAA', 58.74),

        ('2012-11-30', 'AAA', 58.45),

        ('2012-10-31', 'AAA', 58.26),

        ('2012-09-30', 'AAA', 58.03),

        ('2012-08-31', 'AAA', 57.79),

        ('2012-07-31', 'AAA', 57.63),

        ('2012-06-30', 'AAA', 57.45),

        ('2012-05-31', 'AAA', 57.22),

        ('2012-04-30', 'AAA', 57.07),

        ('2012-03-31', 'AAA', 56.92),

        ('2012-02-29', 'AAA', 56.74),

        ('2012-01-31', 'AAA', 56.46),

        ('2011-12-31', 'AAA', 56.26),

        ('2011-11-30', 'AAA', 56.07),

        ('2011-10-31', 'AAA', 55.87),

        ('2011-09-30', 'AAA', 55.71),

        ('2011-08-31', 'AAA', 55.52),

        ('2011-07-31', 'AAA', 55.34),

        ('2011-06-30', 'AAA', 55.19),

        ('2011-05-31', 'AAA', 55.02),

        ('2011-04-30', 'AAA', 54.84),

        ('2011-03-31', 'AAA', 54.65),

        ('2011-02-28', 'AAA', 54.4),

        ('2011-01-31', 'AAA', 54.28),

        ('2010-12-31', 'AAA', 54.1),

        ('2010-11-30', 'AAA', 53.93),

        ('2010-10-31', 'AAA', 53.8),

        ('2010-09-30', 'AAA', 53.62),

        ('2010-08-31', 'AAA', 53.38),

        ('2010-07-31', 'AAA', 53.21),

        ('2010-06-30', 'AAA', 53.06),

        ('2010-05-31', 'AAA', 52.91),

        ('2010-04-30', 'AAA', 52.74),

        ('2010-03-31', 'AAA', 52.59),

        ('2010-02-28', 'AAA', 52.45),

        ('2010-01-31', 'AAA', 52.23),

        ('2009-12-31', 'AAA', 52.09),

        ('2009-11-30', 'AAA', 51.91),

        ('2009-10-31', 'AAA', 51.66),

        ('2009-09-30', 'AAA', 51.53),

        ('2009-08-31', 'AAA', 51.4),

        ('2009-07-31', 'AAA', 51.22),

        ('2009-06-30', 'AAA', 51.05),

        ('2009-05-31', 'AAA', 50.88),

        ('2009-04-30', 'AAA', 50.77),

        ('2009-03-31', 'AAA', 50.65),

        ('2009-02-28', 'AAA', 50.44),

        ('2009-01-31', 'AAA', 50.34),

        ('2008-12-31', 'AAA', 50.17),

        ('2013-12-31', 'BBB', 169.65),

        ('2013-11-30', 'BBB', 167.14),

        ('2013-10-31', 'BBB', 165.64),

        ('2013-09-30', 'BBB', 163.21),

        ('2013-08-31', 'BBB', 163.01),

        ('2013-07-31', 'BBB', 165.28),

        ('2013-06-30', 'BBB', 166.37),

        ('2013-05-31', 'BBB', 164.31),

        ('2013-04-30', 'BBB', 164.05),

        ('2013-03-31', 'BBB', 161.58),

        ('2013-02-28', 'BBB', 161.13),

        ('2013-01-31', 'BBB', 159.4),

        ('2012-12-31', 'BBB', 158.12),

        ('2012-11-30', 'BBB', 154.55),

        ('2012-10-31', 'BBB', 155.28),

        ('2012-09-30', 'BBB', 155.16),

        ('2012-08-31', 'BBB', 152.62),

        ('2012-07-31', 'BBB', 151.5),

        ('2012-06-30', 'BBB', 151.46),

        ('2012-05-31', 'BBB', 149.27),

        ('2012-04-30', 'BBB', 147.52),

        ('2012-03-31', 'BBB', 147.29),

        ('2012-02-29', 'BBB', 145.65),

        ('2012-01-31', 'BBB', 142.62),

        ('2011-12-31', 'BBB', 142.36),

        ('2011-11-30', 'BBB', 140.5),

        ('2011-10-31', 'BBB', 139.13),

        ('2011-09-30', 'BBB', 137.5),

        ('2011-08-31', 'BBB', 137.73),

        ('2011-07-31', 'BBB', 135.45),

        ('2011-06-30', 'BBB', 135.27),

        ('2011-05-31', 'BBB', 133.4),

        ('2011-04-30', 'BBB', 133.32),

        ('2011-03-31', 'BBB', 131.37),

        ('2011-02-28', 'BBB', 129.37),

        ('2011-01-31', 'BBB', 128.24),

        ('2010-12-31', 'BBB', 127),

        ('2010-11-30', 'BBB', 125.76),

        ('2010-10-31', 'BBB', 125.95),

        ('2010-09-30', 'BBB', 124.8),

        ('2010-08-31', 'BBB', 121.84),

        ('2010-07-31', 'BBB', 120.64),

        ('2010-06-30', 'BBB', 119.69),

        ('2010-05-31', 'BBB', 121.53),

        ('2010-04-30', 'BBB', 120.49),

        ('2010-03-31', 'BBB', 118.04),

        ('2010-02-28', 'BBB', 115.21),

        ('2010-01-31', 'BBB', 114.18),

        ('2009-12-31', 'BBB', 112.7),

        ('2009-11-30', 'BBB', 110.84),

        ('2009-10-31', 'BBB', 110.09),

        ('2009-09-30', 'BBB', 108.19),

        ('2009-08-31', 'BBB', 107.4),

        ('2009-07-31', 'BBB', 106.72),

        ('2009-06-30', 'BBB', 105.57),

        ('2009-05-31', 'BBB', 105.55),

        ('2009-04-30', 'BBB', 103.41),

        ('2009-03-31', 'BBB', 103.5),

        ('2009-02-28', 'BBB', 102.87),

        ('2009-01-31', 'BBB', 101.01),

        ('2008-12-31', 'BBB', 99.92),

        ('2013-12-31', 'CCC', 97.98),

        ('2013-11-30', 'CCC', 97.7),

        ('2013-10-31', 'CCC', 97.82),

        ('2013-09-30', 'CCC', 97.74),

        ('2013-08-31', 'CCC', 96.64),

        ('2013-07-31', 'CCC', 97.16),

        ('2013-06-30', 'CCC', 96.59),

        ('2013-05-31', 'CCC', 96.67),

        ('2013-04-30', 'CCC', 95.87),

        ('2013-03-31', 'CCC', 95.85),

        ('2013-02-28', 'CCC', 95.94),

        ('2013-01-31', 'CCC', 95.6),

        ('2012-12-31', 'CCC', 94.9),

        ('2012-11-30', 'CCC', 94.15),

        ('2012-10-31', 'CCC', 93.13),

        ('2012-09-30', 'CCC', 91.83),

        ('2012-08-31', 'CCC', 90.8),

        ('2012-07-31', 'CCC', 90.15),

        ('2012-06-30', 'CCC', 89.88),

        ('2012-05-31', 'CCC', 89.41),

        ('2012-04-30', 'CCC', 88.67),

        ('2012-03-31', 'CCC', 88.81),

        ('2012-02-29', 'CCC', 88.25),

        ('2012-01-31', 'CCC', 88.35),

        ('2011-12-31', 'CCC', 88.13),

        ('2011-11-30', 'CCC', 87.64),

        ('2011-10-31', 'CCC', 87.16),

        ('2011-09-30', 'CCC', 86.64),

        ('2011-08-31', 'CCC', 86.79),

        ('2011-07-31', 'CCC', 85.37),

        ('2011-06-30', 'CCC', 85.04),

        ('2011-05-31', 'CCC', 83.79),

        ('2011-04-30', 'CCC', 83.87),

        ('2011-03-31', 'CCC', 83.9),

        ('2011-02-28', 'CCC', 83.65),

        ('2011-01-31', 'CCC', 83.88),

        ('2010-12-31', 'CCC', 82.83),

        ('2010-11-30', 'CCC', 82.58),

        ('2010-10-31', 'CCC', 82.12),

        ('2010-09-30', 'CCC', 81.19),

        ('2010-08-31', 'CCC', 80.42),

        ('2010-07-31', 'CCC', 80.39),

        ('2010-06-30', 'CCC', 79.47),

        ('2010-05-31', 'CCC', 79.18),

        ('2010-04-30', 'CCC', 78.54),

        ('2010-03-31', 'CCC', 77.17),

        ('2010-02-28', 'CCC', 77.06),

        ('2010-01-31', 'CCC', 76.85),

        ('2009-12-31', 'CCC', 76.73),

        ('2009-11-30', 'CCC', 76.68),

        ('2009-10-31', 'CCC', 76.97),

        ('2009-09-30', 'CCC', 76.67),

        ('2009-08-31', 'CCC', 77.14),

        ('2009-07-31', 'CCC', 76.85),

        ('2009-06-30', 'CCC', 76.62),

        ('2009-05-31', 'CCC', 76.22),

        ('2009-04-30', 'CCC', 75.83),

        ('2009-03-31', 'CCC', 75.88),

        ('2009-02-28', 'CCC', 76),

        ('2009-01-31', 'CCC', 75.29),

        ('2008-12-31', 'CCC', 75.45),

        ('2013-12-31', 'BMK', 148.82),

        ('2013-11-30', 'BMK', 148.27),

        ('2013-10-31', 'BMK', 147.47),

        ('2013-09-30', 'BMK', 145.95),

        ('2013-08-31', 'BMK', 143.12),

        ('2013-07-31', 'BMK', 143.6),

        ('2013-06-30', 'BMK', 141.63),

        ('2013-05-31', 'BMK', 141.13),

        ('2013-04-30', 'BMK', 140.78),

        ('2013-03-31', 'BMK', 140.76),

        ('2013-02-28', 'BMK', 140.11),

        ('2013-01-31', 'BMK', 139.16),

        ('2012-12-31', 'BMK', 137.33),

        ('2012-11-30', 'BMK', 136.05),

        ('2012-10-31', 'BMK', 135.79),

        ('2012-09-30', 'BMK', 135.83),

        ('2012-08-31', 'BMK', 135.1),

        ('2012-07-31', 'BMK', 134.01),

        ('2012-06-30', 'BMK', 132.21),

        ('2012-05-31', 'BMK', 131.02),

        ('2012-04-30', 'BMK', 129.33),

        ('2012-03-31', 'BMK', 128.45),

        ('2012-02-29', 'BMK', 127.07),

        ('2012-01-31', 'BMK', 126.12),

        ('2011-12-31', 'BMK', 125.11),

        ('2011-11-30', 'BMK', 123.79),

        ('2011-10-31', 'BMK', 122.94),

        ('2011-09-30', 'BMK', 122.55),

        ('2011-08-31', 'BMK', 121.82),

        ('2011-07-31', 'BMK', 120.17),

        ('2011-06-30', 'BMK', 119.14),

        ('2011-05-31', 'BMK', 118.73),

        ('2011-04-30', 'BMK', 117.49),

        ('2011-03-31', 'BMK', 117.93),

        ('2011-02-28', 'BMK', 116.67),

        ('2011-01-31', 'BMK', 116.53),

        ('2010-12-31', 'BMK', 115.78),

        ('2010-11-30', 'BMK', 114.58),

        ('2010-10-31', 'BMK', 113.8),

        ('2010-09-30', 'BMK', 113.23),

        ('2010-08-31', 'BMK', 112.69),

        ('2010-07-31', 'BMK', 110.27),

        ('2010-06-30', 'BMK', 109.11),

        ('2010-05-31', 'BMK', 108.52),

        ('2010-04-30', 'BMK', 106.97),

        ('2010-03-31', 'BMK', 106.3),

        ('2010-02-28', 'BMK', 105.28),

        ('2010-01-31', 'BMK', 105.39),

        ('2009-12-31', 'BMK', 105.73),

        ('2009-11-30', 'BMK', 105.42),

        ('2009-10-31', 'BMK', 104.83),

        ('2009-09-30', 'BMK', 104.5),

        ('2009-08-31', 'BMK', 104.42),

        ('2009-07-31', 'BMK', 103.98),

        ('2009-06-30', 'BMK', 102.58),

        ('2009-05-31', 'BMK', 102.99),

        ('2009-04-30', 'BMK', 101.56),

        ('2009-03-31', 'BMK', 101),

        ('2009-02-28', 'BMK', 101.24),

        ('2009-01-31', 'BMK', 102.25),

        ('2008-12-31', 'BMK', 101.21)

) n (eom, sym, pr);

SELECT s1.EOM,

       s1.sym,

       wct.MovingINFORATIO(

                              s1.pr,

                              s2.pr,

                              12,

                              'True',

                              36,

                              ROW_NUMBER() OVER (PARTITION BY s1.SYM ORDER BY 

                                        s1.sym, s1.eom ASC),

                              1,

                              'True'

                          ) as INFO

FROM #s s1

    JOIN #s s2

        ON s1.eom = s2.eom

WHERE s1.sym <> 'BMK'

      AND s2.sym = 'BMK';

This produces the following result.

{"columns":[{"field":"EOM","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"sym"},{"field":"INFO"}],"rows":[{"EOM":"2008-12-31","sym":"AAA","INFO":"NULL"},{"EOM":"2009-01-31","sym":"AAA","INFO":"NULL"},{"EOM":"2009-02-28","sym":"AAA","INFO":"NULL"},{"EOM":"2009-03-31","sym":"AAA","INFO":"NULL"},{"EOM":"2009-04-30","sym":"AAA","INFO":"NULL"},{"EOM":"2009-05-31","sym":"AAA","INFO":"NULL"},{"EOM":"2009-06-30","sym":"AAA","INFO":"NULL"},{"EOM":"2009-07-31","sym":"AAA","INFO":"NULL"},{"EOM":"2009-08-31","sym":"AAA","INFO":"NULL"},{"EOM":"2009-09-30","sym":"AAA","INFO":"NULL"},{"EOM":"2009-10-31","sym":"AAA","INFO":"NULL"},{"EOM":"2009-11-30","sym":"AAA","INFO":"NULL"},{"EOM":"2009-12-31","sym":"AAA","INFO":"NULL"},{"EOM":"2010-01-31","sym":"AAA","INFO":"NULL"},{"EOM":"2010-02-28","sym":"AAA","INFO":"NULL"},{"EOM":"2010-03-31","sym":"AAA","INFO":"NULL"},{"EOM":"2010-04-30","sym":"AAA","INFO":"NULL"},{"EOM":"2010-05-31","sym":"AAA","INFO":"NULL"},{"EOM":"2010-06-30","sym":"AAA","INFO":"NULL"},{"EOM":"2010-07-31","sym":"AAA","INFO":"NULL"},{"EOM":"2010-08-31","sym":"AAA","INFO":"NULL"},{"EOM":"2010-09-30","sym":"AAA","INFO":"NULL"},{"EOM":"2010-10-31","sym":"AAA","INFO":"NULL"},{"EOM":"2010-11-30","sym":"AAA","INFO":"NULL"},{"EOM":"2010-12-31","sym":"AAA","INFO":"NULL"},{"EOM":"2011-01-31","sym":"AAA","INFO":"NULL"},{"EOM":"2011-02-28","sym":"AAA","INFO":"NULL"},{"EOM":"2011-03-31","sym":"AAA","INFO":"NULL"},{"EOM":"2011-04-30","sym":"AAA","INFO":"NULL"},{"EOM":"2011-05-31","sym":"AAA","INFO":"NULL"},{"EOM":"2011-06-30","sym":"AAA","INFO":"NULL"},{"EOM":"2011-07-31","sym":"AAA","INFO":"NULL"},{"EOM":"2011-08-31","sym":"AAA","INFO":"NULL"},{"EOM":"2011-09-30","sym":"AAA","INFO":"NULL"},{"EOM":"2011-10-31","sym":"AAA","INFO":"NULL"},{"EOM":"2011-11-30","sym":"AAA","INFO":"NULL"},{"EOM":"2011-12-31","sym":"AAA","INFO":"-1.50264335385127"},{"EOM":"2012-01-31","sym":"AAA","INFO":"-1.47405028124021"},{"EOM":"2012-02-29","sym":"AAA","INFO":"-1.84676037014358"},{"EOM":"2012-03-31","sym":"AAA","INFO":"-2.15641678352096"},{"EOM":"2012-04-30","sym":"AAA","INFO":"-2.1739413324635"},{"EOM":"2012-05-31","sym":"AAA","INFO":"-2.17128210170209"},{"EOM":"2012-06-30","sym":"AAA","INFO":"-2.5317422089487"},{"EOM":"2012-07-31","sym":"AAA","INFO":"-2.53188351427334"},{"EOM":"2012-08-31","sym":"AAA","INFO":"-2.62837551419835"},{"EOM":"2012-09-30","sym":"AAA","INFO":"-2.72145792313755"},{"EOM":"2012-10-31","sym":"AAA","INFO":"-2.55195013877502"},{"EOM":"2012-11-30","sym":"AAA","INFO":"-2.49044158602105"},{"EOM":"2012-12-31","sym":"AAA","INFO":"-2.6058963440003"},{"EOM":"2013-01-31","sym":"AAA","INFO":"-3.00315246759007"},{"EOM":"2013-02-28","sym":"AAA","INFO":"-3.35044041416273"},{"EOM":"2013-03-31","sym":"AAA","INFO":"-3.17148170381401"},{"EOM":"2013-04-30","sym":"AAA","INFO":"-2.92585906326791"},{"EOM":"2013-05-31","sym":"AAA","INFO":"-2.71821547287965"},{"EOM":"2013-06-30","sym":"AAA","INFO":"-2.64361364266275"},{"EOM":"2013-07-31","sym":"AAA","INFO":"-2.6529046127412"},{"EOM":"2013-08-31","sym":"AAA","INFO":"-2.35020101018412"},{"EOM":"2013-09-30","sym":"AAA","INFO":"-2.44660010597957"},{"EOM":"2013-10-31","sym":"AAA","INFO":"-2.53463230735959"},{"EOM":"2013-11-30","sym":"AAA","INFO":"-2.48913598084977"},{"EOM":"2013-12-31","sym":"AAA","INFO":"-2.37004988731189"},{"EOM":"2008-12-31","sym":"BBB","INFO":"NULL"},{"EOM":"2009-01-31","sym":"BBB","INFO":"NULL"},{"EOM":"2009-02-28","sym":"BBB","INFO":"NULL"},{"EOM":"2009-03-31","sym":"BBB","INFO":"NULL"},{"EOM":"2009-04-30","sym":"BBB","INFO":"NULL"},{"EOM":"2009-05-31","sym":"BBB","INFO":"NULL"},{"EOM":"2009-06-30","sym":"BBB","INFO":"NULL"},{"EOM":"2009-07-31","sym":"BBB","INFO":"NULL"},{"EOM":"2009-08-31","sym":"BBB","INFO":"NULL"},{"EOM":"2009-09-30","sym":"BBB","INFO":"NULL"},{"EOM":"2009-10-31","sym":"BBB","INFO":"NULL"},{"EOM":"2009-11-30","sym":"BBB","INFO":"NULL"},{"EOM":"2009-12-31","sym":"BBB","INFO":"NULL"},{"EOM":"2010-01-31","sym":"BBB","INFO":"NULL"},{"EOM":"2010-02-28","sym":"BBB","INFO":"NULL"},{"EOM":"2010-03-31","sym":"BBB","INFO":"NULL"},{"EOM":"2010-04-30","sym":"BBB","INFO":"NULL"},{"EOM":"2010-05-31","sym":"BBB","INFO":"NULL"},{"EOM":"2010-06-30","sym":"BBB","INFO":"NULL"},{"EOM":"2010-07-31","sym":"BBB","INFO":"NULL"},{"EOM":"2010-08-31","sym":"BBB","INFO":"NULL"},{"EOM":"2010-09-30","sym":"BBB","INFO":"NULL"},{"EOM":"2010-10-31","sym":"BBB","INFO":"NULL"},{"EOM":"2010-11-30","sym":"BBB","INFO":"NULL"},{"EOM":"2010-12-31","sym":"BBB","INFO":"NULL"},{"EOM":"2011-01-31","sym":"BBB","INFO":"NULL"},{"EOM":"2011-02-28","sym":"BBB","INFO":"NULL"},{"EOM":"2011-03-31","sym":"BBB","INFO":"NULL"},{"EOM":"2011-04-30","sym":"BBB","INFO":"NULL"},{"EOM":"2011-05-31","sym":"BBB","INFO":"NULL"},{"EOM":"2011-06-30","sym":"BBB","INFO":"NULL"},{"EOM":"2011-07-31","sym":"BBB","INFO":"NULL"},{"EOM":"2011-08-31","sym":"BBB","INFO":"NULL"},{"EOM":"2011-09-30","sym":"BBB","INFO":"NULL"},{"EOM":"2011-10-31","sym":"BBB","INFO":"NULL"},{"EOM":"2011-11-30","sym":"BBB","INFO":"NULL"},{"EOM":"2011-12-31","sym":"BBB","INFO":"1.36339934163092"},{"EOM":"2012-01-31","sym":"BBB","INFO":"1.28172706095312"},{"EOM":"2012-02-29","sym":"BBB","INFO":"1.23307512240945"},{"EOM":"2012-03-31","sym":"BBB","INFO":"1.15476509186243"},{"EOM":"2012-04-30","sym":"BBB","INFO":"1.16992728545154"},{"EOM":"2012-05-31","sym":"BBB","INFO":"1.0894336069323"},{"EOM":"2012-06-30","sym":"BBB","INFO":"1.10289847320593"},{"EOM":"2012-07-31","sym":"BBB","INFO":"0.96073332708266"},{"EOM":"2012-08-31","sym":"BBB","INFO":"0.930951955594759"},{"EOM":"2012-09-30","sym":"BBB","INFO":"0.968198232770012"},{"EOM":"2012-10-31","sym":"BBB","INFO":"0.85615565913842"},{"EOM":"2012-11-30","sym":"BBB","INFO":"0.76997655662585"},{"EOM":"2012-12-31","sym":"BBB","INFO":"0.768909077101311"},{"EOM":"2013-01-31","sym":"BBB","INFO":"0.571397151287231"},{"EOM":"2013-02-28","sym":"BBB","INFO":"0.516290645810907"},{"EOM":"2013-03-31","sym":"BBB","INFO":"0.357226587544548"},{"EOM":"2013-04-30","sym":"BBB","INFO":"0.363271637643036"},{"EOM":"2013-05-31","sym":"BBB","INFO":"0.417827941047359"},{"EOM":"2013-06-30","sym":"BBB","INFO":"0.787047673692989"},{"EOM":"2013-07-31","sym":"BBB","INFO":"0.537841694271647"},{"EOM":"2013-08-31","sym":"BBB","INFO":"0.558355847746184"},{"EOM":"2013-09-30","sym":"BBB","INFO":"0.159096275100095"},{"EOM":"2013-10-31","sym":"BBB","INFO":"0.162088282377083"},{"EOM":"2013-11-30","sym":"BBB","INFO":"0.290293376295917"},{"EOM":"2013-12-31","sym":"BBB","INFO":"0.408487055655326"},{"EOM":"2008-12-31","sym":"CCC","INFO":"NULL"},{"EOM":"2009-01-31","sym":"CCC","INFO":"NULL"},{"EOM":"2009-02-28","sym":"CCC","INFO":"NULL"},{"EOM":"2009-03-31","sym":"CCC","INFO":"NULL"},{"EOM":"2009-04-30","sym":"CCC","INFO":"NULL"},{"EOM":"2009-05-31","sym":"CCC","INFO":"NULL"},{"EOM":"2009-06-30","sym":"CCC","INFO":"NULL"},{"EOM":"2009-07-31","sym":"CCC","INFO":"NULL"},{"EOM":"2009-08-31","sym":"CCC","INFO":"NULL"},{"EOM":"2009-09-30","sym":"CCC","INFO":"NULL"},{"EOM":"2009-10-31","sym":"CCC","INFO":"NULL"},{"EOM":"2009-11-30","sym":"CCC","INFO":"NULL"},{"EOM":"2009-12-31","sym":"CCC","INFO":"NULL"},{"EOM":"2010-01-31","sym":"CCC","INFO":"NULL"},{"EOM":"2010-02-28","sym":"CCC","INFO":"NULL"},{"EOM":"2010-03-31","sym":"CCC","INFO":"NULL"},{"EOM":"2010-04-30","sym":"CCC","INFO":"NULL"},{"EOM":"2010-05-31","sym":"CCC","INFO":"NULL"},{"EOM":"2010-06-30","sym":"CCC","INFO":"NULL"},{"EOM":"2010-07-31","sym":"CCC","INFO":"NULL"},{"EOM":"2010-08-31","sym":"CCC","INFO":"NULL"},{"EOM":"2010-09-30","sym":"CCC","INFO":"NULL"},{"EOM":"2010-10-31","sym":"CCC","INFO":"NULL"},{"EOM":"2010-11-30","sym":"CCC","INFO":"NULL"},{"EOM":"2010-12-31","sym":"CCC","INFO":"NULL"},{"EOM":"2011-01-31","sym":"CCC","INFO":"NULL"},{"EOM":"2011-02-28","sym":"CCC","INFO":"NULL"},{"EOM":"2011-03-31","sym":"CCC","INFO":"NULL"},{"EOM":"2011-04-30","sym":"CCC","INFO":"NULL"},{"EOM":"2011-05-31","sym":"CCC","INFO":"NULL"},{"EOM":"2011-06-30","sym":"CCC","INFO":"NULL"},{"EOM":"2011-07-31","sym":"CCC","INFO":"NULL"},{"EOM":"2011-08-31","sym":"CCC","INFO":"NULL"},{"EOM":"2011-09-30","sym":"CCC","INFO":"NULL"},{"EOM":"2011-10-31","sym":"CCC","INFO":"NULL"},{"EOM":"2011-11-30","sym":"CCC","INFO":"NULL"},{"EOM":"2011-12-31","sym":"CCC","INFO":"-0.680484554124345"},{"EOM":"2012-01-31","sym":"CCC","INFO":"-0.613067733094883"},{"EOM":"2012-02-29","sym":"CCC","INFO":"-1.0556643740288"},{"EOM":"2012-03-31","sym":"CCC","INFO":"-1.12857934562344"},{"EOM":"2012-04-30","sym":"CCC","INFO":"-1.15148862718521"},{"EOM":"2012-05-31","sym":"CCC","INFO":"-1.10663872200846"},{"EOM":"2012-06-30","sym":"CCC","INFO":"-1.33589225180152"},{"EOM":"2012-07-31","sym":"CCC","INFO":"-1.33562547382318"},{"EOM":"2012-08-31","sym":"CCC","INFO":"-1.34294940890139"},{"EOM":"2012-09-30","sym":"CCC","INFO":"-1.14410892844854"},{"EOM":"2012-10-31","sym":"CCC","INFO":"-0.885800768444971"},{"EOM":"2012-11-30","sym":"CCC","INFO":"-0.63863952256145"},{"EOM":"2012-12-31","sym":"CCC","INFO":"-0.627978199910875"},{"EOM":"2013-01-31","sym":"CCC","INFO":"-0.76868217990417"},{"EOM":"2013-02-28","sym":"CCC","INFO":"-0.86526391043653"},{"EOM":"2013-03-31","sym":"CCC","INFO":"-0.836517628192648"},{"EOM":"2013-04-30","sym":"CCC","INFO":"-1.03293876400083"},{"EOM":"2013-05-31","sym":"CCC","INFO":"-0.856405284557855"},{"EOM":"2013-06-30","sym":"CCC","INFO":"-0.889764187487621"},{"EOM":"2013-07-31","sym":"CCC","INFO":"-1.0024183141239"},{"EOM":"2013-08-31","sym":"CCC","INFO":"-0.836435734282757"},{"EOM":"2013-09-30","sym":"CCC","INFO":"-1.03422090678605"},{"EOM":"2013-10-31","sym":"CCC","INFO":"-1.28325469416878"},{"EOM":"2013-11-30","sym":"CCC","INFO":"-1.35717062783412"},{"EOM":"2013-12-31","sym":"CCC","INFO":"-1.26791636115069"}]}

Using the same data, we could PIVOT the results into a tabular format.

SELECT EOM,

       AAA,

       BBB,

       CCC

FROM

(

    SELECT s1.EOM,

           s1.sym,

           wct.MovingINFORATIO(

                                  s1.pr,

                                  s2.pr,

                                  12,

                                  'True',

                                  36,

                                  ROW_NUMBER() OVER (PARTITION BY s1.SYM ORDER BY 

                                            s1.sym, s1.eom ASC),

                                  1,

                                  'True'

                              ) as INFO

    FROM #s s1

        JOIN #s s2

            ON s1.eom = s2.eom

    WHERE s1.sym <> 'BMK'

          AND s2.sym = 'BMK'

) d

PIVOT

(

    sum(INFO)

    for sym in (AAA, BBB, CCC)

) as P;

This produces the following result.

{"columns":[{"field":"EOM","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"AAA"},{"field":"BBB"},{"field":"CCC"}],"rows":[{"EOM":"2008-12-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2009-01-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2009-02-28","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2009-03-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2009-04-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2009-05-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2009-06-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2009-07-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2009-08-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2009-09-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2009-10-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2009-11-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2009-12-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2010-01-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2010-02-28","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2010-03-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2010-04-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2010-05-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2010-06-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2010-07-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2010-08-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2010-09-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2010-10-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2010-11-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2010-12-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2011-01-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2011-02-28","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2011-03-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2011-04-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2011-05-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2011-06-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2011-07-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2011-08-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2011-09-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2011-10-31","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2011-11-30","AAA":"NULL","BBB":"NULL","CCC":"NULL"},{"EOM":"2011-12-31","AAA":"-1.50264335385127","BBB":"1.36339934163092","CCC":"-0.680484554124345"},{"EOM":"2012-01-31","AAA":"-1.47405028124021","BBB":"1.28172706095312","CCC":"-0.613067733094883"},{"EOM":"2012-02-29","AAA":"-1.84676037014358","BBB":"1.23307512240945","CCC":"-1.0556643740288"},{"EOM":"2012-03-31","AAA":"-2.15641678352096","BBB":"1.15476509186243","CCC":"-1.12857934562344"},{"EOM":"2012-04-30","AAA":"-2.1739413324635","BBB":"1.16992728545154","CCC":"-1.15148862718521"},{"EOM":"2012-05-31","AAA":"-2.17128210170209","BBB":"1.0894336069323","CCC":"-1.10663872200846"},{"EOM":"2012-06-30","AAA":"-2.5317422089487","BBB":"1.10289847320593","CCC":"-1.33589225180152"},{"EOM":"2012-07-31","AAA":"-2.53188351427334","BBB":"0.96073332708266","CCC":"-1.33562547382318"},{"EOM":"2012-08-31","AAA":"-2.62837551419835","BBB":"0.930951955594759","CCC":"-1.34294940890139"},{"EOM":"2012-09-30","AAA":"-2.72145792313755","BBB":"0.968198232770012","CCC":"-1.14410892844854"},{"EOM":"2012-10-31","AAA":"-2.55195013877502","BBB":"0.85615565913842","CCC":"-0.885800768444971"},{"EOM":"2012-11-30","AAA":"-2.49044158602105","BBB":"0.76997655662585","CCC":"-0.63863952256145"},{"EOM":"2012-12-31","AAA":"-2.6058963440003","BBB":"0.768909077101311","CCC":"-0.627978199910875"},{"EOM":"2013-01-31","AAA":"-3.00315246759007","BBB":"0.571397151287231","CCC":"-0.76868217990417"},{"EOM":"2013-02-28","AAA":"-3.35044041416273","BBB":"0.516290645810907","CCC":"-0.86526391043653"},{"EOM":"2013-03-31","AAA":"-3.17148170381401","BBB":"0.357226587544548","CCC":"-0.836517628192648"},{"EOM":"2013-04-30","AAA":"-2.92585906326791","BBB":"0.363271637643036","CCC":"-1.03293876400083"},{"EOM":"2013-05-31","AAA":"-2.71821547287965","BBB":"0.417827941047359","CCC":"-0.856405284557855"},{"EOM":"2013-06-30","AAA":"-2.64361364266275","BBB":"0.787047673692989","CCC":"-0.889764187487621"},{"EOM":"2013-07-31","AAA":"-2.6529046127412","BBB":"0.537841694271647","CCC":"-1.0024183141239"},{"EOM":"2013-08-31","AAA":"-2.35020101018412","BBB":"0.558355847746184","CCC":"-0.836435734282757"},{"EOM":"2013-09-30","AAA":"-2.44660010597957","BBB":"0.159096275100095","CCC":"-1.03422090678605"},{"EOM":"2013-10-31","AAA":"-2.53463230735959","BBB":"0.162088282377083","CCC":"-1.28325469416878"},{"EOM":"2013-11-30","AAA":"-2.48913598084977","BBB":"0.290293376295917","CCC":"-1.35717062783412"},{"EOM":"2013-12-31","AAA":"-2.37004988731189","BBB":"0.408487055655326","CCC":"-1.26791636115069"}]}