I'm not sure how to add this, but how can you make it so it picks only stocks within a certain price range? like below 20 dollars in price.
QUANTCONNECT COMMUNITY
I'm not sure how to add this, but how can you make it so it picks only stocks within a certain price range? like below 20 dollars in price.
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 Hector, please checkout the docs section Universes.
Here is code snippet from the Coarse Universe Selection section that teaches you how to pick stocks based on price:
// Take the top 50 by dollar volume using coarse AddUniverse(coarse => { return (from c in coarse where c.Price > 10 orderby c.DollarVolume descending select c.Symbol).Take(50); });
Zedrick Gilo
Ah, Yeah I'm reading it now. Thank you.
Zedrick Gilo
Okay, So I added the code under the setcash like this
public override void Initialize() { UniverseSettings.Resolution = Resolution.Daily; SetStartDate(2016, 01, 01); SetCash(100000); // Take the top 50 by dollar volume using coarse AddUniverse(coarse => { return (from c in coarse where c.Price > 10 orderby c.DollarVolume descending select c.Symbol).Take(10); });
I get no errors but, It doesn't seem to be working correctly... Do it not belong there?
Guadiana
Hi Hector. You are adding universe twice.
First you're adding Universe with the explicit selection function as parameter on line 44.
Later on line 55, you're calling again AddUniverse, using CoarseSelectionFunction, FineSelectionFunction as parameters.
i moved your code inside the CoarseSelectionFunction
Guadiana
By the way, the code Alex Catarino posted is based on LINQ syntax. The one i did is is slightly different, as it uses Lambda expressions . Both do the same.
Zedrick Gilo
Thank you guys, but why is it that when I look at the trades in the backtesting it still doesn't do trades within the price range?
Alexandre Catarino
Hi Hector,
The price is not adjusted when you select the security.
After you selected it, it will be adjusted by default.
I changed Marco's algorithm to buy securities with price below $20 like you asked above. On February 4th, 2016, DUST was priced at $8.66, so it was selected to be bought. Since DUST has two reverse splits (1:15), it was bought with the adjusted price of $464.5.
Zedrick Gilo
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!