Back

How can I handle split situation? like uvxy is reverse_split as 1:5

Hi, I wrote code to test UVXY.  Here is my code:

it is very simple, but, UVXY is reverse_split as 1:5. When I short it on Friday, I short 100 shares, then when I bought back on Monday, it should be 20 shares cause, it has been rs. But, the log shows that I bought 100. .. this is the log


namespace QuantConnect 
{   

    public class BasicTemplateAlgorithm : QCAlgorithm
    {
        
        private  string symbol = "UVXY";
        private  int quantity=100;
        private  int trigger=0;
        //movingaveragealgorithm emafast=new movingaveragealgorithm(10);
        //movingaveragealgorithm emaslow=new movingaveragealgorithm(50);
        //MovingAverageConvergenceDivergence _macd;

        
   public override void Initialize()
        {
            SetStartDate(2016, 07, 22);
            SetEndDate(2016, 07, 27);
            SetCash(30000);
            AddSecurity(SecurityType.Equity, symbol, Resolution.Daily);
            
            Securities["UVXY"].SetDataNormalizationMode(DataNormalizationMode.SplitAdjusted);

            Schedule.On(DateRules.Every(DayOfWeek.Friday), TimeRules.AfterMarketOpen("UVXY",0), () =>
            {
                trigger=-1;
                Log(Time.ToString()+"");
            });
            
           Schedule.On(DateRules.Every(DayOfWeek.Monday), TimeRules.BeforeMarketClose("UVXY",0), () =>
            {
                trigger=1;
                Log(Time.ToString()+"");
            });
         
         
         }

        public void OnData(TradeBars data) 
        {  
            Log(Time.ToString()+"\t"+Securities["UVXY"].Close);
            Log(Portfolio["UVXY"].Quantity+"cdd");

            if(trigger==-1&&!Portfolio.HoldStock)
            {
                Order(symbol, -quantity);
                Log(Time.ToString()+"\t"+"short "+quantity);
            }
            else if(trigger==1&&Portfolio.HoldStock)
            {
                Log(Portfolio["UVXY"].Quantity+"abb");
                Order(symbol,quantity);
                Log(Time.ToString()+"\t"+"close "+quantity);
                

            }
            
        
            
        }
    }
}

Update Backtest








I am trying to understand if it is a bug or not. Tipically ApplySplit(..) event is triggered on a share split or reverse split event. all BrokeragesModels implement  when the split is trigered by Broker.
Anyway, there was in fact a UVXY Split on the 25, and the Splits event should be triggered in the Algorithm, but by some reasons is not..

public void OnData(Splits splits)
{
Split split = splits["UVXY"];
Debug("## Split >> Split factor: "+split.SplitFactor);
}

Later i will try to debug LEAN, in order to understand better how Splits are being triggered by BrokerageModel classes. Hope i can help you

0


Something might be wrong related with this security itself. Same code working for other security doesnt work for UVXY. I picked up IUSG just because had split on same day as UVXY.

0


Hi @Lifan, @Marco; this is an issue with the daily update data coming from QuantQuote since the last split. We've notified QuantQuote and the data will update with the fixed factor file shortly. 

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.


Correct its trick Michael. Indicators don't work well with raw data. You'll need to bind to the OnData(Split) event and reset your indicators or normalize the price for your indicators in your algorithm.

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