Back

Random Universe Selection

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.

Update Backtest








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);
});


 

1

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.


Ah, Yeah I'm reading it now. Thank you. 

0

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?

 

0


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

2


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. 

1

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? 

0

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.

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed