FinQuant icon indicating copy to clipboard operation
FinQuant copied to clipboard

Limit allocation weights

Open Hexik opened this issue 3 years ago • 1 comments

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

Hexik avatar Oct 29 '21 12:10 Hexik

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.

Leohanhart avatar Jan 05 '23 11:01 Leohanhart