示例#1
0
    def Update(self, algorithm, changes):
        ''' Creates an insight for each security based on the alphabetical
        value of its symbol
        Returns:
            The new insights generated'''

        algorithm.Debug('update: ' + str(changes))

        insights = []

        for security in self.securities:
            first_letter = str(security.Symbol)[0]
            second_letter = str(security.Symbol)[1]

            # insight parameters based on symbol letters
            direction = InsightDirection.Up if ord(first_letter) > ord('M') else InsightDirection.Down
            magnitude = float(ord(first_letter)) / float(ord('Z'))
            confidence = float(ord(second_letter)) / float(ord('Z'))

            insight = Insight(
                security.Symbol,
                timedelta(minutes=10),
                InsightType.Price,
                direction,
                magnitude,
                confidence,
            )
            #self.EmitInsights(insight)
            insights.append(insight)

        return insights
示例#2
0
 def Update(self, algorithm, data):
     ''' Creates a constant insight for each security as specified via the constructor
     Args:
         algorithm: The algorithm instance
         data: The new data available
     Returns:
         The new insights generated'''
     for security in self.securities:
         if self.ShouldEmitInsight(algorithm.UtcTime, security.Symbol):
             yield Insight(security.Symbol, self.period, self.type,
                           self.direction, self.magnitude, self.confidence)
示例#3
0
    def Update(self, algorithm, data):

        insights = [] # list to store the new insights to be created
        
        # loop through securities and generate insights
        for security in self.securities:
            # check if there's new data for the security or we're already invested
            # if there's no new data but we're invested, we keep updating the insight since we don't really need to place orders
            if data.ContainsKey(security.Symbol) or algorithm.Portfolio[security.Symbol].Invested:
                # append the insights list with the prediction for each symbol
                insights.append(Insight.Price(security.Symbol, self.insightExpiry, self.insightDirection))
            else:
                algorithm.Log('(Alpha) excluding this security due to missing data: ' + str(security.Symbol.Value))
            
        return insights
    def Update(self, algorithm, data):
        ''' Creates a constant insight for each security as specified via the constructor
        Args:
            algorithm: The algorithm instance
            data: The new data available
        Returns:
            The new insights generated'''
        insights = []

        for security in self.securities:
            # security price could be zero until we get the first data point. e.g. this could happen
            # when adding both forex and equities, we will first get a forex data point
            if security.Price != 0 and self.ShouldEmitInsight(
                    algorithm.UtcTime, security.Symbol):
                insights.append(
                    Insight(security.Symbol, self.period, self.type,
                            self.direction, self.magnitude, self.confidence))

        return insights