TSRunningCor 函数会计算运行窗口上的两个时间系列的运行关联。如果该窗口中任一输入的方差是零或 NULL,那么 TSRunningCor 函数会返回 NULL。
TSRunningCor(value1 double precision,
value2 double precision,
num_values integer)
returns double precision;
TSRunningCor(value1 real,
value2 real,
num_values integer)
returns double precision;
在 Apply 函数内使用 TSRunningCor 函数。
TSRunningCor 函数针对固定数量的元素运行,而非针对固定长度的时间运行;因此,它可能不适用于不规则时间系列。
前 (num_values - 1) 个输出源自较短的窗口(第一个输出从第一个输入时间派生,第二个输出从前两个输入时间派生,依此类推)。输入中的 Null 元素也会导致窗口变短。
TSRunningCor 函数可以采用作为时间系列的列的参数。使用 Apply 函数接受的相同参数格式。
最后 k 个值的 DOUBLE PRECISION 运行关联。
select Apply('TSRunningCor($0.high, $1.high, 20)',
ds1.stock_data::TimeSeries(stock_bar),
ds1.stock_data::TimeSeries(stock_bar))::TimeSeries(one_real)
from daily_stocks ds1, daily_stocks ds2
where ds1.stock_name = 'GBase'
and ds2.stock_name = 'AA1';