Back

AddEquity from a List

Hi 

I'm trying to add equities ,from a predefined list which I've loaded. However ,no trades are made. I'd appreciate any assitance ,thanks.

 

from snp import snp #S&P 500 ticker list

    def Initialize(self):
        self.snp_list = self.AddEquity("AAPL", Resolution.Second).Symbol #Just initializing

def OnData(self, slice):
        if self._limitTicket is None:

            for i in range (0 ,99):
                    self._limitTicket = self.LimitOrder(self.snp_list,1,slice[snp[i]].Close * Decimal(0.9),"limit order")  #Buying

Update Backtest







It looks like only "AAPL" is being subscribed, however, limit orders are being created for 100 tickers, In the initialize method all equities to be traded should be subscribed. This can be done via a simple for-loop like the limit order for-loop above. Another issue could be that the limit order was constructed wrong. Switching the limit order into a market order will help to debug whether or not the orders are being constructed since there is no limit price and all trades will be executed. Might also be useful to use the self.Debug() method make sure the data from the predefined list is being accessed, I can't give any concrete suggestions since a complete algorithm is not provided. The information should help get you started. 

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 for the feedback Gurumeher .

"In the initialize method all equities to be traded should be subscribed. This can be done via a simple for-loop like the limit order for-loop above." Please explain?

This cannot be accomplished via a simple loop ,since I separate the Initialize from the OnData(self, slice).

It goes like this:

1) Initialize 

2) Some logic checks on my list 

3) Order on the subset list from #2.

I'm using the basic template provided by QC:

import numpy as np
from decimal import Decimal
from snp import snp

class BasicTemplateAlgorithm(QCAlgorithm):

    def Initialize(self):
        self._limitTicket = None
        self._stopMarketTicket = None
        self._stopLimitTicket = None
        self.SetCash(1000)
        self.SetStartDate(2018,7,16)
        self.SetEndDate(2018,7,16)
        self.snp_list = self.AddEquity("AAPL", Resolution.Second).Symbol
        #self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)
        
        
                    
        self.Schedule.On(self.DateRules.On(2018,7,13), self.TimeRules.At(9,30), Action(self.SpecificTime))
        
    ###Some Logic Here###

  
    def OnData(self, slice):
        if self._limitTicket is None:
                for i in range (0 ,99):
                    self._limitTicket = self.LimitOrder(self.snp_list,1,slice[snp[i]].Close * Decimal(0.9),"limit order")  #Buying
                    
            
 

0

You only have "self.AddEquity("AAPL") instead of all of the stocks in your snp list

Also you're setting a buy order at 90% of the current price which is unlikely to get filled because it requires the stock to go down 10%

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