Hi. I need SimpleMovingAverage of last 20 days of DollarVolume for my algo. I see that DollarVolume is available in CoarseFundamental as part of coarse selection function. How can I get the last 20 days of this data? Thanks in advance for any help!
Eugene
Hi,
that is not build in by default.Â
I would creat a dictionary with symbols as keys and SMAs as values.Â
Btw. in my opinion it is better to use the market cap as a selection criteria. It is more stable than dollarVolume and I guess that is what you are aming for.Â
Use this in Coarse:
var list = (from c in coarse where c.HasFundamentalData select c).ToList(); splitFactorBySymbol.Clear(); splitFactorBySymbol = list.GroupBy(x => x.Symbol).Select(x => x.First()).ToDictionary(x => x.Symbol, x => x.SplitFactor);
And this in Fine:
// market Cap calculation var marketCapList = (from f in fine let marketCap = (decimal)(f.EarningReports.BasicAverageShares.ThreeMonths * f.Price * splitFactorBySymbol[f.Symbol]) orderby marketCap select marketCap.. or symbol ..).ToList();
Â
Sameer Abdul
Thanks Eugene. I am using a Dictionary to track these values currently. Just having to wait 20 days for the SMA to be ready was cumbersome so I was hoping to find a better way. I will try using market cap instead and see if it gives similar results. Thanks again for the pointer!
Sri Sat
Sameer,
Did you try using History method?
Â
private Symbol benchmarkSymbol; .... benchmarkSymbol = AddEquity("SPY", Resolution.Daily).Symbol; .... var history = History(benchmarkSymbol, movingAverageLength, Resolution.Daily);
Â
Sameer Abdul
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!