generated from cvxgrp/simulator
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* typo * synthetic returns * removed playground * merged long-only and unconstrained * remove uncommented function * explained return predictions model * Small updates --------- Co-authored-by: phschiele <[email protected]>
- Loading branch information
Showing
2 changed files
with
49 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
import numpy as np | ||
import pandas as pd | ||
|
||
|
||
def synthetic_returns(prices, sigma_r=0.02236, sigma_eps=0.14142): | ||
def synthetic_returns( | ||
prices: pd.DataFrame, var_r: float = 0.0005, var_eps: float = 0.02 | ||
) -> pd.DataFrame: | ||
""" | ||
param prices: a DataFrame of prices | ||
param var_r: the Gaussian variance of the returns | ||
param var_eps: the Gaussian variance of the noise term | ||
returns: a DataFrame of "synthetic return predictions" computed as | ||
alpha*(returns+noise), where alpha=var_r / (var_r + var_eps); this is the | ||
coefficient that minimize the variance of the prediction error under the | ||
above model. | ||
var_r = 0.0005 and var_eps = 0.02 correspond to an information ratio | ||
sqrt(alpha) of about 0.15. | ||
""" | ||
returns = prices.pct_change() | ||
|
||
alpha = sigma_r**2 / (sigma_r**2 + sigma_eps**2) | ||
return alpha * (returns + np.random.normal(size=returns.shape) * sigma_eps) | ||
alpha = var_r / (var_r + var_eps) | ||
sigma_eps = np.sqrt(var_eps) | ||
synthetic_returns = alpha * ( | ||
returns + np.random.normal(size=returns.shape) * sigma_eps | ||
) | ||
return synthetic_returns |