Correlation matrix shrinkage causes matrix multiplication error for monte carlo simulation

28 Views Asked by At

I have list of 10 stocks and a correlation 10x10 correlation matrix for these stocks. I have to reduce the size of this matrix to 3x3 and use it for Monte Carlo simulation to simulate possible outcomes. The problem is that reducing the size is causing the matrix multiplication to fail. How can I move forward ?

num_stocks = 10
correlation_matrix = np.zeros((num_stocks, num_stocks))
for i in range(num_stocks):
            for j in range(num_stocks):
                correlation_matrix[i, j] = 0.9 ** abs(i - j)

# using PCA to generate 3x3 reduced correlation matrix
from sklearn.decomposition import PCA
pca = PCA(n_components=3)
p = pca.fit_transform(correlation_matrix)
reduced_correlation_matrix = np.corrcoef(p, rowvar=False)

# Generate 10 random values for simulation
random_vars = np.random.normal(0, 1, num_stocks)

correlated_random_vars = random_vars @ reduced_correlation_matrix

# logic after this uses monte carlo simulation
# correlated_random_vars needs to be a list of 10 random variables
# failing above as random_vars is [10x1] matrix and reduced_correlation_matrix is [3x3] matrix

Any help would be appreciated.

0

There are 0 best solutions below