Research Tools
Portfolio
Portfolio Construction
PortfolioConstructor
A class to construct balanced and weighted portfolios with constraints.
Parameters (constructor)
max_iterations
(int, default=1000): Maximum iterations for constraint enforcement.tolerance
(float, default=1e-6): Convergence tolerance for constraint enforcement.
Example
construct_portfolio
Build a balanced and weighted portfolio with position and category constraints.
Parameters
df
(pd.DataFrame): DataFrame containing company data.score_col
(str): Column name to use for ranking companies within each category.balance_col
(str): Column name to use for balancing (e.g., ‘sector’, ‘industry’, ‘region’).weight_col
(str, optional): Column name to use for weighting when using COLUMN or SCORE methods.size
(int, optional): Target number of companies in the portfolio.max_position_weight
(float, default=0.05): Maximum weight allowed for any single position.max_category_weight
(float, default=0.15): Maximum weight allowed for any category.weight_method
(WeightMethod, default=WeightMethod.EQUAL): Weighting methodology to use.
Returns
pd.DataFrame
: Portfolio with calculated weights, sorted by weight (descending).
Example
WeightMethod
Enumeration for portfolio weighting methods.
WeightMethod.EQUAL
: Equal weighting for all companies.WeightMethod.COLUMN
: Weight based on a specific column (e.g., market cap).WeightMethod.SCORE
: Weight based on score values (softmax-normalized).
Example