0
votes

I want to calculate the pairwise correlations of stock returns based on the volume-weighted average prices (vwap).

My starting point is :

priceMatrix=pivot(wavg, [t.price,t.volume],t.trade_date,t.sym)

This creates a vwap price matrix with the trade time as row label and the stock symbol as column label.

Output (the real one has 250+rows and 1576 columns):

           S1   S2   S3   S4
           ---- ---- ---- ----
2020.10.01 38.5 29.0 9.8  7.1
2020.10.02 38   29.1 10.4 7.2
2020.10.03 37.2 29.3 10.8 7.6
....

What I need now is to do the pairwise correlations for each column like this:

    S1  S2  S3  S4
    --- --- --- ---
S1  1   **  **  **
S2  **  1   **  **
S3  **  **  1   **
S4  **  **  **  1

Does anyone know of a way I can get a pairwise correlation matrix in DolphinDB? Thanks!

1

1 Answers

0
votes

Calculate the pair-wise correlation by cross function, for example:

priceMatrix=pivot(avg, t.open,t.trade_date,t.ts_code)
t1=each(ratios,priceMatrix)-1;
pairwisecorr=cross(corr,t1,t1);