Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

191 smooth weights #207

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
experiment edits
  • Loading branch information
kasperjo committed Mar 26, 2024
commit 826f02715879beabd9a096bb552455f5e24f1322
10 changes: 8 additions & 2 deletions cvx/covariance/ewma.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def iterated_ewma(
returns,
vola_halflife,
cov_halflife,
min_periods_vola=20,
min_periods_cov=20,
min_periods_vola=None,
min_periods_cov=None,
mean=False,
mu_halflife1=None,
mu_halflife2=None,
Expand All @@ -117,9 +117,15 @@ def iterated_ewma(
if None, no winsorization is performed
nan_to_num: if True, replace NaNs in returns with 0.0
"""
n = returns.shape[1]
mu_halflife1 = mu_halflife1 or vola_halflife
mu_halflife2 = mu_halflife2 or cov_halflife

if min_periods_vola is None:
min_periods_vola = n
if min_periods_cov is None:
min_periods_cov = min_periods_cov or 3 * n

def scale_cov(vola, matrix):
index = matrix.index
columns = matrix.columns
Expand Down
386 changes: 219 additions & 167 deletions experiments/industry_portfolios.ipynb

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions experiments/utils/iterated_ewma_vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,16 @@ def ewma(y, halflife, clip_at=None, min_periods=None):
"""

beta = np.exp(-np.log(2) / halflife)
# EWMAs = np.zeros_like(y)
# EWMAs[0] = y[0]

EWMA_old = list(y.values())[0]
for t, time in enumerate(y.keys()):
if t == 0:
continue
# for t in range(1, y.shape[0]): # First EWMA is for t=2
# y_last = y[t-1] # Note zero-indexing
# EWMA_t = get_next_ewma(EWMA_t, y_last, t, beta, clip_at, min_periods)

EWMA_old = get_next_ewma(EWMA_old, y[time], t + 1, beta, clip_at, min_periods)

yield time, EWMA_old

# EWMAs[t] = get_next_ewma(EWMAs[t - 1], y[t], t + 1, beta, clip_at, min_periods)

# EWMAs.append(EWMA_t)


def _get_realized_covs(returns):
"""
Expand Down
182 changes: 0 additions & 182 deletions tests/playground.ipynb

This file was deleted.

Loading