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

**URL:** <https://discourse.julialang.org/t/how-to-calculate-correlation-and-covariance-matrix-between-columns-of-a-timearray/94038>\
**Category:** Statistics\
**Tags:** time-series\
**Created:** [February 4, 2023, 10:35am UTC](https://discourse.julialang.org/t/how-to-calculate-correlation-and-covariance-matrix-between-columns-of-a-timearray/94038 "2023-02-04T10:35:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdogan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mdogan/32/47244_2.png) [@mdogan](https://discourse.julialang.org/u/mdogan)\
**Post date:** [February 4, 2023, 10:35am UTC](https://discourse.julialang.org/t/how-to-calculate-correlation-and-covariance-matrix-between-columns-of-a-timearray/94038/1 "2023-02-04T10:35:17Z")

</div>

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.

```julia
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:

```julia
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.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [February 4, 2023, 8:16pm UTC](https://discourse.julialang.org/t/how-to-calculate-correlation-and-covariance-matrix-between-columns-of-a-timearray/94038/2 "2023-02-04T20:16:26Z")

</div>

I think you need:

```julia
using Statistics
cov(values(ta))
cor(values(ta))

```
