0

Short question. The Variance-Covariance Matrix should be positive semidefinite and symmetric. Using Pandas function .cov() does not return a positive matrix on my end. Instead, all off-diagonal entries are negative:

First I generate a geometric Brownian motion and calculate log returns

import numpy as np
import pandas as pd

def gen_paths(S0, r, sigma, T, M, I):
    dt = float(T) / M
    paths = np.zeros((M + 1, I), np.float64)
    paths[0] = S0
    for t in range(1, M + 1):
        rand = np.random.standard_normal(I)
        rand = (rand - rand.mean()) / rand.std()
        paths[t] = paths[t - 1] * np.exp((r - 0.5 * sigma ** 2) * dt +
        sigma * np.sqrt(dt) * rand)
    return paths

S0 = 100.
r = 0.05
sigma = 0.2
T = 1.0
M = 500
I = 5

paths = gen_paths(S0, r, sigma, T, M, I)
data = pd.DataFrame(paths)
rets = np.log(data / data.shift(1)).dropna()

Now, running the pandas .cov() function on the dataframe returns

In[1]: rets.cov()

Out[1]: 
          0         1         2         3         4
0  0.000086 -0.000022 -0.000026 -0.000016 -0.000021
1 -0.000022  0.000080 -0.000018 -0.000022 -0.000018
2 -0.000026 -0.000018  0.000082 -0.000017 -0.000021
3 -0.000016 -0.000022 -0.000017  0.000074 -0.000019
4 -0.000021 -0.000018 -0.000021 -0.000019  0.000078

Symmetry is given. Positive definiteness not...

Pat
  • 1,299
  • 4
  • 17
  • 40
  • 4
    I think you might be confused about the definition of positive-semidefinite. Try this `np.linalg.eigvals(rets.cov()) > 0`. And see here: https://stackoverflow.com/questions/16266720/find-out-if-matrix-is-positive-definite-with-numpy – JohnE Jan 02 '18 at 20:12
  • 1
    For the particular matrix you show, I get eigenvalues of `[ -3.89788920e-09 1.11287739e-04 8.98372227e-05 9.74523949e-05 1.01426541e-04]`; the first e-value is negative, but is within a reasonable tolerance of 0 (given that I'm using values that have already been rounded to only two significant figures for display purposes). So this looks plausibly positive semdefinite to me. Why do you think it's not positive semidefinite? – Mark Dickinson Jan 02 '18 at 20:40

0 Answers0