QuantConnect / QuantConnect/Lean

Implement RemoveSecurities for Coarse and Fine Universes

Open
#3,581 2 comments 0 reactions 0 assignees View on GitHub

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

Current Behaviour

Currently Lean only allows to remove securities from a User-Defined Universe

Requested Behavior

Allow to use RemoveSecurities also for Coarse and Fine Universes.

A Few Use Cases
  • At the moment, simple Long/Short strategies that use Coarse/Fine Universe can only be built in two ways:
  1. Performing all the needed calculations within the Universe module to select securities to go Long and securities to go Short. Then, once this Universe is created, the same calculations need to be performed again within the Alpha module in order to know which securities were Longs and which ones were Shorts. This process is not elegant and slow. However, it allows for a much more thorough screening of securities than scenario 2 below as you could perform the calculations in Universe across hundreds of securities and then repeat them in Alpha for just the few securities you have already decided to trade.

A potential solution to this scenario would be the ability to tag the securities as Long/Short (or any other tags) in Universe in order for the Alpha to know what to do with them.

  1. Performing a basic preliminary selection in Universe based on price, volume and fundamentals and keep a few hundred of assets. This Universe will then be sent to Alpha for calculations to select the few Longs and Shorts. This process looks more elegant as the calculations are only performed once, however the algorithm would be really slow and inefficient since most of the securities in the Universe won't be traded and therefore useless to stay in the Universe. Actually, with normal capacity, the maximum number of assets that could be in Universe with minute data would be around 100 and that with risk of crashing already.

I believe the second scenario makes a more general case, and that simply being able to get rid of the useless securities from the Universe (once the decision of trading has been made) would fix the issue.

  • Any strategies that need intraday data to make the trading decision. For example, selecting securities based on price, volume and fundamentals within Universe that could be interesting for the day. Then, waiting for the market open to make the final decision on which of those securities to trade based on behavior during the trading session. This is a similar issue to the second scenario mentioned above, in which only a few assets are traded and the remaining stay in Universe slowing down the algorithm and potentially causing a crash.

The solution would be again to remove those remaining securities from Universe.

Checklist
  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching [issues]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the existing RemoveSecurities entry point and how Coarse and Fine Universes manage their selected securities. The work is complete when RemoveSecurities can remove securities from both universe types without breaking their normal selection and update behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.