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

implemented DetoneCovarianceTransformer #46

Closed moneygeek closed 4 years ago

moneygeek commented 4 years ago

It does, and it should. By the way, we get the reordered corr matrix if we use the recorded w and v to do vdiag(w)v'

On Wed, May 27, 2020 at 2:22 PM stevey628 notifications@github.com wrote:

@stevey628 commented on this pull request.

In mcos/covariance_transformer.py https://github.com/enjine-com/mcos/pull/46#discussion_r431449977:

  • Derive the correlation matrix from a covariance matrix
  • :param cov: covariance matrix
  • :return: correlation matrix
  • """
  • std = np.sqrt(np.diag(cov))
  • corr = cov / np.outer(std, std)
  • corr[corr < -1], corr[corr > 1] = -1, 1 # numerical error
  • return corr
  • corr = cov_to_corr(cov)
  • w, v = linalg.eig(corr)
  • sort from highest eigenvalues to lowest

  • sort_index = np.argsort(-np.abs(w)) # get sort_index in descending absolute order - i.e. from most significant
  • w = w[sort_index]
  • v = reorder_matrix(v, sort_index)

reorder_matrix reorders both columns and rows of the matrix. won't reordering the rows of the eigenvectors change the vectors themselves?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/enjine-com/mcos/pull/46#pullrequestreview-419618332, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXTIXOM52ABFAUUJ7ZJW7TRTWABRANCNFSM4NMIZTKA .

moneygeek commented 4 years ago

*reordered

On Wed, May 27, 2020 at 2:25 PM Jin Won Choi jin.choi@moneygeek.ca wrote:

It does, and it should. By the way, we get the reordered corr matrix if we use the recorded w and v to do vdiag(w)v'

On Wed, May 27, 2020 at 2:22 PM stevey628 notifications@github.com wrote:

@stevey628 commented on this pull request.

In mcos/covariance_transformer.py https://github.com/enjine-com/mcos/pull/46#discussion_r431449977:

  • Derive the correlation matrix from a covariance matrix
  • :param cov: covariance matrix
  • :return: correlation matrix
  • """
  • std = np.sqrt(np.diag(cov))
  • corr = cov / np.outer(std, std)
  • corr[corr < -1], corr[corr > 1] = -1, 1 # numerical error
  • return corr
  • corr = cov_to_corr(cov)
  • w, v = linalg.eig(corr)
  • sort from highest eigenvalues to lowest

  • sort_index = np.argsort(-np.abs(w)) # get sort_index in descending absolute order - i.e. from most significant
  • w = w[sort_index]
  • v = reorder_matrix(v, sort_index)

reorder_matrix reorders both columns and rows of the matrix. won't reordering the rows of the eigenvectors change the vectors themselves?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/enjine-com/mcos/pull/46#pullrequestreview-419618332, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXTIXOM52ABFAUUJ7ZJW7TRTWABRANCNFSM4NMIZTKA .

moneygeek commented 4 years ago

actually, I guess I wouldn't have to reorder the corr matrix if I only swapped the eigenvectors around. I'll update the code.

On Wed, May 27, 2020 at 2:25 PM Jin Won Choi jin.choi@moneygeek.ca wrote:

*reordered

On Wed, May 27, 2020 at 2:25 PM Jin Won Choi jin.choi@moneygeek.ca wrote:

It does, and it should. By the way, we get the reordered corr matrix if we use the recorded w and v to do vdiag(w)v'

On Wed, May 27, 2020 at 2:22 PM stevey628 notifications@github.com wrote:

@stevey628 commented on this pull request.

In mcos/covariance_transformer.py https://github.com/enjine-com/mcos/pull/46#discussion_r431449977:

  • Derive the correlation matrix from a covariance matrix
  • :param cov: covariance matrix
  • :return: correlation matrix
  • """
  • std = np.sqrt(np.diag(cov))
  • corr = cov / np.outer(std, std)
  • corr[corr < -1], corr[corr > 1] = -1, 1 # numerical error
  • return corr
  • corr = cov_to_corr(cov)
  • w, v = linalg.eig(corr)
  • sort from highest eigenvalues to lowest

  • sort_index = np.argsort(-np.abs(w)) # get sort_index in descending absolute order - i.e. from most significant
  • w = w[sort_index]
  • v = reorder_matrix(v, sort_index)

reorder_matrix reorders both columns and rows of the matrix. won't reordering the rows of the eigenvectors change the vectors themselves?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/enjine-com/mcos/pull/46#pullrequestreview-419618332, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXTIXOM52ABFAUUJ7ZJW7TRTWABRANCNFSM4NMIZTKA .