enjine-com / mcos

Implementation of Monte Carlo Optimization Selection from the paper "A Robust Estimator of the Efficient Frontier"
MIT License
55 stars 18 forks source link

UnboundLocalError: local variable 'kmeans' referenced before assignment #49

Open ccx01-start opened 3 years ago

ccx01-start commented 3 years ago

Tried to run the notebook sample and received the following error

UnboundLocalError Traceback (most recent call last)

in 18 19 # Run the simulation ---> 20 results = mcos.simulate_optimizations(obs_sim, num_sims, op, ee, [cov_trans]) 21 print(results) 22 results.plot.bar() ~/.venv/lib/python3.9/site-packages/mcos/mcos.py in simulate_optimizations(obs_simulator, n_sims, optimizers, error_estimator, covariance_transformers) 27 28 for optimizer in optimizers: ---> 29 allocation = optimizer.allocate(mu_hat, cov_hat) 30 optimal_allocation = optimizer.allocate(obs_simulator.mu, obs_simulator.cov) 31 ~/.venv/lib/python3.9/site-packages/mcos/optimizer.py in allocate(self, mu, cov) 115 116 # find the optimal partition of clusters --> 117 clusters = self._cluster_k_means_base(corr) 118 119 # calculate intra-cluster allocations by finding the optimal portfolio for each cluster ~/.venv/lib/python3.9/site-packages/mcos/optimizer.py in _cluster_k_means_base(self, corr) 169 clusters = { 170 i: corr.columns[np.where(kmeans.labels_ == i)].tolist() --> 171 for i in np.unique(kmeans.labels_) 172 } # cl