robertmartin8 / PyPortfolioOpt

Financial portfolio optimisation in python, including classical efficient frontier, Black-Litterman, Hierarchical Risk Parity
https://pyportfolioopt.readthedocs.io/
MIT License
4.43k stars 948 forks source link

Question: Does the EfficientFrontier +CAPM + ledoit_wolf give more weight to recently listed stocks? #500

Closed Originn closed 1 year ago

Originn commented 1 year ago

I have the following setup:

S = risk_models.CovarianceShrinkage(prices).ledoit_wolf()
mu = pypfopt.expected_returns.capm_return(prices)
ef = EfficientFrontier(mu, S)
ef.add_objective(objective_functions.L2_reg, gamma=(0.1)) 
ef.efficient_risk(0.025)
weights = ef.clean_weights()
su = pd.DataFrame([weights])
#finding zero weights
num_small = len([k for k in weights if weights[k] <= 1e-4])
global_dict[int(userId)]['num_small'] = str(f"{num_small}/{len(ef.tickers)} tickers have zero weight")
fig = px.pie(su, values=weights.values(), names=su.columns)
fig.update_traces(textposition='inside')
fig.update_layout(width=500, height=500, uniformtext_minsize=12, uniformtext_mode='hide', title_text='Weights Distribution using Capital Asset Pricing Model', title_x=0.5)

And I have the following output:

Price graph showing GLBE was listed on May 2021 image

The weights return of the above code image

The allocation return of the above code image

When using another recently listed stock (MNDY) instead of GLBE I get similar results:

image

Is there more weights allocated in this setup to more recently listed stocks? or this is by chance ?

Originn commented 1 year ago

Raising in another question