trophy

Long Only, ETF Alpha Streams Competition with $27,500 Prize Pool

Back

Combining multiple assets with indicators

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,

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.


Hi Urahara,

You're on the right track -- OnSecuritiesChanged() is the best place to add or removed indicators for new securities being added or removed from the Universe. The easiest way to do this is to define a dictionary that uses a Symbol for the key and an Indicator for the value. This way, you can add or remove indicators in the OnSecuritiesChanged() and then access the indicators in OnData() by indexing the dictionary using the Symbols in the data Slice. The indicators will all update automatically each time there is data present for the corresponding Symbol in the data Slice, so no need to update manually. I've attached a backtest that will provide you with the basic steps to accomplish all of this, I hope it is helpful.

 

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