Hi Grant,
Are you referring to: b_t+1 = argmin ∥b − b_t+1∥² ?
The way I understand this is that they have to do this because the b_t+1 from the line before is not necessarily in the portfolio-simplex (i.e. the space of valid portfolios; here, their constraint is that the b has to sum to 1 and that all entries are positive). Graphically speaking, you can imagine a sphere in a 3d space. All points on the surface of the sphere are valid portfolios to use. However, if the optimization in the prior line selects one that is outside (or inside) of that sphere, what do you do? Here, they look for the closest point that is still on the sphere (by finding the one with the closest distance) and choose that instead. They "project" it down to this subspace.
This is also related to the Lagrangian multiplier. If you e.g. want to minimize a function you can just take the derivative and set that to = 0. However, what if you only want to find solutions that sum to 1? The derivative doesn't care. What you can do then is add Lagrangian multipliers that enforce this constraint if you do the derivative. I'm not 100% sure but I think they use it here to enforce that b sums to 1. They do not constrain that all entries in b are positive however which is why you have to normalize it. This however they already taken care of.
Now the question is how to normalize. They don't go into a lot of detail here but point to this paper:
Efficient projections onto the l1-ball for learning in high dimensions, John Duchi, et al. ICML 2008.
In the MATLAB code you posted there is a reference implementation (simplex_projection.m). I would probably have to take a look at that paper to see what's going on, but maybe we can get away with just porting that code to python ;).
Let me know if any of this is unclear or you have any other questions. This is fun :). If you want I could also try to port the normalizing function for you to import.
Finally, I think Quantopian/zipline really needs a function to rebalance a portfolio. You give it a vector of your your prior portfolio and what it should look like and it issues the buy/sell orders to achieve the desired portfolio. What do you think?
Disclaimer
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.