PyPortfolioOpt icon indicating copy to clipboard operation
PyPortfolioOpt copied to clipboard

How to add portfolio yield objective?

Open Token-DAO opened this issue 3 years ago • 0 comments

When optimizing a portfolio using the efficient_risk objective function, how can I add an objective that says the resulting portfolio must have a total yield (dividends and interest) of say 4%? Here is the work I've done so far.

I wrote the function for portfolio yield and tried to add constraint and add objective:

def portfolio_yield(w, yields, negative=True):
    sign = -1 if negative else 1
    port_yield = w @ yields
    return _objective_value(w, sign * port_yield)

target_yield = cp.Parameter(name='target_yield', value=target_yield)
portfolio_yield = portfolio_yield(w, yields, negative=False)
ef.add_constraint(lambda w: w >= target_yield)
ef.add_objective(portfolio_yield(yields=yields))

After that, I am kind of stuck. Thanks for the help.

Token-DAO avatar Sep 17 '22 17:09 Token-DAO