Hello,
Thank you for this great tool. I'm new to QC and unfortunately I'm starting to get stuck.
I've followed the basics steps to set-up a strategy with a symbol, an indicator, a warm-up period...
Then, I've reached a point I want to try out a back-test with multiple symbols. This is where I'm stuck.
I've created a universe as such it is in the documentation.
/**
* Coarse Universe Filtering
*/
public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse)
{
// select only symbols with fundamental data and sort descending by daily dollar volume
var sortedByDollarVolume = coarse
.Where(x => x.HasFundamentalData)
.OrderByDescending(x => x.DollarVolume);
// take the top entries from our sorted collection
var selection = sortedByDollarVolume.Take(CoarseNumberOfSymbols);
// we need to return only the symbol objects
return selection.Select(x => x.Symbol);
}
/**
* sort the data by P/E ratio and take the top 'NumberOfSymbolsFine'
*/
public IEnumerable<Symbol> FineSelectionFunction(IEnumerable<FineFundamental> fine)
{
// sort descending by P/E ratio
var sortedByPeRatio = fine.OrderByDescending(x => x.ValuationRatios.PERatio);
// take the top entries from our sorted collection
var topFine = sortedByPeRatio.Take(FineNumberOfSymbols);
// we need to return only the symbol objects
return topFine.Select(x => x.Symbol);
}
I understand how universe are working but it's not clear how we can use a universe of symbols with indicators since we have to register a symbol with an indicator. I thought the good way would be to handle it in the OnSecuritiesChanged. Whenever a new security is added to the universe I will screen it with an indicator. Nevertheless, it's not obvious how to create each time an indicator per new security added.
public override void OnSecuritiesChanged(SecurityChanges changes)
{
if (changes.AddedSecurities.Count > 0)
{
Debug("Securities added: " + string.Join(",", changes.AddedSecurities.Select(x => x.Symbol.Value)));
foreach(var security in changes.AddedSecurities) {
RegisterIndicator(security.Symbol, myindicator, Resolution.Minute, Field.Close);
}
}
if (changes.RemovedSecurities.Count > 0)
{
Debug("Securities removed: " +
string.Join(",", changes.RemovedSecurities.Select(x => x.Symbol.Value)));
// UniverseManager.Remove(symbol);
}
}
I would like like to know:
- how can I use the indicator data for each symbol in the OnData method ?
- is this enough or should I update the indicator data manually in the OnData method ?
- should I use a Map of Symbol<->Indicator ?
- how can we unregister data of an indicator ?
Many thanks,
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!