Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Modified OLMAR (mean revert to a fair price instead of moving average)

So, I was thinking that since OLMAR tries to find a portfolio assuming that stocks mean revert around a moving average. Lets say I have another method to find the fair price of a stock, can I still use OLMAR framework and replace the moving average with my estimate of fair price? I still haven't completely understood OLMAR algorithm but wanted to check with community experts on OLMAR if something like this feasible before I embark on the implementation.

2 responses

Pravin -

I'll comment more when I get the chance. The short answer, I think, is yes. You just need an expected return forecast. Under the hood, it is just constrained optimization with a quadratic objective function.

Grant

Hi Pravin,

There are a bunch of references here:

https://www.quantopian.com/posts/on-line-portfolio-selection-from-grant-k

Here are some code snippets:

###########################  
    # Inside of OLMAR (algo 2)

    x_bar = x_tilde.mean()

    # Calculate terms for lambda (lam)  
    dot_prod = np.dot(b_t, x_tilde)  
    num = context.eps - dot_prod  
    denom = (np.linalg.norm((x_tilde-x_bar)))**2

    # test for divide-by-zero case  
    if denom == 0.0:  
        lam = 0 # no portolio update  
    else:  
        lam = max(0, num/denom)  
    b = b_t + lam*(x_tilde-x_bar)

    b_norm = simplex_projection(b)  
    weight = np.dot(b_norm,x_tilde)  
    return (b_norm, weight)  
def simplex_projection(v, b=1):  
    """Projection vectors to the simplex domain

Implemented according to the paper: Efficient projections onto the  
l1-ball for learning in high dimensions, John Duchi, et al. ICML 2008.  
Implementation Time: 2011 June 17 by [email protected] AT pmail.ntu.edu.sg  
Optimization Problem: min_{w}\| w - v \|_{2}^{2}  
s.t. sum_{i=1}^{m}=z, w_{i}\geq 0

Input: A vector v \in R^{m}, and a scalar z > 0 (default=1)  
Output: Projection vector w

:Example:
>>> proj = simplex_projection([.4 ,.3, -.4, .5])  
>>> print proj  
array([ 0.33333333, 0.23333333, 0. , 0.43333333])  
>>> print proj.sum()  
1.0

Original matlab implementation: John Duchi ([email protected])  
Python-port: Copyright 2012 by Thomas Wiecki ([email protected]).  
"""

    v = np.asarray(v)  
    p = len(v)

    # Sort v into u in descending order  
    v = (v > 0) * v  
    u = np.sort(v)[::-1]  
    sv = np.cumsum(u)

    rho = np.where(u > (sv - b) / np.arange(1, p+1))[0][-1]  
    theta = np.max([0, (sv[rho] - b) / (rho+1)])  
    w = (v - theta)  
    w[w<0] = 0  
    return w  

So, you just need to compute your x_tilde (I think).

Note also that the so-called BAH(OLMAR) is a simple matter of doing a weighted average over expected returns over an expanding trailing window. Not sure how this maps onto your strategy, but you should probably consider some way of sampling/smoothing, since otherwise, you could end up with choppy returns.

Hope this helps. Just let me know if you need anything else. This weekend, I might get the chance to work up a simple running example.

Grant