Allow None as rounding precision

This commit is contained in:
Pat Newell
2019-07-16 12:30:37 -04:00
parent 1eee512088
commit 0dfc183fd0
2 changed files with 22 additions and 3 deletions

View File

@@ -52,11 +52,11 @@ class BaseOptimizer:
:return: asset weights
:rtype: dict
"""
if not isinstance(rounding, int) or rounding < 1:
raise ValueError("rounding must be a positive integer")
clean_weights = self.weights.copy()
clean_weights[np.abs(clean_weights) < cutoff] = 0
if rounding is not None:
if not isinstance(rounding, int) or rounding < 1:
raise ValueError("rounding must be a positive integer")
clean_weights = np.round(clean_weights, rounding)
return dict(zip(self.tickers, clean_weights))