How do I build a regression model with integer constraints on parameters? My question is similar to: How do I fit a constrained regression in R so that coefficients total = 1? except that I am interested in a solution to the following constraints on the parameters:
All $\pi_i$ should be -1, 0 or 1.
Basically: How do I fit a regression when the only allowed weights are -1, 0 or 1?
 A: This seems to be a discrete optimization problem, where you have integer (some of the decision variables / parameters are discrete) constrains on the decision parameters. Comparing to continuous optimization, discrete optimization is much harder to solve: many continuous optimization problems can be solved in $P$ time but most real world discrete optimization problems are $NP$.
If your problem is not in large scale, you can run a brute-force search. For example, if you have $10$ parameters and each parameter has $3$ possible values, the search space is $3^{10}=59049$, which can be done in seconds with modern computer. On the other hand, please note, the search space grows exponentially, if you have $20$ parameters, the brute force is not feasible.
When I say search, I mean, try different configurations of parameters and calculate the loss/objective function. (for example, squared loss in regression). Check for the configurations with lowest loss. Here is an example on mtcars data with $2$ parameters, each of them takes $\{-1,0,1\}$. In this toy example, the optimal solution is $(0,0)$, and has minimal loss of $14042.31$.


As mentioned earlier, if you have more parameters, then, such approach is not feasible. You may want to do two things.


*

*Integer programming

*Local search
Integer programming one will give you exact answer with high computation cost, and local search is fast, but may give you sub-optimal answer. Each one is a huge topic you can explore and I think it is hard to explain them in detail here.

Edit: as Mark mentioned in the comment, comparing to general discrete optimization problem, the problem has a special structure: the problem is the objective function is quadratic, therefore Mixed Integer Quadratic Programming (MIQP) software can be used. In addition, 

Another option would be to solve this as a (mixed) integer Second Order Cone Problem (SOCP), which may or may not be easier (faster) to solve, but requires more knowledge to formulate.

