-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchapter2.py
More file actions
25 lines (18 loc) · 802 Bytes
/
chapter2.py
File metadata and controls
25 lines (18 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import pandas as pd
import numpy as np
import denoisingAndDetoning
if __name__ == "__main__":
data = pd.read_csv("data/dailyReturns.csv")
data = data.drop(columns=["date"])
# Punto 2:
# compute covariance matrix
cov = denoisingAndDetoning.covariance(data)
# compute correlation matrix, its eigenvalues
# and the condition number
corr = denoisingAndDetoning.cov2corr(cov)
eVal, eVec = denoisingAndDetoning.getPCA(corr)
conditionNumber = denoisingAndDetoning.conditionNumber(eVal)
print(f"Punto2:\nA. the condition number of the correlation matrix is: {conditionNumber}")
pdf0 = denoisingAndDetoning.mpPDF(data.to_numpy()) # theorical pdf
pdf1 = denoisingAndDetoning.fitKDE(np.diag(eVal)) # empirical pdf
print(np.sum((pdf0 - pdf1) **2))