Skip to main content

Constrain

Comments

2 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • Shi He
    Gurobi-versary
    First Comment
    First Question

    If I use stkwt instead of selwt in exposure constraint and set min weight of stkwt to 0.0(represent that no constraint of select 100 tickers), exposure constraint works well. I wonder how should I write the exposure contraint in my case to select 100 tickers and limit the min weight to 0.001.

    ------------------------------- code ---------------------------------

        model.setObjective(risk_ret, GRB.MAXIMIZE) #maximize forecast return
        model.addConstr(stkwt.sum() == 1)       #sum of weights of selected tickers equals 1.0
        for v in stkwt:
            model.addConstr(v == [0.0, 0.03])  #weight constrained to [0.0,0.03]
        benchmarkWt = self.index_wt / 100  #benchmark weights
        for i in range(len(fac_names)):
            facExpo = X.iloc[:,i]
            idxExpo = benchmarkWt.dot(facExpo)
            if idxExpo != 0:
                model.addConstr((stkwt.dot(facExpo) - idxExpo) / idxExpo == [-0.5, 0.5])   #factors exposure constraint


        model.optimize()

     

    0

Post is closed for comments.