Lean
Lean copied to clipboard
[Feature Request] Concise Factor-Based Algorithms
Expected Behavior
We can simply calculate factor scores for each asset in a universe, where LEAN manages the required dataset and rebalancing for us.
class FactorAlgorithm(QCAlgorithm):
def __init__(self):
universe_settings.resolution = Resolution.DAILY
universe = self.add_universe(
lambda fundamentals: [f.symbol for f in sorted(fundamentals, key=lambda f: f.market_cap)[-10:]]
)
universe.add_factors([InverseCorrelation(252, Field.OPEN)])
class InverseCorrelation(CrossAssetFactor):
def update(self, data):
factor_value_by_symbol = 1/data.dropna(axis=1).corr().abs().sum()
return factor_value_by_symbol / factor_value_by_symbol.sum()
Actual Behavior
Not currently supported
Potential Solution
N/A
Reproducing the Problem
System Information
Checklist
- [x] I have completely filled out this template
- [x] I have confirmed that this issue exists on the current
masterbranch - [x] I have confirmed that this is not a duplicate issue by searching issues
- [ ] I have provided detailed steps to reproduce the issue