I am trying to get log of share prices (matrix) in SQL Server. The column name are dynamic and have been by applying PIVOT
DECLARE
@cmd AS NVARCHAR(MAX),
@cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
SET @cols = (SELECT DISTINCT STRING_AGG(Cast(Quotename (Symbol)as NVARCHAR(MAX)),',') FROM #symbol)
--print @cols
set @query = 'SELECT PriceDate,' + @cols + ' INTO ##temp3 from
(
SELECT PriceDate,LastPrice,Symbol FROM #WORK
) x
pivot
(
sum(LastPrice)
for Symbol in (' + @cols + ')
) p ORDER BY PriceDate'
execute(@query);
Now I have to apply log of price change on this column with dynamic column names.
And then I have to apply portfolio Covariance