One-factor mean-reverting model parameter estimation with Kalman Filter - LinAlgError: 13-th leading minor of the array is not positive definite 
My code so far is as follows, starting from the simplest case of estimating only k:
import scipy
from pykalman.sqrt import CholeskyKalmanFilter
import numpy as np

k = 0.0001
T = np.array([1, 3, 6, 7, 8, 9, 10, 11, 12, 13, 16,20,24,28,32,34,35] , dtype=int) #maturities
delta = 1e-9
x = k

#Optimisation

def obj(x):
    k = x[0]
    Q = (1 - k) *np.eye(1)
    Z = np.exp(-k*T)
    Z =Z[:, None] #reshape to 2 dim
    transition_covariance=delta / (1 - delta) * np.eye(1)
    print(transition_covariance.shape)
    observation_covariance=0.001*np.eye(len(T))
    print(observation_covariance.shape)
    print(Q.shape)
    print(Z.shape)
    
    kf = CholeskyKalmanFilter(transition_matrices=np.eye(1)*(1-k),
                  observation_matrices= Z,
                  transition_covariance=transition_covariance,
                  observation_covariance=observation_covariance,
                  )
    
    lk =  kf.loglikelihood(X) # X is my observed data, 1016 rows × 17 columns
    return -lk

x = np.array([k])

k = scipy.optimize.minimize(obj, x)

However, when I run the optimization I get the error
LinAlgError: 13-th leading minor of the array is not positive definite
I have tried to use both standard Kalman Filter and the "square root" filter (CholeskyKalmanFilter), however with the same results. Any idea how to fix it?
Thank you!
 A: I think I found a solution! Using a different scipy algorithm there is a solution to the optimisation. The optimised factors provide a good fit for the model.
Here is the code:
k =  0.00000000000001 
sigma = 0.00000000000001
T = np.array([1, 3, 6, 7, 8, 9, 10, 11, 12, 13, 16,20,24,28,32,34,35] , dtype=int) #maturities
x = k, sigma

#objective function

def obj(x):
    k = x[0]
    sigma = x[1]
    Q = (1 - k) *np.eye(1)
    Z = np.exp(-k*T)
    Z =Z[:, None] #reshape to 2 dim
    transition_covariance= (sigma**2)* np.eye(1)

    observation_covariance=0.001*np.eye(len(T))

    
    kf = KalmanFilter(transition_matrices=Q,
                  observation_matrices= Z,
                  transition_covariance=transition_covariance,
                  observation_covariance=observation_covariance)

    lk =  kf.loglikelihood(X) # X is my observed data, 1016 rows × 17 columns
    return -lk #negative to maximise minimise algorithm

x = np.array([k, sigma])

opt_params = scipy.optimize.minimize(obj, x, method= 'TNC')


