title: Simple linear regression with constraint
body: <p>I have developed an algorithm to loop through 15 variables and produce a simple OLS for each variable. Then the algorithm loops a further 11 times to produce the same 15 OLS regressions but the lag of the X variable increases by one each time. I select the independent variables with the highest r^2 and use the optimum lag for 3,4 or 5 variables</p>
  <p>i.e.</p>
  <pre><code>Y_t+1 - Y_t = B ( X_t+k - X_t) + e
  </code></pre>
  <p>My dataset looks like this:</p>
  <pre><code>Regression = pd.DataFrame(np.random.randint(low=0, high=10, size=(100, 6)), 
                  columns=['Y', 'X1', 'X2', 'X3', 'X4','X5'])
  </code></pre>
  <p>The OLS regression I have fitted so far uses the following code:</p>
  <pre><code>Y = Regression['Y']
  X = Regression[['X1','X2','X3']]
  
  Model = sm.OLS(Y,X).fit()
  predictions = Model.predict(X)
  
  Model.summary()
  </code></pre>
  <p>The issue is that with OLS, you can get negative coefficients (which I do). I'd appreciate the help in constraining this model with the following:</p>
  <pre><code>sum(B_i) = 1
  
  B_i &gt;= 0
  </code></pre>