Back

How to use RollingWindow[ ] on multiple equities and indicators?

I am new to QC and I am trying to understand how to use RollingWindow[ ] to get previous data for multiple equities and indicators.

I have been studying Python and so I prefer the example in Python.

I have searched the forum and studied the examples and I have not been able to determine how to apply RollingWindow[ ] to multiple equities.

Your help is appreciated.

Thank you.

Update Backtest








as i remember it right this sample uses an class that stores info about some stocks.

you would need to create such class that stores rolling window for every stock:  -> class SymbolData(object):

https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/EmaCrossUniverseSelectionAlgorithm.py
0

Jared Broad the python equivalent for MultipleSymbolConsolidationAlgorithm.cs is missing with storing rolling window in class for multiple symbols.....second or third time people asking in a week :)

1

Ty! Will add tomorrow :)

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.


Thank you for the reply Michael and Jared.

Michael I looked at the code that you referenced above (EmaCrossUniverseSelectionAlgorithm.py) and I did not see how I could use the code to do what I need to do.

I want to look back at previous prices (OHLC) and indicators (SMA etc) for multiple stocks and or ETFs. And when the right conditions occur take a position or close a position at that time.

If there is some other way to do this I would really appreciate your thoughts.

Thank you for your time :).

0

you would need to add a rolling window in that class as you already know it

so you can look back to the values you added in the window.

thats a simpler example.....take a look....it holds info of some etfs:

https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/ETFGlobalRotationAlgorithm.py
0

Michael,

Will you please give me an example of how I would add a rolling window to the strategy.

Thank you.

0

Hi Michael and hal_trade, MultipleSymbolConsolidationAlgorithm python version has been added.

https://github.com/QuantConnect/Lean/pull/1505/commits/2b0937b36a7012505270e74a59e3cf939dc296b0
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 Jing Wu ......

one last hint:

when i copy the code in the lab it says : unexpected indent

here in line 94: 

+def OnEndOfDay(self):
+
+ i = 0
+ for symbol in sorted(self.Data.keys()):

but then after moving the for loop to the left:

Failed to initialize algorithm: Initialize(): Python.Runtime.PythonException: AttributeError : 'MultipleSymbolConsolidationAlgorithm' object has no attribute 'OnDataConsolidated'
at QuantConnect.AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper.Initialize () [0x00045] in <0c88b9ca11b74259bd317eba6892dda0>:0
at QuantConnect.Lean.Engine.Setup.BacktestingSetupHandler+<>c__DisplayClass19_0.<Setup>b__0 () [0x0007c] in <c118b4a93df0492aa91bee9d82a40e78>:0 (Open Stacktrace)

0

ok sorry the output was not well formated in github after clicking on raw:

Raw MultipleSymbolConsolidationAlgorithm.py

0


thanks Jing Wu for implementing it for Hal Trade 

everything works as expected :)

0

Jing Wu and Michael Manus I really appreciate your work.

Thank you for helping the community.

I will be working to implement this into my strategy.

0

Michael,  I cloned you algorithm above and when I run the backtest I get an error on the console:

Backtest Handled Error: Unable to submit order with id -10 which quantity (1) is less than lot size (1000).

What does this error mean?
 
 
0


the example has a problem....it buys every stock and currency of quantitiy 1 in his list. because of lot size quantitiy of 1000 has to be taken for buying a currency. thats why this example buys only stocks and gets order errors in the log for buying currencies.

0

the example above will not work anymore because of using the older python 2.7 which changed to 3.6:

self.SetStartDate(2014, 12, 01)

->

self.SetStartDate(2014, 12, 1)


for symbol, symbolData in self.Data.iteritems():

->

for symbol, symbolData in self.Data.items():
1

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