Back

Coarse Universe Selection- Price < 50day SMA Give no results

In this algo I am basically trying to do a coarse selection of stocks that have Price < 50 day SMA. I am using a helper class to calc the SMA as I've seen in other examples.  Any ideas why no stocks get returned? Surely in the last couple months there have been stocks under their 50 day SMA.

Update Backtest








Hi Mark Axmann, I believe the lack of trades is due to the size of the period of the slow moving average. The period number will be the amount of daily data it will need before it is set to Ready. Increasing the data range or reducing the period (for example to 20) made trades appear.

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.


Thanks Martin, If I were to go live, how could I ensure that I have the 50 day SMA? Thanks

0

I also just tried adding: SetWarmup(TimeSpan.FromDays(_slowPeriod));

Still no data. Surely there is a way to add a warmup when using universes? 

0

I ended up finding my answer in this post. Basically I needed to run the history inside the constructor for my SelectionData class. 

https://www.quantconnect.com/forum/discussion/1377/universe-warmup/p1


            public SelectionData(QCAlgorithm algorithm, Symbol symbol)
            {
                Slow = new SimpleMovingAverage(_slowPeriod);
                
                algorithm.AddSecurity(SecurityType.Equity, symbol);
                var history = algorithm.History(symbol, _slowPeriod);
                algorithm.RemoveSecurity(symbol);
                foreach (TradeBar tradeBar in history)
                {
                    Slow.Update(tradeBar.EndTime, tradeBar.Close);
                }
            }

0

This added another issue.. when calling AddSecurity() in SelectionData - this triggers the OnSecuritiesChanged() event in my algo , which is what I use to determine if I should add/remove it from the Portfolio.  Now as it starts running the history for each stock, it triggers a Position to be added for all of them , alphabetically. Any ideas around this?  

0

Hi Mark Axmann. The algorithm could check UniverseManager.Values and trade on the universe which is not  UserDefinedUniverse (User defined universe has symbols from AddSecurity/AddEquity calls).

foreach (var universe in UniverseManager.Values)
{
// User defined universe has symbols from AddSecurity/AddEquity calls
if (!(universe is UserDefinedUniverse))
{
foreach (var security in _changes.AddedSecurities)
{
if (universe.Members.ContainsKey(security.Symbol))
{
// Trade
}
}
}
}

 

https://www.quantconnect.com/docs/algorithm-reference/universes
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.


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