How to calculate correlation and covariance matrix between columns of a TimeArray

I’m new to Julia.

I want to calculate the correlation and covariance matrix of the columns of a TimeArray. To reproduce my example, I copied my code below to construct a TimeArray.

using DataFrames
using TimeSeries

date = ["2022-12-01","2022-12-02","2022-12-03","2022-12-04","2022-12-05","2022-12-06","2022-12-07","2022-12-08","2022-12-09","2022-12-10"]
bond = [0.06276629, 0.03958098, 0.08456482,0.02759821,0.09584956,0.06363253,0.02874502,0.02707264,0.08776449,0.02950032]
stock = [0.1759782,0.20386651,0.21993588,0.3090001,0.17365969,0.10465274,0.07888138,0.13220847,0.28409742,0.14343067]

df = DataFrame(date =  date, bond = bond, stock = stock)
df.date = Date.(df.date, "yyyy-mm-dd")

ta = TimeArray(df, timestamp = :date)

Is there any easy way to do it? Something like:

cor(ta) 
cov(ta)

It throws out an error when I do it.

I appreciate any answer. Thank you so much for your attention and participation.

I think you need:

using Statistics
cov(values(ta))
cor(values(ta))
1 Like