コード例 #1
0
 def _get_regime_one_line(self, date, date_1, date_2):
     
     # check parameters
     if len(self.parameters) != 1:
         raise CoreError('Error in parameter')
     
     # build the cache
     if 'line' not in self.cache:
         self.cache['line'] = []
     
     # check the cache
     if len(self.cache['line']) < 2:
         self.cache['line'].insert(0, self.instrument.get_adjusted_close_value(date))
         return Regime.FLAT
     
     # get filter input values
     current_value = self.instrument.get_adjusted_close_value(date)
     last_value = self.instrument.get_adjusted_close_value(date_1)
     before_value = self.instrument.get_adjusted_close_value(date_2)
     last_filter = self.cache['line'][0]
     before_filter = self.cache['line'][1]
     
     # compute filter
     if self.indicator_type == IndicatorType.BUTTERWORTH:
         current_filter = DigitalFilter.get_butterworth_lpf_value(self.parameters[0], current_value, last_value, before_value, last_filter, before_filter)
     elif self.indicator_type == IndicatorType.BESSEL:
         current_filter = DigitalFilter.get_bessel_lpf_value(self.parameters[0], current_value, last_value, before_value, last_filter, before_filter)
     elif self.indicator_type == IndicatorType.CHEBYSCHEV:
         current_filter = DigitalFilter.get_chebyschev_lpf_value(self.parameters[0], current_value, last_value, before_value, last_filter, before_filter)
     
     if self.building_type == BuildingType.ONE_LINE_SLOPE:
         slope = current_filter - last_filter
         current_regime = RegimeHelper.get_regime(self.building_type, date, line=slope)
     elif self.building_type == BuildingType.ONE_LINE_VALUE:
         current_regime = RegimeHelper.get_regime(self.building_type, date, line=current_filter, 
                                                  instrument=self.instrument.get_adjusted_close_value(date))
     
     # update cache
     self.cache['line'].pop()
     self.cache['line'].insert(0, current_filter)
     
     return current_regime
コード例 #2
0
    def testGetChebyschevLpf(self):
        time = range(500)
        fundamental = 8*arctan(1)/30
        noise = 8*arctan(1)/4
        
        input = time[:]
        for t in time:
            input[t]=cos(fundamental*t) + cos(noise*t)
            
        output = DigitalFilter.get_chebyschev_lpf(input, 20)

        self.assertEqual(len(input), len(output), 'good length')
        self.assertAlmostEqual(output[499], -1.15550766,msg='good Chebyschev') 
コード例 #3
0
    def testGetBesselLpf(self):
        time = range(500)
        fundamental = 8*arctan(1)/30
        noise = 8*arctan(1)/4
        
        input = time[:]
        for t in time:
            input[t]=cos(fundamental*t) + cos(noise*t)
            
        output = DigitalFilter.get_bessel_lpf(input, 20)

        self.assertEqual(len(input), len(output), 'good length')
        self.assertAlmostEqual(output[499], -0.94269355,msg='good Bessel')