PM (Portfolio Model)
Create a portfolio by combining alphas created by yourself or others
Importing Libraries
Here, necessary libraries are imported for the operation of the portfolio model.
Define Model Universe
Alpha List Definition
A list of alphas for the portfolio is defined. These alphas are specific financial models or strategies to be used within the portfolio. alpha_list
replaces the functionality of the deprecated alpha_set
.
Portfolio Class Definition
A Portfolio
class is defined, inheriting from BasePortfolio
. It includes methods for loading alpha positions for a given period and fetching alpha positions to construct the portfolio.
There are two key methods that must be inherited from BasePortfolio:
weight: This method should return a pd.DataFrame where the row indices represent the trading dates and the columns correspond to the “sub-alphas.” The rows must sum to 1.0 (i.e., the weights across sub-alphas for each date should add up to 1.0).
get: This method should return the model’s final positions as a pd.DataFrame. Each row (i.e., each trading date) must sum to 1e8.
In the BasePortfolio class, both methods are already implemented:
weight: Returns an equal-weighted DataFrame across the elements in alpha_list.
get: Returns the weighted sum of the results from the weight method.
Initializing Portfolio and Fetching Data
The portfolio is initialized, and data for a specified period is fetched.
Simulation
Constraints of portfolio
Last updated
Was this helpful?