import numpy as np
rho = 0.5
cor_matrix = np.ones((5,5))* rho
np.fill_diagonal(cor_matrix,1)
print(cor_matrix)
array([[1. , 0.5, 0.5, 0.5, 0.5],
[0.5, 1. , 0.5, 0.5, 0.5],
[0.5, 0.5, 1. , 0.5, 0.5],
[0.5, 0.5, 0.5, 1. , 0.5],
[0.5, 0.5, 0.5, 0.5, 1. ]])
L = np.linalg.cholesky(cor_matrix)
X_synthetic = L.dot(np.random.normal(0,1, (5,2000)))
np.corrcoef(X_synthetic)
array([[1. , 0.50576661, 0.51472813, 0.47208374, 0.49260528],
[0.50576661, 1. , 0.4798111 , 0.48540114, 0.47225243],
[0.51472813, 0.4798111 , 1. , 0.4649033 , 0.4745259 ],
[0.47208374, 0.48540114, 0.4649033 , 1. , 0.50059795],
[0.49260528, 0.47225243, 0.4745259 , 0.50059795, 1. ]])