I need a way to add stocks and options in my universe by pulling most active stocks or other criteria into my algo
QUANTCONNECT COMMUNITY
I need a way to add stocks and options in my universe by pulling most active stocks or other criteria into my algo
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Mia Alissi
To add stocks and options to your universe based on criteria such as the most active stocks, you can use the
add_universe
andadd_universe_options
methods in QuantConnect. Here's a step-by-step guide to help you implement this in your algorithm:Step 1: Initialize Your Algorithm
Set up your algorithm with the necessary start and end dates, initial cash, and universe settings.
Step 2: Define Stock Selection Criteria
Create a selection function that filters stocks based on your criteria, such as daily dollar volume or P/E ratio.
Step 3: Add Options to Your Universe
Use the
add_universe_options
method to include options for the selected stocks.Step 4: Implement Data Handling
Use the
on_data
method to handle incoming data and manage your portfolio.Step 5: Respond to Universe Changes
Implement the
on_securities_changed
method to adjust your holdings based on changes in the universe.This setup will allow you to dynamically select stocks and options based on your specified criteria and manage your portfolio accordingly. Adjust the selection criteria and option filters as needed to align with your trading strategy.
Sources: Dropbox Base Data Universe Selection Algorithm, User Defined Universe Algorithm, Add Universe Selection Model Algorithm, Basic Template Options Filter Universe Algorithm, Fundamental Universe Selection Algorithm
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Alexandre Catarino
Hi Manoj Kandlikar ,
If Alpaca has a REST API that provides the list of stocks, you can use:
Parse current, which is a string, to the tickers, and call add_equity. You will have to remove the securities at some point too. Say that content is “SPY\nAAPL\nMSFT”, then
Best regards,
Alex
Manoj Kandlikar
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!