Back

Updating indicators and getting their values for multiple symbols?

Good day, guys, what's the fastest way to update custom indicator(s) and getting their data for multiple symbols? SymbolData(), dictionary/list of values, dynamic objects dictionary? Better I'll ask as seen too many too different things :)
Update Backtest








Hey @Tadas!

I like to define a special SymbolData class inside my algorithm. I used this to hold all the data I want for a particular symbol in a convenient place. It's easy to tack on indicators, functions, and other behavior. Then creating a Dictionary allows for easy lookup.
class SymbolData
{
public readonly string Symbol;
public readonly ExponentialMovingAverage Fast;
public readonly ExponentialMovingAverage Slow;

public SymbolData(string symbol, QCAlgorithm algorithm)
{
Symbol = symbol
Fast = algorithm.EMA(symbol, 10);
Slow = algorithm.EMA(symbol, 50);
};
}

private Dictionary Symbols = new Dictionary();

// in initialize
foreach (var symbol in SymbolList)
{
AddSecurity(SecurityType.Equity, symbol);
Symbols.Add(symbol, new SymbolData(symbol, this));
}

// in on data
foreach (var symbolData in Symbols.Values)
{
if (symbolData.Fast > symbolData.Slow) SetHoldings(symbolData.Symbol, 1.0);
else Liquidate(symbolData.Symbol);
}
4

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.


Cool idea, never thought of symbol-data like that. @Michael, perhaps a symbol-indicator wrapper is a good candidate to be put on the slice class? slice.Indicators["SPY"].[DotSomething]
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.


@Jared, it would be cool to be able to say:data["SPY"].mavg(7) > data["SPY"].mavg(14)
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.


Seems nice, I've just understood algorithm is also an object :)

Still have questions until I'll get that working. How to declare, for example, window indicator?


/.../
//_window = algorithm ???
/.../
0

Duh, never mind, seems I do too much different things and forget the basics.
0

@Tadas, apologies for the delay, there currently is no built in helper function to define an automatically updated RollingWindow on QCAlgorithm, but maybe there should be! Consider submitting a feature request to the github issues list!

You could manually define it using code similar to the following:var consolidator = new TradeBarConsolidator(period);
SubscriptionManager.AddConsolidator("SPY", consolidator);
var window = new RollingWindow(windowSize);
consolidator.DataConsolidated += (sender, tradeBar) => window.Add(tradeBar);

Now everytime the consolidator makes new data it will be pumped into the window! This would also work for indicator values using indicator.Updated event.
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.


No problem, @Michael, thank you.
0

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