SQL Server running volatility function

RunningVOLATILITY

Updated: 31 Dec 2013

Use RunningVOLATILITY to calculate the historical volatility based upon price or valuation data from column values in an ordered resultant table, without the need for a self-join. The volatility is calculated for each value from the first value in the set to the last value in the set. If the column values are presented to the functions out of order, an error message will be generated.

The historic volatility is calculated as the sample standard deviation of the natural logarithm of the returns multiplied by the square of the scaling factor supplied to the function.

Syntax

SELECT [wctWindowing].[wct].[RunningVOLATILITY](

<@Price,float,>

,<@Scale,float,>

,<@RowNum,int,>

,<@Id,tinyint,>)

Arguments

@Price

the price passed into the function. Generally, price is the end-of-day price for the security, commodity, currency, or index for which the volatility is being calculated. @Price is an expression of type float or of a type that can be implicitly converted to float.

@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.

@RowNum

the number of the row within the group for which the sum 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.

@Id

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

Returns

float

Remarks

·If @Id is NULL then @Id = 0.

·To calculate the moving volatility over a window in a dataset or partition, use the MovingVOLATILITY function.

·If @RowNum is equal to 1, RunningVOLATILITY is equal to NULL.

·@RowNum must be in ascending order.

·There may be cases where the order in which the data are returned to the function and the order in which the results are returned are different, generally due to parallelism. You can use OPTION(MAXDOP 1) or OPTION(MAXDOP 1,FORCE ORDER) to help eliminate this problem.

Example

In this example we calculate the running volatility from the 2013-09-30 to 2013-12-27.

SELECT

ticker

,tdate

,CAST(price asmoney)as price

,wct.RunningVOLATILITY(

price,--@Price

252,--@Scale

ROW_NUMBER()OVER (ORDERBY tdate),--@RowNum

NULL--@Id

)as VOL

FROM

(VALUES

('IBM','2013-12-27',185.08)

,('IBM','2013-12-26',185.35)

,('IBM','2013-12-24',183.22)

,('IBM','2013-12-23',182.23)

,('IBM','2013-12-20',180.02)

,('IBM','2013-12-19',180.22)

,('IBM','2013-12-18',178.7)

,('IBM','2013-12-17',175.76)

,('IBM','2013-12-16',177.85)

,('IBM','2013-12-13',172.8)

,('IBM','2013-12-12',173.37)

,('IBM','2013-12-11',175.2)

,('IBM','2013-12-10',177.12)

,('IBM','2013-12-09',177.46)

,('IBM','2013-12-06',177.67)

,('IBM','2013-12-05',176.08)

,('IBM','2013-12-04',175.74)

,('IBM','2013-12-03',176.08)

,('IBM','2013-12-02',177.48)

,('IBM','2013-11-29',179.68)

,('IBM','2013-11-27',178.97)

,('IBM','2013-11-26',177.31)

,('IBM','2013-11-25',178.94)

,('IBM','2013-11-22',181.3)

,('IBM','2013-11-21',184.13)

,('IBM','2013-11-20',185.19)

,('IBM','2013-11-19',185.25)

,('IBM','2013-11-18',184.47)

,('IBM','2013-11-15',183.19)

,('IBM','2013-11-14',182.21)

,('IBM','2013-11-13',183.55)

,('IBM','2013-11-12',183.07)

,('IBM','2013-11-11',182.88)

,('IBM','2013-11-08',179.99)

,('IBM','2013-11-07',180)

,('IBM','2013-11-06',179.19)

,('IBM','2013-11-05',176.9)

,('IBM','2013-11-04',179.31)

,('IBM','2013-11-01',178.27)

,('IBM','2013-10-31',178.25)

,('IBM','2013-10-30',179.19)

,('IBM','2013-10-29',181.15)

,('IBM','2013-10-28',176.4)

,('IBM','2013-10-25',175.91)

,('IBM','2013-10-24',176.85)

,('IBM','2013-10-23',174.83)

,('IBM','2013-10-22',174.04)

,('IBM','2013-10-21',171.94)

,('IBM','2013-10-18',172.85)

,('IBM','2013-10-17',173.9)

,('IBM','2013-10-16',185.73)

,('IBM','2013-10-15',183.67)

,('IBM','2013-10-14',185.97)

,('IBM','2013-10-11',185.17)

,('IBM','2013-10-10',183.78)

,('IBM','2013-10-09',180.35)

,('IBM','2013-10-08',177.77)

,('IBM','2013-10-07',181.04)

,('IBM','2013-10-04',183.12)

,('IBM','2013-10-03',182.88)

,('IBM','2013-10-02',183.97)

,('IBM','2013-10-01',185.38)

,('IBM','2013-09-30',184.19)

)n(ticker,tdate,price)

This produces the following result.

ticker tdate price VOL

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

IBM 2013-09-30 184.19 NULL

IBM 2013-10-01 185.38 NULL

IBM 2013-10-02 183.97 0.157991601318105

IBM 2013-10-03 182.88 0.121985295333914

IBM 2013-10-04 183.12 0.103819114248728

IBM 2013-10-07 181.04 0.1144147399885

IBM 2013-10-08 177.77 0.1401579805873

IBM 2013-10-09 180.35 0.1767404717407

IBM 2013-10-10 183.78 0.204482795103378

IBM 2013-10-11 185.17 0.195693582420282

IBM 2013-10-14 185.97 0.185445051011276

IBM 2013-10-15 183.67 0.187265588559365

IBM 2013-10-16 185.73 0.186049678915767

IBM 2013-10-17 173.90 0.342742937950233

IBM 2013-10-18 172.85 0.329369740776868

IBM 2013-10-21 171.94 0.317403106677901

IBM 2013-10-22 174.04 0.313744375771333

IBM 2013-10-23 174.83 0.30536711027807

IBM 2013-10-24 176.85 0.301214200365808

IBM 2013-10-25 175.91 0.292941050832951

IBM 2013-10-28 176.40 0.285725276959642

IBM 2013-10-29 181.15 0.295741935323325

IBM 2013-10-30 179.19 0.29062633554224

IBM 2013-10-31 178.25 0.284254243424246

IBM 2013-11-01 178.27 0.278050768878414

IBM 2013-11-04 179.31 0.273148784591888

IBM 2013-11-05 176.90 0.27042556572641

IBM 2013-11-06 179.19 0.268806191182128

IBM 2013-11-07 180.00 0.264302413631107

IBM 2013-11-08 179.99 0.259549647060813

IBM 2013-11-11 182.88 0.259600756641362

IBM 2013-11-12 183.07 0.255263347230854

IBM 2013-11-13 183.55 0.251236693474519

IBM 2013-11-14 182.21 0.248083217211755

IBM 2013-11-15 183.19 0.2447863673686

IBM 2013-11-18 184.47 0.241915934806432

IBM 2013-11-19 185.25 0.238690800797804

IBM 2013-11-20 185.19 0.235355683781686

IBM 2013-11-21 184.13 0.232647822225072

IBM 2013-11-22 181.30 0.232914395369242

IBM 2013-11-25 178.94 0.232107235776856

IBM 2013-11-26 177.31 0.230138018432581

IBM 2013-11-27 178.97 0.228695714503832

IBM 2013-11-29 179.68 0.226236229264604

IBM 2013-12-02 177.48 0.225349326156618

IBM 2013-12-03 176.08 0.223402266012121

IBM 2013-12-04 175.74 0.220916846781547

IBM 2013-12-05 176.08 0.218609398878077

IBM 2013-12-06 177.67 0.217468996906325

IBM 2013-12-09 177.46 0.215194000212408

IBM 2013-12-10 177.12 0.213002692451954

IBM 2013-12-11 175.20 0.21205763372289

IBM 2013-12-12 173.37 0.211011420807653

IBM 2013-12-13 172.80 0.209024171994707

IBM 2013-12-16 177.85 0.216955191401418

IBM 2013-12-17 175.76 0.216263294117974

IBM 2013-12-18 178.70 0.217458654239988

IBM 2013-12-19 180.22 0.216339442752101

IBM 2013-12-20 180.02 0.214438701845782

IBM 2013-12-23 182.23 0.214170134187367

IBM 2013-12-24 183.22 0.212657208109115

IBM 2013-12-26 185.35 0.212202038649472

IBM 2013-12-27 185.08 0.21047900944155

In this example, we calculate the running volatility for multiple securities.

SELECT

ticker

,tdate

,CAST(price asmoney)as price

,wct.RunningVOLATILITY(

price,--@Price

252,--@Scale

ROW_NUMBER()OVER (PARTITIONBY ticker ORDERBY ticker, tdate),--@RowNum

NULL--@Id

)as VOL

FROM

(VALUES

('IBM','2013-12-27',185.08)

,('IBM','2013-12-26',185.35)

,('IBM','2013-12-24',183.22)

,('IBM','2013-12-23',182.23)

,('IBM','2013-12-20',180.02)

,('IBM','2013-12-19',180.22)

,('IBM','2013-12-18',178.7)

,('IBM','2013-12-17',175.76)

,('IBM','2013-12-16',177.85)

,('IBM','2013-12-13',172.8)

,('IBM','2013-12-12',173.37)

,('IBM','2013-12-11',175.2)

,('IBM','2013-12-10',177.12)

,('IBM','2013-12-09',177.46)

,('IBM','2013-12-06',177.67)

,('IBM','2013-12-05',176.08)

,('IBM','2013-12-04',175.74)

,('IBM','2013-12-03',176.08)

,('IBM','2013-12-02',177.48)

,('IBM','2013-11-29',179.68)

,('IBM','2013-11-27',178.97)

,('IBM','2013-11-26',177.31)

,('IBM','2013-11-25',178.94)

,('IBM','2013-11-22',181.3)

,('IBM','2013-11-21',184.13)

,('IBM','2013-11-20',185.19)

,('IBM','2013-11-19',185.25)

,('IBM','2013-11-18',184.47)

,('IBM','2013-11-15',183.19)

,('IBM','2013-11-14',182.21)

,('IBM','2013-11-13',183.55)

,('IBM','2013-11-12',183.07)

,('IBM','2013-11-11',182.88)

,('IBM','2013-11-08',179.99)

,('IBM','2013-11-07',180)

,('IBM','2013-11-06',179.19)

,('IBM','2013-11-05',176.9)

,('IBM','2013-11-04',179.31)

,('IBM','2013-11-01',178.27)

,('IBM','2013-10-31',178.25)

,('IBM','2013-10-30',179.19)

,('IBM','2013-10-29',181.15)

,('IBM','2013-10-28',176.4)

,('IBM','2013-10-25',175.91)

,('IBM','2013-10-24',176.85)

,('IBM','2013-10-23',174.83)

,('IBM','2013-10-22',174.04)

,('IBM','2013-10-21',171.94)

,('IBM','2013-10-18',172.85)

,('IBM','2013-10-17',173.9)

,('IBM','2013-10-16',185.73)

,('IBM','2013-10-15',183.67)

,('IBM','2013-10-14',185.97)

,('IBM','2013-10-11',185.17)

,('IBM','2013-10-10',183.78)

,('IBM','2013-10-09',180.35)

,('IBM','2013-10-08',177.77)

,('IBM','2013-10-07',181.04)

,('IBM','2013-10-04',183.12)

,('IBM','2013-10-03',182.88)

,('IBM','2013-10-02',183.97)

,('IBM','2013-10-01',185.38)

,('IBM','2013-09-30',184.19)

,('FB','2013-12-27',55.44)

,('FB','2013-12-26',57.73)

,('FB','2013-12-24',57.96)

,('FB','2013-12-23',57.77)

,('FB','2013-12-20',55.12)

,('FB','2013-12-19',55.05)

,('FB','2013-12-18',55.57)

,('FB','2013-12-17',54.86)

,('FB','2013-12-16',53.81)

,('FB','2013-12-13',53.32)

,('FB','2013-12-12',51.83)

,('FB','2013-12-11',49.38)

,('FB','2013-12-10',50.25)

,('FB','2013-12-09',48.84)

,('FB','2013-12-06',47.94)

,('FB','2013-12-05',48.34)

,('FB','2013-12-04',48.62)

,('FB','2013-12-03',46.73)

,('FB','2013-12-02',47.06)

,('FB','2013-11-29',47.01)

,('FB','2013-11-27',46.49)

,('FB','2013-11-26',45.89)

,('FB','2013-11-25',44.82)

,('FB','2013-11-22',46.23)

,('FB','2013-11-21',46.7)

,('FB','2013-11-20',46.43)

,('FB','2013-11-19',46.36)

,('FB','2013-11-18',45.83)

,('FB','2013-11-15',49.01)

,('FB','2013-11-14',48.99)

,('FB','2013-11-13',48.71)

,('FB','2013-11-12',46.61)

,('FB','2013-11-11',46.2)

,('FB','2013-11-08',47.53)

,('FB','2013-11-07',47.56)

,('FB','2013-11-06',49.12)

,('FB','2013-11-05',50.11)

,('FB','2013-11-04',48.22)

,('FB','2013-11-01',49.75)

,('FB','2013-10-31',50.21)

,('FB','2013-10-30',49.01)

,('FB','2013-10-29',49.4)

,('FB','2013-10-28',50.23)

,('FB','2013-10-25',51.95)

,('FB','2013-10-24',52.45)

,('FB','2013-10-23',51.9)

,('FB','2013-10-22',52.68)

,('FB','2013-10-21',53.85)

,('FB','2013-10-18',54.22)

,('FB','2013-10-17',52.21)

,('FB','2013-10-16',51.14)

,('FB','2013-10-15',49.5)

,('FB','2013-10-14',49.51)

,('FB','2013-10-11',49.11)

,('FB','2013-10-10',49.05)

,('FB','2013-10-09',46.77)

,('FB','2013-10-08',47.14)

,('FB','2013-10-07',50.52)

,('FB','2013-10-04',51.04)

,('FB','2013-10-03',49.18)

,('FB','2013-10-02',50.28)

,('FB','2013-10-01',50.42)

,('FB','2013-09-30',50.23)

,('ORCL','2013-12-27',37.98)

,('ORCL','2013-12-26',37.69)

,('ORCL','2013-12-24',37.32)

,('ORCL','2013-12-23',36.93)

,('ORCL','2013-12-20',36.37)

,('ORCL','2013-12-19',36.6)

,('ORCL','2013-12-18',34.6)

,('ORCL','2013-12-17',33.63)

,('ORCL','2013-12-16',33.54)

,('ORCL','2013-12-13',33.23)

,('ORCL','2013-12-12',33.6)

,('ORCL','2013-12-11',34.56)

,('ORCL','2013-12-10',34.8)

,('ORCL','2013-12-09',35.6)

,('ORCL','2013-12-06',35.48)

,('ORCL','2013-12-05',34.85)

,('ORCL','2013-12-04',35.07)

,('ORCL','2013-12-03',35.07)

,('ORCL','2013-12-02',35.08)

,('ORCL','2013-11-29',35.29)

,('ORCL','2013-11-27',35.29)

,('ORCL','2013-11-26',34.93)

,('ORCL','2013-11-25',34.78)

,('ORCL','2013-11-22',34.83)

,('ORCL','2013-11-21',34.94)

,('ORCL','2013-11-20',34.75)

,('ORCL','2013-11-19',34.76)

,('ORCL','2013-11-18',34.93)

,('ORCL','2013-11-15',34.92)

,('ORCL','2013-11-14',34.38)

,('ORCL','2013-11-13',35)

,('ORCL','2013-11-12',34.7)

,('ORCL','2013-11-11',34.37)

,('ORCL','2013-11-08',34.35)

,('ORCL','2013-11-07',34)

,('ORCL','2013-11-06',34.07)

,('ORCL','2013-11-05',33.5)

,('ORCL','2013-11-04',33.71)

,('ORCL','2013-11-01',33.53)

,('ORCL','2013-10-31',33.5)

,('ORCL','2013-10-30',33.53)

,('ORCL','2013-10-29',33.71)

,('ORCL','2013-10-28',33.14)

,('ORCL','2013-10-25',33.15)

,('ORCL','2013-10-24',33.07)

,('ORCL','2013-10-23',32.7)

,('ORCL','2013-10-22',32.9)

,('ORCL','2013-10-21',32.95)

,('ORCL','2013-10-18',32.9)

,('ORCL','2013-10-17',32.87)

,('ORCL','2013-10-16',33.02)

,('ORCL','2013-10-15',32.75)

,('ORCL','2013-10-14',33.28)

,('ORCL','2013-10-11',33.26)

,('ORCL','2013-10-10',32.99)

,('ORCL','2013-10-09',32.19)

,('ORCL','2013-10-08',32.37)

,('ORCL','2013-10-07',32.84)

,('ORCL','2013-10-04',33.21)

,('ORCL','2013-10-03',33.12)

,('ORCL','2013-10-02',33.56)

,('ORCL','2013-10-01',33.38)

,('ORCL','2013-09-30',33.05)

,('MSFT','2013-12-27',37.29)

,('MSFT','2013-12-26',37.44)

,('MSFT','2013-12-24',37.08)

,('MSFT','2013-12-23',36.62)

,('MSFT','2013-12-20',36.8)

,('MSFT','2013-12-19',36.25)

,('MSFT','2013-12-18',36.58)

,('MSFT','2013-12-17',36.52)

,('MSFT','2013-12-16',36.89)

,('MSFT','2013-12-13',36.69)

,('MSFT','2013-12-12',37.22)

,('MSFT','2013-12-11',37.61)

,('MSFT','2013-12-10',38.11)

,('MSFT','2013-12-09',38.71)

,('MSFT','2013-12-06',38.36)

,('MSFT','2013-12-05',38)

,('MSFT','2013-12-04',38.94)

,('MSFT','2013-12-03',38.31)

,('MSFT','2013-12-02',38.45)

,('MSFT','2013-11-29',38.13)

,('MSFT','2013-11-27',37.6)

,('MSFT','2013-11-26',37.35)

,('MSFT','2013-11-25',37.64)

,('MSFT','2013-11-22',37.57)

,('MSFT','2013-11-21',37.4)

,('MSFT','2013-11-20',37.08)

,('MSFT','2013-11-19',36.74)

,('MSFT','2013-11-18',36.92)

,('MSFT','2013-11-15',37.56)

,('MSFT','2013-11-14',37.73)

,('MSFT','2013-11-13',37.87)

,('MSFT','2013-11-12',37.08)

,('MSFT','2013-11-11',37.31)

,('MSFT','2013-11-08',37.5)

,('MSFT','2013-11-07',37.22)

,('MSFT','2013-11-06',37.89)

,('MSFT','2013-11-05',36.36)

,('MSFT','2013-11-04',35.67)

,('MSFT','2013-11-01',35.26)

,('MSFT','2013-10-31',35.14)

,('MSFT','2013-10-30',35.27)

,('MSFT','2013-10-29',35.25)

,('MSFT','2013-10-28',35.3)

,('MSFT','2013-10-25',35.46)

,('MSFT','2013-10-24',33.47)

,('MSFT','2013-10-23',33.51)

,('MSFT','2013-10-22',34.32)

,('MSFT','2013-10-21',34.73)

,('MSFT','2013-10-18',34.7)

,('MSFT','2013-10-17',34.66)

,('MSFT','2013-10-16',34.38)

,('MSFT','2013-10-15',34.23)

,('MSFT','2013-10-14',34.19)

,('MSFT','2013-10-11',33.87)

,('MSFT','2013-10-10',33.51)

,('MSFT','2013-10-09',32.82)

,('MSFT','2013-10-08',32.76)

,('MSFT','2013-10-07',33.05)

,('MSFT','2013-10-04',33.62)

,('MSFT','2013-10-03',33.61)

,('MSFT','2013-10-02',33.66)

,('MSFT','2013-10-01',33.33)

,('MSFT','2013-09-30',33.03)

,('AAPL','2013-12-27',560.09)

,('AAPL','2013-12-26',563.9)

,('AAPL','2013-12-24',567.67)

,('AAPL','2013-12-23',570.09)

,('AAPL','2013-12-20',549.02)

,('AAPL','2013-12-19',544.46)

,('AAPL','2013-12-18',550.77)

,('AAPL','2013-12-17',554.99)

,('AAPL','2013-12-16',557.5)

,('AAPL','2013-12-13',554.43)

,('AAPL','2013-12-12',560.54)

,('AAPL','2013-12-11',561.36)

,('AAPL','2013-12-10',565.55)

,('AAPL','2013-12-09',566.43)

,('AAPL','2013-12-06',560.02)

,('AAPL','2013-12-05',567.9)

,('AAPL','2013-12-04',565)

,('AAPL','2013-12-03',566.32)

,('AAPL','2013-12-02',551.23)

,('AAPL','2013-11-29',556.07)

,('AAPL','2013-11-27',545.96)

,('AAPL','2013-11-26',533.4)

,('AAPL','2013-11-25',523.74)

,('AAPL','2013-11-22',519.8)

,('AAPL','2013-11-21',521.14)

,('AAPL','2013-11-20',515)

,('AAPL','2013-11-19',519.55)

,('AAPL','2013-11-18',518.63)

,('AAPL','2013-11-15',524.99)

,('AAPL','2013-11-14',528.16)

,('AAPL','2013-11-13',520.63)

,('AAPL','2013-11-12',520.01)

,('AAPL','2013-11-11',519.05)

,('AAPL','2013-11-08',520.56)

,('AAPL','2013-11-07',512.49)

,('AAPL','2013-11-06',520.92)

,('AAPL','2013-11-05',522.4)

,('AAPL','2013-11-04',523.69)

,('AAPL','2013-11-01',517.01)

,('AAPL','2013-10-31',519.67)

,('AAPL','2013-10-30',521.85)

,('AAPL','2013-10-29',513.68)

,('AAPL','2013-10-28',526.8)

,('AAPL','2013-10-25',522.91)

,('AAPL','2013-10-24',528.82)

,('AAPL','2013-10-23',521.91)

,('AAPL','2013-10-22',516.85)

,('AAPL','2013-10-21',518.33)

,('AAPL','2013-10-18',505.94)

,('AAPL','2013-10-17',501.57)

,('AAPL','2013-10-16',498.2)

,('AAPL','2013-10-15',495.79)

,('AAPL','2013-10-14',493.16)

,('AAPL','2013-10-11',489.95)

,('AAPL','2013-10-10',486.8)

,('AAPL','2013-10-09',483.77)

,('AAPL','2013-10-08',478.15)

,('AAPL','2013-10-07',484.92)

,('AAPL','2013-10-04',480.23)

,('AAPL','2013-10-03',480.6)

,('AAPL','2013-10-02',486.72)

,('AAPL','2013-10-01',485.13)

,('AAPL','2013-09-30',473.98)

)n(ticker,tdate,price)

This produces the following result.

ticker tdate price VOL

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

AAPL 2013-09-30 473.98 NULL

AAPL 2013-10-01 485.13 NULL

AAPL 2013-10-02 486.72 0.224271090600065

AAPL 2013-10-03 480.60 0.285595548859782

AAPL 2013-10-04 480.23 0.237084900781644

AAPL 2013-10-07 484.92 0.210356013380844

AAPL 2013-10-08 478.15 0.223531451606084

AAPL 2013-10-09 483.77 0.213078771862708

AAPL 2013-10-10 486.80 0.198152326707184

AAPL 2013-10-11 489.95 0.186085489735147

AAPL 2013-10-14 493.16 0.176024763494547

AAPL 2013-10-15 495.79 0.167117075670665

AAPL 2013-10-16 498.20 0.159377876724916

AAPL 2013-10-17 501.57 0.153017708043086

AAPL 2013-10-18 505.94 0.148154178443564

AAPL 2013-10-21 518.33 0.163681793295629

AAPL 2013-10-22 516.85 0.161961570226251

AAPL 2013-10-23 521.91 0.157702562105636

AAPL 2013-10-24 528.82 0.155537178833955

AAPL 2013-10-25 522.91 0.163789677373325

AAPL 2013-10-28 526.80 0.159619478834349

AAPL 2013-10-29 513.68 0.188068722816282

AAPL 2013-10-30 521.85 0.187939213793648

AAPL 2013-10-31 519.67 0.185791257925522

AAPL 2013-11-01 517.01 0.184101659389185

AAPL 2013-11-04 523.69 0.18258564582163

AAPL 2013-11-05 522.40 0.180022101389953

AAPL 2013-11-06 520.92 0.177666471057637

AAPL 2013-11-07 512.49 0.184198773746174

AAPL 2013-11-08 520.56 0.184793776282328

AAPL 2013-11-11 519.05 0.182448898566812

AAPL 2013-11-12 520.01 0.179413859536272

AAPL 2013-11-13 520.63 0.176568489038223

AAPL 2013-11-14 528.16 0.176632767341278

AAPL 2013-11-15 524.99 0.175768975036049

AAPL 2013-11-18 518.63 0.177900006327752

AAPL 2013-11-19 519.55 0.175352929726722

AAPL 2013-11-20 515.00 0.175417509647309

AAPL 2013-11-21 521.14 0.174791013713095

AAPL 2013-11-22 519.80 0.172956766676484

AAPL 2013-11-25 523.74 0.17122031232006

AAPL 2013-11-26 533.40 0.173534056442168

AAPL 2013-11-27 545.96 0.178535535312193

AAPL 2013-11-29 556.07 0.180087476749503

AAPL 2013-12-02 551.23 0.180460442787382

AAPL 2013-12-03 566.32 0.186918087070296

AAPL 2013-12-04 565.00 0.185414766083349

AAPL 2013-12-05 567.90 0.183413052330087

AAPL 2013-12-06 560.02 0.185988179879154

AAPL 2013-12-09 566.43 0.184911834132172

AAPL 2013-12-10 565.55 0.18338595456892

AAPL 2013-12-11 561.36 0.18317290765486

AAPL 2013-12-12 560.54 0.18167312583229

AAPL 2013-12-13 554.43 0.182557458425315

AAPL 2013-12-16 557.50 0.180911821574914

AAPL 2013-12-17 554.99 0.179949862331222

AAPL 2013-12-18 550.77 0.17969270355442

AAPL 2013-12-19 544.46 0.180568123604884

AAPL 2013-12-20 549.02 0.179400394730715

AAPL 2013-12-23 570.09 0.192092068662242

AAPL 2013-12-24 567.67 0.191057332118658

AAPL 2013-12-26 563.90 0.190475164684819

AAPL 2013-12-27 560.09 0.189901899033866

FB 2013-09-30 50.23 NULL

FB 2013-10-01 50.42 NULL

FB 2013-10-02 50.28 0.0735909403320345

FB 2013-10-03 49.18 0.21372716386867

FB 2013-10-04 51.04 0.391578925365895

FB 2013-10-07 50.52 0.353864396216867

FB 2013-10-08 47.14 0.555272404098915

FB 2013-10-09 46.77 0.507151192773698

FB 2013-10-10 49.05 0.570678322191235

FB 2013-10-11 49.11 0.534281803337772

FB 2013-10-14 49.51 0.506537694162177

FB 2013-10-15 49.50 0.480580605322842

FB 2013-10-16 51.14 0.483870696606763

FB 2013-10-17 52.21 0.470928852008138

FB 2013-10-18 54.22 0.475936400052069

FB 2013-10-21 53.85 0.461389696597704

FB 2013-10-22 52.68 0.458080123607665

FB 2013-10-23 51.90 0.448852700952121

FB 2013-10-24 52.45 0.436643260698796

FB 2013-10-25 51.95 0.426578483320681

FB 2013-10-28 50.23 0.433841652776117

FB 2013-10-29 49.40 0.426777613108773

FB 2013-10-30 49.01 0.417191302857349

FB 2013-10-31 50.21 0.416118490473473

FB 2013-11-01 49.75 0.40805911065836

FB 2013-11-04 48.22 0.411289680407328

FB 2013-11-05 50.11 0.421856397340002

FB 2013-11-06 49.12 0.418091141033746

FB 2013-11-07 47.56 0.420982309480531

FB 2013-11-08 47.53 0.413414726634288

FB 2013-11-11 46.20 0.413408370202952

FB 2013-11-12 46.61 0.407808527594948

FB 2013-11-13 48.71 0.421850218058507

FB 2013-11-14 48.99 0.415618117817277

FB 2013-11-15 49.01 0.409284732830668

FB 2013-11-18 45.83 0.440789708660948

FB 2013-11-19 46.36 0.436049727901166

FB 2013-11-20 46.43 0.430061359858497

FB 2013-11-21 46.70 0.424700478381667

FB 2013-11-22 46.23 0.419592812289521

FB 2013-11-25 44.82 0.420459563671933

FB 2013-11-26 45.89 0.420314036577719

FB 2013-11-27 46.49 0.416821504492747

FB 2013-11-29 47.01 0.413023783761765

FB 2013-12-02 47.06 0.408240489554877

FB 2013-12-03 46.73 0.403788802021793

FB 2013-12-04 48.62 0.410786334412208

FB 2013-12-05 48.34 0.406466128989073

FB 2013-12-06 47.94 0.402485128343155

FB 2013-12-09 48.84 0.400736005841239

FB 2013-12-10 50.25 0.401945870464066

FB 2013-12-11 49.38 0.399797257238259

FB 2013-12-12 51.83 0.410152262710804

FB 2013-12-13 53.32 0.410668241058772

FB 2013-12-16 53.81 0.407144480328883

FB 2013-12-17 54.86 0.405203257279515

FB 2013-12-18 55.57 0.402212057196699

FB 2013-12-19 55.05 0.399300456156596

FB 2013-12-20 55.12 0.395782944403901

FB 2013-12-23 57.77 0.403397610908762

FB 2013-12-24 57.96 0.399968754375222

FB 2013-12-26 57.73 0.396832399932739

FB 2013-12-27 55.44 0.402895731629006

IBM 2013-09-30 184.19 NULL

IBM 2013-10-01 185.38 NULL

IBM 2013-10-02 183.97 0.157991601318105

IBM 2013-10-03 182.88 0.121985295333914

IBM 2013-10-04 183.12 0.103819114248728

IBM 2013-10-07 181.04 0.1144147399885

IBM 2013-10-08 177.77 0.1401579805873

IBM 2013-10-09 180.35 0.1767404717407

IBM 2013-10-10 183.78 0.204482795103378

IBM 2013-10-11 185.17 0.195693582420282

IBM 2013-10-14 185.97 0.185445051011276

IBM 2013-10-15 183.67 0.187265588559365

IBM 2013-10-16 185.73 0.186049678915767

IBM 2013-10-17 173.90 0.342742937950233

IBM 2013-10-18 172.85 0.329369740776868

IBM 2013-10-21 171.94 0.317403106677901

IBM 2013-10-22 174.04 0.313744375771333

IBM 2013-10-23 174.83 0.30536711027807

IBM 2013-10-24 176.85 0.301214200365808

IBM 2013-10-25 175.91 0.292941050832951

IBM 2013-10-28 176.40 0.285725276959642

IBM 2013-10-29 181.15 0.295741935323325

IBM 2013-10-30 179.19 0.29062633554224

IBM 2013-10-31 178.25 0.284254243424246

IBM 2013-11-01 178.27 0.278050768878414

IBM 2013-11-04 179.31 0.273148784591888

IBM 2013-11-05 176.90 0.27042556572641

IBM 2013-11-06 179.19 0.268806191182128

IBM 2013-11-07 180.00 0.264302413631107

IBM 2013-11-08 179.99 0.259549647060813

IBM 2013-11-11 182.88 0.259600756641362

IBM 2013-11-12 183.07 0.255263347230854

IBM 2013-11-13 183.55 0.251236693474519

IBM 2013-11-14 182.21 0.248083217211755

IBM 2013-11-15 183.19 0.2447863673686

IBM 2013-11-18 184.47 0.241915934806432

IBM 2013-11-19 185.25 0.238690800797804

IBM 2013-11-20 185.19 0.235355683781686

IBM 2013-11-21 184.13 0.232647822225072

IBM 2013-11-22 181.30 0.232914395369242

IBM 2013-11-25 178.94 0.232107235776856

IBM 2013-11-26 177.31 0.230138018432581

IBM 2013-11-27 178.97 0.228695714503832

IBM 2013-11-29 179.68 0.226236229264604

IBM 2013-12-02 177.48 0.225349326156618

IBM 2013-12-03 176.08 0.223402266012121

IBM 2013-12-04 175.74 0.220916846781547

IBM 2013-12-05 176.08 0.218609398878077

IBM 2013-12-06 177.67 0.217468996906325

IBM 2013-12-09 177.46 0.215194000212408

IBM 2013-12-10 177.12 0.213002692451954

IBM 2013-12-11 175.20 0.21205763372289

IBM 2013-12-12 173.37 0.211011420807653

IBM 2013-12-13 172.80 0.209024171994707

IBM 2013-12-16 177.85 0.216955191401418

IBM 2013-12-17 175.76 0.216263294117974

IBM 2013-12-18 178.70 0.217458654239988

IBM 2013-12-19 180.22 0.216339442752101

IBM 2013-12-20 180.02 0.214438701845782

IBM 2013-12-23 182.23 0.214170134187367

IBM 2013-12-24 183.22 0.212657208109115

IBM 2013-12-26 185.35 0.212202038649472

IBM 2013-12-27 185.08 0.21047900944155

MSFT 2013-09-30 33.03 NULL

MSFT 2013-10-01 33.33 NULL

MSFT 2013-10-02 33.66 0.00909945101198763

MSFT 2013-10-03 33.61 0.100413740807231

MSFT 2013-10-04 33.62 0.0929039814232559

MSFT 2013-10-07 33.05 0.172704008464697

MSFT 2013-10-08 32.76 0.16496637923671

MSFT 2013-10-09 32.82 0.151810388040649

MSFT 2013-10-10 33.51 0.186038465405536

MSFT 2013-10-11 33.87 0.180258404799758

MSFT 2013-10-14 34.19 0.173161316297753

MSFT 2013-10-15 34.23 0.164638099338941

MSFT 2013-10-16 34.38 0.157061406259348

MSFT 2013-10-17 34.66 0.151836148905988

MSFT 2013-10-18 34.70 0.146280696627879

MSFT 2013-10-21 34.73 0.141380283329524

MSFT 2013-10-22 34.32 0.149348503047182

MSFT 2013-10-23 33.51 0.17648721369219

MSFT 2013-10-24 33.47 0.171388315917496

MSFT 2013-10-25 35.46 0.266205233746523

MSFT 2013-10-28 35.30 0.260758230410505

MSFT 2013-10-29 35.25 0.254685710035094

MSFT 2013-10-30 35.27 0.248695297981262

MSFT 2013-10-31 35.14 0.243979969242079

MSFT 2013-11-01 35.26 0.238628420047195

MSFT 2013-11-04 35.67 0.235283525148774

MSFT 2013-11-05 36.36 0.235905078374151

MSFT 2013-11-06 37.89 0.258171079125072

MSFT 2013-11-07 37.22 0.262514261741813

MSFT 2013-11-08 37.50 0.257959595816974

MSFT 2013-11-11 37.31 0.254950380754112

MSFT 2013-11-12 37.08 0.252361424843963

MSFT 2013-11-13 37.87 0.25298730614803

MSFT 2013-11-14 37.73 0.249976816419

MSFT 2013-11-15 37.56 0.247257570736894

MSFT 2013-11-18 36.92 0.250006421033669

MSFT 2013-11-19 36.74 0.247331957441656

MSFT 2013-11-20 37.08 0.24441827639571

MSFT 2013-11-21 37.40 0.241503405501464

MSFT 2013-11-22 37.57 0.238326247744306

MSFT 2013-11-25 37.64 0.235278737797096

MSFT 2013-11-26 37.35 0.233914475011621

MSFT 2013-11-27 37.60 0.231219373329762

MSFT 2013-11-29 38.13 0.229972362005404

MSFT 2013-12-02 38.45 0.227599588301816

MSFT 2013-12-03 38.31 0.225624993419381

MSFT 2013-12-04 38.94 0.225174218939492

MSFT 2013-12-05 38.00 0.231967729440119

MSFT 2013-12-06 38.36 0.229961622354126

MSFT 2013-12-09 38.71 0.227955449372869

MSFT 2013-12-10 38.11 0.229555795763475

MSFT 2013-12-11 37.61 0.230038376124558

MSFT 2013-12-12 37.22 0.229554485482657

MSFT 2013-12-13 36.69 0.230213432071093

MSFT 2013-12-16 36.89 0.228153270737405

MSFT 2013-12-17 36.52 0.227516586364405

MSFT 2013-12-18 36.58 0.225439106141073

MSFT 2013-12-19 36.25 0.224586468963242

MSFT 2013-12-20 36.80 0.224360044116301

MSFT 2013-12-23 36.62 0.222856719616219

MSFT 2013-12-24 37.08 0.222052453655894

MSFT 2013-12-26 37.44 0.220754663739106

MSFT 2013-12-27 37.29 0.219279343527289

ORCL 2013-09-30 33.05 NULL

ORCL 2013-10-01 33.38 NULL

ORCL 2013-10-02 33.56 0.0511565598296228

ORCL 2013-10-03 33.12 0.194524893385894

ORCL 2013-10-04 33.21 0.15962693079071

ORCL 2013-10-07 32.84 0.163932835979515

ORCL 2013-10-08 32.37 0.169562026007422

ORCL 2013-10-09 32.19 0.155305745732859

ORCL 2013-10-10 32.99 0.21431115182054

ORCL 2013-10-11 33.26 0.205313209118141

ORCL 2013-10-14 33.28 0.193571835461169

ORCL 2013-10-15 32.75 0.200370410678046

ORCL 2013-10-16 33.02 0.195485030209003

ORCL 2013-10-17 32.87 0.188197940692586

ORCL 2013-10-18 32.90 0.180903070498614

ORCL 2013-10-21 32.95 0.174486249795735

ORCL 2013-10-22 32.90 0.168650690800606

ORCL 2013-10-23 32.70 0.164822064740397

ORCL 2013-10-24 33.07 0.165962090777967

ORCL 2013-10-25 33.15 0.161519400284209

ORCL 2013-10-28 33.14 0.157219945521419

ORCL 2013-10-29 33.71 0.164062931940689

ORCL 2013-10-30 33.53 0.161520549212189

ORCL 2013-10-31 33.50 0.157890374452793

ORCL 2013-11-01 33.53 0.154423039447922

ORCL 2013-11-04 33.71 0.151923027704309

ORCL 2013-11-05 33.50 0.150458464663653

ORCL 2013-11-06 34.07 0.155764497416513

ORCL 2013-11-07 34.00 0.153150637637205

ORCL 2013-11-08 34.35 0.152832044576634

ORCL 2013-11-11 34.37 0.150189552419081

ORCL 2013-11-12 34.70 0.14952695793235

ORCL 2013-11-13 35.00 0.148415028337516

ORCL 2013-11-14 34.38 0.155857645320068

ORCL 2013-11-15 34.92 0.158398514829021

ORCL 2013-11-18 34.93 0.15609269226205

ORCL 2013-11-19 34.76 0.154792958378235

ORCL 2013-11-20 34.75 0.152691551288764

ORCL 2013-11-21 34.94 0.150983119369056

ORCL 2013-11-22 34.83 0.149444734053735

ORCL 2013-11-25 34.78 0.147681465369976

ORCL 2013-11-26 34.93 0.146016866459654

ORCL 2013-11-27 35.29 0.145865045489117

ORCL 2013-11-29 35.29 0.14416765527668

ORCL 2013-12-02 35.08 0.143605575139531

ORCL 2013-12-03 35.07 0.142017343854959

ORCL 2013-12-04 35.07 0.140464403577833

ORCL 2013-12-05 34.85 0.140034298943158

ORCL 2013-12-06 35.48 0.143777496046051

ORCL 2013-12-09 35.60 0.142337053959356

ORCL 2013-12-10 34.80 0.15102648981496

ORCL 2013-12-11 34.56 0.150549994024614

ORCL 2013-12-12 33.60 0.162202594528557

ORCL 2013-12-13 33.23 0.16254416848462

ORCL 2013-12-16 33.54 0.162220989652853

ORCL 2013-12-17 33.63 0.160794505922403

ORCL 2013-12-18 34.60 0.170125829254427

ORCL 2013-12-19 36.60 0.204897995628464

ORCL 2013-12-20 36.37 0.203792242270183

ORCL 2013-12-23 36.93 0.203982009515225

ORCL 2013-12-24 37.32 0.203016695028237

ORCL 2013-12-26 37.69 0.201947497604015

ORCL 2013-12-27 37.98 0.200593310017029

In this example, we use the same data as in the previous example, except that the data are no longer in 3rd normal form. The closing prices for each of the 5 tickers are now stored in colums with each each date containing a 5 columns, one for each ticker. We can use the @Id variable to calculate the 5 running volatilities in a single select.