portfolio_replicator
mainsequence.virtualfundbuilder.contrib.time_series.portfolio_replicator
ETFReplicator
Bases: WeightsBase
, TimeSerie
__init__(symbol_to_replicate, tracking_strategy_configuration, in_window=60, tracking_strategy=TrackingStrategy.LASSO, *args, **kwargs)
Initialize the ETFReplicator.
Args: symbol_to_replicate (str): Symbol of the asset to replicate. Must be included in the signals asset universe. tracking_strategy_configuration (TrackingStrategyConfiguration): Configuration parameters for the tracking strategy. in_window (int, optional): The size of the rolling window for regression. Defaults to 60. tracking_strategy (TrackingStrategy, optional): The regression strategy to use for tracking. Defaults to TrackingStrategy.LASSO. args: Variable length argument list. *kwargs: Arbitrary keyword arguments.
rolling_elastic_net(y, X, window, alpha=1.0, l1_ratio=0.5)
Perform rolling Elastic Net regression and return the coefficients.
Parameters: y (pd.Series): Target variable. X (pd.DataFrame): Feature variables. window (int): Size of the rolling window. alpha (float, optional): Regularization strength. Defaults to 1.0. l1_ratio (float, optional): The ElasticNet mixing parameter. Defaults to 0.5.
Returns: np.ndarray: Array of coefficients for each rolling window.
rolling_lasso_regression(y, X, window, alpha=1.0, *args, **kwargs)
Perform rolling Lasso regression and return the coefficients.
Parameters: y (pd.Series): Target variable. X (pd.DataFrame): Feature variables. window (int): Size of the rolling window. alpha (float, optional): Regularization strength. Defaults to 1.0.
Returns: list: List of DataFrames containing the coefficients for each rolling window.
rolling_pca_betas(X, window, n_components=5, *args, **kwargs)
Perform rolling PCA and return the betas (normalized principal component weights).
Parameters: X (pd.DataFrame): DataFrame of stock returns or feature data (rows are time, columns are assets). window (int): The size of the rolling window. n_components (int, optional): The number of principal components to extract. Defaults to 5.
Returns: np.ndarray: An array of normalized PCA weights for each rolling window.