Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit allocation weights #69

Open
Hexik opened this issue Oct 29, 2021 · 1 comment
Open

Limit allocation weights #69

Hexik opened this issue Oct 29, 2021 · 1 comment

Comments

@Hexik
Copy link

Hexik commented Oct 29, 2021

Thanks for the great work at this library.

How can I set the lower and upper limit for the allocation of shares in the portfolio when calculating EfficientFrontier? E.g. not less than 2% and not more than 15% per title.

Thank you

Mira

@Leohanhart
Copy link

Hi Mira,

  • I am not part --yet-- of the creators of this project but-

I fixed this by extracting by Exctracing the values of the pf by doing :

set optimalization

    opt_w, opt_res = pf.mc_optimisation(num_trials=500)

creates frames of porfolios

    self.portfolio_strat_low_vol_stocks = self.process__stocks__to__df(
        opt_w.iloc[0], self.the_id_low_vol)
    self.portfolio_strat_high_sharp_stocks = self.process__stocks__to__df(
        opt_w.iloc[1], self.the_id_sharp__)

and after this simply extract the statistics.
# sets vars
self.low_vol_frame = self.portfolio_strat_low_vol_stocks
self.high_sharp_frame = self.portfolio_strat_high_sharp_stocks

    # potfolio items.
    self.std_vol: float = float(self.low_vol_frame.balance.std())
    self.min_vol: float = float(self.low_vol_frame.balance.min())
    self.max_vol: float = float(self.low_vol_frame.balance.max())
    self.avg_vol: float = float(self.low_vol_frame.balance.mean())

    #
    self.std_sharp: float = float(self.high_sharp_frame.balance.std())
    self.min_sharp: float = float(self.high_sharp_frame.balance.min())
    self.max_sharp: float = float(self.high_sharp_frame.balance.max())
    self.avg_sharp: float = float(self.high_sharp_frame.balance.mean())

If you do this in on class like I did, you can just reject the class if the weights are not in you favor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants