QuantConnect / QuantConnect/Lean
[Feature Request] Concise Factor-Based Algorithms
Open
Nobody has claimed this yet.
depth
feature
- Dominant language
- C#
- Stars
- 21.7k
- Forks
- 5.3k
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 34
Description
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
- I have completely filled out this template
- I have confirmed that this issue exists on the current
masterbranch - I have confirmed that this is not a duplicate issue by searching issues
- I have provided detailed steps to reproduce the issue
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the QCAlgorithm, add_universe, add_factors, and CrossAssetFactor entry points shown in the example, then compare them with the current factor-calculation support. Done means users can calculate and normalize factor scores across a universe while LEAN manages the dataset and rebalancing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, python
- Domain
- backend, data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100