KER and FCF Yield Factor Optimization

K

This is a factor optimization strategy, written for Quantconnect LEAN (Python). The attached code demonstrates how to combine technical and fundamental factors in an optimized portfolio, focusing on the most heavily-weighted stocks in SPY.

Feel free to re-use this, customize it, make it better and re-share.

General Architecture
The strategy uses a two-factor model combining the Kaufman Efficiency Ratio (technical) and Free Cash Flow Yield (fundamental). Each factor is implemented as a class with a standardized interface. A monthly rebalancing routine collects factor values, normalizes them to z-scores, and uses Nelder-Mead optimization to find optimal factor weights that maximize the correlation with recent price performance.
The Code
I’ve structured the code with clear separation between factor definitions and the main algorithm, making it easy to understand and extend with your own factors.
  1. Universe Selection
    The strategy targets the top 5 weighted stocks in the S&P 500 ETF (SPY). This approach focuses on the most liquid, large-cap names in the market, providing stability and reliability for factor testing.
  1. Factor Definitions
    Two complementary factors are used to evaluate stocks:
    • Kaufman Efficiency Ratio (KER): A technical factor that identifies stocks exhibiting smooth, directional price movement. Values closer to 1 indicate strong trend efficiency, while values closer to 0 indicate choppy price action.
    • Free Cash Flow Yield (FCF Yield): A fundamental factor that highlights companies generating strong cash flows relative to their market value. Higher values indicate potentially undervalued companies with solid cash generation.

  1. Live Optimization with Nelder-Mead
    At each monthly rebalance, the algorithm:
    • Collects raw factor values for each security
    • Normalizes them to create factor z-scores for cross-sectional comparison
    • Uses the Nelder-Mead method to optimize factor weights, maximizing correlation with recent price performance
    • This direct search optimization method is effective for this low-dimensional problem without requiring derivatives

  1. Portfolio Construction
    After optimizing factor weights, the algorithm:
    • Calculates combined portfolio scores by applying optimized weights to factor z-scores
    • Filters out negative-scored securities to maintain a long-only portfolio
    • Normalizes weights to ensure 100% exposure
  1. Monthly Rebalancing
    The strategy rebalances at the start of each month, incorporating both technical efficiency and fundamental strength in its weighting scheme. This monthly cadence balances trading costs with the need to adapt to changing market conditions. This approach combines momentum and value factors in a systematic, optimized framework while maintaining focus on the market’s most liquid securities.
     

 


 

About the author

quantish
By quantish

quantish

Automate everything.