@@ -83,8 +83,10 @@ def fix_nonpositive_semidefinite(matrix, fix_method="spectral"):
8383 else :
8484 raise NotImplementedError ("Method {} not implemented" .format (fix_method ))
8585
86- if not _is_positive_semidefinite (fixed_matrix ):
87- warnings .warn ("Could not fix matrix. Please try a different risk model." )
86+ if not _is_positive_semidefinite (fixed_matrix ): # pragma: no cover
87+ warnings .warn (
88+ "Could not fix matrix. Please try a different risk model." , UserWarning
89+ )
8890
8991 # Rebuild labels if provided
9092 if isinstance (matrix , pd .DataFrame ):
@@ -109,7 +111,6 @@ def risk_matrix(prices, method="sample_cov", **kwargs):
109111 - ``sample_cov``
110112 - ``semicovariance``
111113 - ``exp_cov``
112- - ``min_cov_determinant``
113114 - ``ledoit_wolf``
114115 - ``ledoit_wolf_constant_variance``
115116 - ``ledoit_wolf_single_factor``
@@ -127,8 +128,6 @@ def risk_matrix(prices, method="sample_cov", **kwargs):
127128 return semicovariance (prices , ** kwargs )
128129 elif method == "exp_cov" :
129130 return exp_cov (prices , ** kwargs )
130- elif method == "min_cov_determinant" :
131- return min_cov_determinant (prices , ** kwargs )
132131 elif method == "ledoit_wolf" or method == "ledoit_wolf_constant_variance" :
133132 return CovarianceShrinkage (prices , ** kwargs ).ledoit_wolf ()
134133 elif method == "ledoit_wolf_single_factor" :
@@ -290,6 +289,8 @@ def min_cov_determinant(
290289 :return: annualised estimate of covariance matrix
291290 :rtype: pd.DataFrame
292291 """
292+ warnings .warn ("min_cov_determinant is deprecated and will be removed in v1.5" )
293+
293294 if not isinstance (prices , pd .DataFrame ):
294295 warnings .warn ("data is not in a dataframe" , RuntimeWarning )
295296 prices = pd .DataFrame (prices )
@@ -306,7 +307,8 @@ def min_cov_determinant(
306307 X = prices
307308 else :
308309 X = returns_from_prices (prices )
309- X = np .nan_to_num (X .values )
310+ # X = np.nan_to_num(X.values)
311+ X = X .dropna ().values
310312 raw_cov_array = sklearn .covariance .fast_mcd (X , random_state = random_state )[1 ]
311313 cov = pd .DataFrame (raw_cov_array , index = assets , columns = assets ) * frequency
312314 return fix_nonpositive_semidefinite (cov , kwargs .get ("fix_method" , "spectral" ))
@@ -377,7 +379,7 @@ def __init__(self, prices, returns_data=False, frequency=252):
377379 from sklearn import covariance
378380
379381 self .covariance = covariance
380- except (ModuleNotFoundError , ImportError ):
382+ except (ModuleNotFoundError , ImportError ): # pragma: no cover
381383 raise ImportError ("Please install scikit-learn via pip or poetry" )
382384
383385 if not isinstance (prices , pd .DataFrame ):
0 commit comments