Back

MeanReversionLunchBreakAlpha question

Looking at this Alpha looks like th goal is to return between the close of the previous day to 12:00 the day after. So total 3 days. But when I look at the code that gets the history it gets historical data for only 1 day which would be just previous day like here -  

                var history = algorithm.History(symbols, 1, _resolution); // My question is should this be for 2 days instead ?.History(symbols, 2, _resolution);
                if (symbols.Count() > 0 && history.Count() == 0)
                {
                    algorithm.Debug($"No data on {algorithm.Time}");
                }

                history.PushThrough(bar =>
                {
                    SymbolData symbolData;
                    if (!_symbolDataBySymbol.TryGetValue(bar.Symbol, out symbolData))
                    {
                        symbolData = new SymbolData(bar.Symbol, _predictionInterval);
                    }
                    symbolData.Update(bar.EndTime, bar.Price);
                    _symbolDataBySymbol[bar.Symbol] = symbolData;
                });

Also SMA is for 3 days as below - 

// Mean value of returns for magnitude prediction
                private readonly SimpleMovingAverage _meanOfPriceChange = new RateOfChangePercent(1).SMA(3);
                // Price change from close price the previous day
                private readonly RateOfChangePercent _priceChange = new RateOfChangePercent(3);
 

 

 

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.


-> history = history.close.unstack(level = 0)

what is the purpose of unstack(level = 0)

also is there a way to plot _meanOfPriceChange ?

I tried it like this - 

public class MeanReversionLunchBreakAlpha : QCAlgorithm
    {

   static private readonly SimpleMovingAverage _meanOfPriceChange1 = new RateOfChangePercent(1).SMA(3);
        // Price change from close price the previous day
   static private readonly RateOfChangePercent _priceChange1 = new RateOfChangePercent(3);

        public void OnAlgorithmEnd()
        {
            Plot("Strategy Equity", "_meanOfPriceChange1", _meanOfPriceChange1.RollingSum);
            Plot("Strategy Equity", "_priceChange1", _priceChange1.RollingSum);
        }

                public bool Update(DateTime time, decimal value)
                {
                    _meanOfPriceChange1.Update(time, value);
                    _priceChange1.Update(time, value);

0

Hey Manoj,

In Python with the pandas library, the unstack and stack methods lets you pivot your dataframe. unstack turns index values into column names. There are some examples on how this works in the pandas documentation.

When you are plotting indicators, you need to plot them every timestamp to a get a continuous graph. You should plot the current value of _meanOfPriceChange in the Update method.

Plot("Strategy Equity", "_meanOfPriceChange1", _meanOfPriceChange1.Current.Value);


>>My question is should this be for 2 days instead ?.History(symbols, 2, _resolution);

It's hard to understand without the full algorithm what is going on. But if this is MeanReversionLunchBreakAlphaModel.cs from the Lean repository, the resolution is in hours. We use 1 hour because the time period between 9:30 am and 12:00 pm, when our insights are first emitted, will be a sufficient amount of time to prime our indicators.

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 Rahul , Thanks for answering my questions , appreciate it!. Thats right , I am referring to the MeanReversionLunchBreakAlphaModel.cs from the Lean repository. Trying to understand what is going on.

Specifically this code below, it looks like we have a period 3 days here. Is it 3 days to account for weekends ?, as we are looking for price change from close price the previous day? 

private readonly RateOfChangePercent _priceChange = new RateOfChangePercent(3);

Also I want to know for the below code , on why we have RateOfChangePercent(1/* this value as 1*/ ).SMA(3 /* and this value as 3*/ );

private readonly SimpleMovingAverage _meanOfPriceChange = new RateOfChangePercent(1).SMA(3);

0

Hey Manoj,

The period is not 3 days, it is 3 data points. When defining a Indicator with no symbol or resolution, like RateOfChangePercent(3), the 3 represents the number of bars of the resolution of the universe. In this case since the universe resolution is hour, the indicator represents 3 hours of data.

>> Also I want to know for the below code , on why we have RateOfChangePercent(1/* this value as 1*/ ).SMA(3 /* and this value as 3*/ );

_meanOfPriceChange represents the 3 period simple moving average of the 1 period rate of change. The RateOfChangePercent(1) calculates the returns for each bar. And the SMA(3) calculates the average of those returns over the past 3 bars.

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