예제 #1
0
 def __init__(self):
     self.indicator = Indicator(function_restart=self.restart,
                                function_pause=self.stop,
                                function_quit=self.quit,
                                icon_default=config.icon_default,
                                icon_paused=config.icon_paused)
     self.process = None
     self.thread = None
     self.state_lock = threading.Lock()
     self.state = Syndicator.STATE_PAUSED
     '''
     self.BackUpProcess = ExternalProcess(
         command=config.backup_command,
         recognized_patterns=config.backup_patterns,
         icon_working=config.backup_icon_working,
         report_status = self.indicator.new_status,
         report_error= self.indicator.new_error,
         report_file = self.indicator.new_file,
         report_notification = self.indicator.new_notification
     )  
     '''
     self.SyncProcess = ExternalProcess(
         command=config.sync_command,
         recognized_patterns=config.sync_patterns,
         icon_working=config.sync_icon_working,
         report_status=self.indicator.new_status,
         report_error=self.indicator.new_error,
         report_file=self.indicator.new_file,
         report_notification=self.indicator.new_notification)
 def __init__(self):
     # init process
     Indicator.__init__(
         self,
         identifier="TriageTime", #the same as the file name
         version = "1.0",
         title="Triage Time",
         abstract="Time interval from first to last triage")
 def __init__(self):
     # init process
     Indicator.__init__(
         self,
         identifier="TreatmentTime", #the same as the file name
         version = "1.0",
         title="Treatment Time",
         abstract="First to last treatment")
예제 #4
0
 def __init__(self):
     # init process
     Indicator.__init__(
         self,
         identifier="OverallTime", #the same as the file name
         version = "1.0",
         title="Overall time",
         abstract="Reference time to last transport")
예제 #5
0
def initHUD():
    Indicator.HUDs["score"] = Indicator(conf.screen, conf.gameFont, "Score",
                                        (10, 10))
    Indicator.HUDs["player"] = Indicator(conf.screen, conf.gameFont,
                                         "player {0}", (10, 30))
    Indicator.HUDs["computer"] = Indicator(conf.screen, conf.gameFont,
                                           "computer {0}", (10, 50))
    Indicator.HUDs["move"] = Indicator(conf.screen, conf.gameFont,
                                       "move {0}, remaining steps {1}",
                                       (300, 10))
예제 #6
0
 def __init__(self):
     self.indicator = Indicator(function_restart=self.restart,
                                function_pause=self.stop,
                                function_quit=self.quit,
                                icon_default=config.icon_default,
                                icon_paused=config.icon_paused)
     self.process = None
     self.thread = None
     self.state_lock = threading.Lock()
     self.state = Syndicator.STATE_PAUSED
     self.BackUpProcess = ExternalProcess(
         command=config.backup_command,
         recognized_patterns=config.backup_patterns,
         icon_working=config.backup_icon_working,
         report_status = self.indicator.new_status,
         report_error= self.indicator.new_error,
         report_file = self.indicator.new_file,
         report_notification = self.indicator.new_notification
     )            
     self.SyncProcess = ExternalProcess(
         command=config.sync_command,
         recognized_patterns=config.sync_patterns,
         icon_working=config.sync_icon_working,
         report_status = self.indicator.new_status,
         report_error= self.indicator.new_error,
         report_file = self.indicator.new_file,
         report_notification = self.indicator.new_notification
     )
예제 #7
0
    def moving_average_model(self,data):

        data_len = len(data)

        indicator = Indicator()
        ema = indicator.exponential_moving_average(data)
        
        data_ema_diff = [data[i] - ema[i - 12] for i in range(12,data_len)]

        data_ema_diff.sort()

        mu = np.mean(data_ema_diff[10:-10])
        sigma = np.std(data_ema_diff[10:-10])

        pred_price = ema[-1] + (mu + sigma * np.randn())

        return pred_price
예제 #8
0
    def cal_fitness_MACD(self, pop, df):
        calpop = []
        for cm in pop:

            df = Indicator().MACD(df, cm[0][0], cm[0][1], cm[0][2])
            b = df.loc[(df['MACD'] > df['SIGNAL LINE']) & (
                df['MACD'].shift() < df['SIGNAL LINE'].shift())]['Close']
            bd = df.loc[(df['MACD'] > df['SIGNAL LINE']) &
                        (df['MACD'].shift() < df['SIGNAL LINE'].shift())].index
            s = df.loc[(df['MACD'] < df['SIGNAL LINE']) & (
                df['MACD'].shift() > df['SIGNAL LINE'].shift())]['Close']
            sd = df.loc[(df['MACD'] < df['SIGNAL LINE']) &
                        (df['MACD'].shift() > df['SIGNAL LINE'].shift())].index
            b, bd, s, sd = b.tolist(), bd.tolist(), s.tolist(), sd.tolist()

            money = 10000

            if len(b) == 0 or len(s) == 0:
                calpop.append([cm[0], 0])
            else:
                if bd[0] > sd[0]:
                    s.pop(0)
                    sd.pop(0)
                if len(b) > len(s):
                    b.pop()
                    bd.pop()

                pfmacd = []
                profitmacd = []
                for i in range(len(b)):
                    pfmacd.append(((s[i] - b[i])))
                    profitmacd.append(((s[i] - b[i]) / (b[i])))
                pfmacd = sum(pfmacd)
                # print(len(bd),len(sd))
                calpop.append([cm[0], pfmacd])
        return calpop
예제 #9
0
class Syndicator:
    STATE_PAUSED = 0
    STATE_RUNNING = 1
    
    def __init__(self):
        self.indicator = Indicator(function_restart=self.restart,
                                   function_pause=self.stop,
                                   function_quit=self.quit,
                                   icon_default=config.icon_default,
                                   icon_paused=config.icon_paused)
        self.process = None
        self.thread = None
        self.state_lock = threading.Lock()
        self.state = Syndicator.STATE_PAUSED
        self.BackUpProcess = ExternalProcess(
            command=config.backup_command,
            recognized_patterns=config.backup_patterns,
            icon_working=config.backup_icon_working,
            report_status = self.indicator.new_status,
            report_error= self.indicator.new_error,
            report_file = self.indicator.new_file,
            report_notification = self.indicator.new_notification
        )            
        self.SyncProcess = ExternalProcess(
            command=config.sync_command,
            recognized_patterns=config.sync_patterns,
            icon_working=config.sync_icon_working,
            report_status = self.indicator.new_status,
            report_error= self.indicator.new_error,
            report_file = self.indicator.new_file,
            report_notification = self.indicator.new_notification
        )
        #self.BackUpProcess = DummyProcess.Sync(self.indicator.queue)
        #self.SyncProcess = DummyProcess.Sync(self.indicator.queue)

    def main(self):
        self.start()
        Gtk.main()

    def quit(self, source):
        #There's currently no way to invoke this function!
        self.stop(source) 
        self.indicator.quit()
        Gtk.main_quit()
        print "Syndicator:  Gtk has quit."
                
    def start(self):
        self.state_lock.acquire()
        self.state = Syndicator.STATE_RUNNING
        self.state_lock.release()
        self.indicator.start()
        self.thread = threading.Thread(target=self.__run, args=())       
        self.thread.daemon = True
        self.thread.start()

    def restart(self,source):
        self.stop(source)
        self.start()

    def stop(self,source):
        print "Syndicator:  Stopping all ..."
        self.state_lock.acquire()
        self.state = Syndicator.STATE_PAUSED
        self.indicator.pause()
        self.BackUpProcess.abort()
        self.SyncProcess.abort()
        self.state_lock.release()
        
        if self.thread:
            if self.thread.isAlive():
                self.thread.join()
                print "Syndicator:  The thread for running subprocesses has joined the main thread."
            self.thread = None 


    def __run(self): # executed in separate thread
        if self.BackUpProcess.run() == 0:
            MIN_WAIT = 2   # two seconds
            MAX_WAIT = 300 # five minutes
            wait_time = MIN_WAIT
            while self.state==Syndicator.STATE_RUNNING: 
                start_time = time.time()
                self.SyncProcess.run()
                elapsed_time = time.time() - start_time
                wait_time = (2-elapsed_time/100)*wait_time
                wait_time = min(max(wait_time,MIN_WAIT),MAX_WAIT)
                self.__count_down(wait_time)

    def __count_down(self,seconds):
        while seconds > 0 and self.state==Syndicator.STATE_RUNNING:
            seconds = seconds - 1
            time.sleep(1)
            self.indicator.new_status("Restarting in %d seconds ..." %seconds)
예제 #10
0
파일: Square.py 프로젝트: ankan5415/PyChess
 def addIndicator(self):
     self.indicator = Indicator(center = self.center)
예제 #11
0
    df.loc[(df['Trend'] == 'Down') | (df['Ntrend'] == 'Down'),
           'Trading Signal'] = (
               (abs(df['Close'] - df[['Close', 'S1', 'S2']].min(axis=1)) /
                abs(df[['Close', 'S1', 'S2']].max(axis=1) -
                    df[['Close', 'S1', 'S2']].min(axis=1))) * 0.5)

    df.loc[df['Trend'].isnull(), 'Trend'] = df['Ntrend']

    df = df.drop(['Ntrend', 'S1', 'S2'], axis=1)

    return df


datalist = [f for f in glob.glob("Dataset2/*.csv")]
print('have stock = ', len(datalist))
indicator = Indicator()
for i in range(30, 35):
    df = pd.read_csv(datalist[i])
    df = MACD(df, 24, 36, 24)  #default 12,26,9
    df = DMI(df, 60)  #default 14
    df = indicator.MA(df, 15)
    df = check_trend(df)
    df['MACD-SL'] = df['MACD'] - df['SIGNAL LINE']
    df['DMI'] = df['plusDI'] - df['minusDI']
    # df = norm(df,'Close')
    # df = indicator.ATR(df)

    df.loc[df['Signal'] == 'buy', 'Signal'] = 0
    df.loc[df['Signal'] == 'sell', 'Signal'] = 1
    df.loc[df['Signal'] == 'wait or hold', 'Signal'] = 2
예제 #12
0
class Syndicator:
    STATE_PAUSED = 0
    STATE_RUNNING = 1

    def __init__(self):
        self.indicator = Indicator(function_restart=self.restart,
                                   function_pause=self.stop,
                                   function_quit=self.quit,
                                   icon_default=config.icon_default,
                                   icon_paused=config.icon_paused)
        self.process = None
        self.thread = None
        self.state_lock = threading.Lock()
        self.state = Syndicator.STATE_PAUSED
        '''
        self.BackUpProcess = ExternalProcess(
            command=config.backup_command,
            recognized_patterns=config.backup_patterns,
            icon_working=config.backup_icon_working,
            report_status = self.indicator.new_status,
            report_error= self.indicator.new_error,
            report_file = self.indicator.new_file,
            report_notification = self.indicator.new_notification
        )  
        '''
        self.SyncProcess = ExternalProcess(
            command=config.sync_command,
            recognized_patterns=config.sync_patterns,
            icon_working=config.sync_icon_working,
            report_status=self.indicator.new_status,
            report_error=self.indicator.new_error,
            report_file=self.indicator.new_file,
            report_notification=self.indicator.new_notification)
        #self.BackUpProcess = DummyProcess.Sync(self.indicator.queue)
        #self.SyncProcess = DummyProcess.Sync(self.indicator.queue)

    def main(self):
        self.start()
        Gtk.main()

    def quit(self, source):
        #There's currently no way to invoke this function!
        self.stop(source)
        self.indicator.quit()
        Gtk.main_quit()
        print("Syndicator:  Gtk has quit.")

    def start(self):
        self.state_lock.acquire()
        self.state = Syndicator.STATE_RUNNING
        self.state_lock.release()
        self.indicator.start()
        self.thread = threading.Thread(target=self.__run, args=())
        self.thread.daemon = True
        self.thread.start()

    def restart(self, source):
        self.stop(source)
        self.start()

    def stop(self, source):
        print("Syndicator:  Stopping all ...")
        self.state_lock.acquire()
        self.state = Syndicator.STATE_PAUSED
        self.indicator.pause()
        #self.BackUpProcess.abort()
        self.SyncProcess.abort()
        self.state_lock.release()

        if self.thread:
            if self.thread.isAlive():
                self.thread.join()
                print(
                    "Syndicator:  The thread for running subprocesses has joined the main thread."
                )
            self.thread = None

    def __run(self):  # executed in separate thread
        MIN_WAIT = 2  # two seconds
        MAX_WAIT = 300  # five minutes
        wait_time = MIN_WAIT
        while self.state == Syndicator.STATE_RUNNING:
            start_time = time.time()
            self.SyncProcess.run()
            elapsed_time = time.time() - start_time
            wait_time = (2 - elapsed_time / 100) * wait_time
            wait_time = min(max(wait_time, MIN_WAIT), MAX_WAIT)
            self.__count_down(wait_time)

    '''
    def __run(self): # executed in separate thread
        backupsuccess = self.BackUpProcess.run()
        if backupsuccess == 0 or backupsuccess == 1: 
            # allow backupsuccess == 1 because of bug in backintime 1.1.24
            # see https://github.com/bit-team/backintime/issues/906
            MIN_WAIT = 2   # two seconds
            MAX_WAIT = 300 # five minutes
            wait_time = MIN_WAIT
            while self.state==Syndicator.STATE_RUNNING: 
                start_time = time.time()
                self.SyncProcess.run()
                elapsed_time = time.time() - start_time
                wait_time = (2-elapsed_time/100)*wait_time
                wait_time = min(max(wait_time,MIN_WAIT),MAX_WAIT)
                self.__count_down(wait_time)
    '''

    def __count_down(self, seconds):
        while seconds > 0 and self.state == Syndicator.STATE_RUNNING:
            seconds = seconds - 1
            time.sleep(1)
            self.indicator.new_status("Restarting in %d seconds ..." % seconds)
예제 #13
0
    return reader.data


def analyst_data(data):
    # 分析数据质量
    data_manager = DataManager()
    data_manager.data_analyst(data)


if __name__ == '__main__':
    # my_data = read_future_data()
    my_data = read_stock_data()
    # 计算指标
    analyst = IndicatorAnalyst(my_data)
    # analyst.indicator = Indicator().mt4_rsi(my_data, 14, 'close')
    analyst.indicator = Indicator(data_set=my_data,
                                  applied_price='close').i_bias(24)
    # 分组统计分析
    # analyst.interval_analyst(lambda x: True if x < 0.35 else False, symbol={'XAUUSD': Symbol("XAUUSD", 0.55)},
    #                          group_plot=True)
    # analyst.interval_analyst(lambda x: True if x < 0.35 else False,
    #                          symbol={"i1601": Symbol("i1601", 0.5, size_value=100, symbol_type=FUTURE_TYPE,
    #                                                  open_cost_rate=0.0001, close_cost_rate=0.0001),
    #                                  "rb1601": Symbol("i1601", 0.5, size_value=10, symbol_type=FUTURE_TYPE,
    #                                                   open_cost_rate=0.0001, close_cost_rate=0.0001)},
    #                          profit_mode=True,
    #                          group_plot=True)
    analyst.interval_analyst(lambda x: True if x < 0.35 else False,
                             symbol={
                                 "600597":
                                 Symbol("600597",
                                        0.0,
예제 #14
0
    if name == '!':
        break
    print('Start Date')
    sy, sm, sd = map(int, input('Y,M,D :').split(','))
    print('End Date')
    ey, em, ed = map(int, input('Y,M,D :').split(','))
    stocklist.append([name, [sy, sm, sd], [ey, em, ed]])
print(stocklist)
for stock in stocklist:
    try:
        st1, st2, st3 = stock[1][0], stock[1][1], stock[1][2]
        ed1, ed2, ed3 = stock[2][0], stock[2][1], stock[2][2]
        start = datetime.datetime(st1 - 3, st2, st3)
        end = datetime.datetime(ed1, ed2, ed3)
        df = web.DataReader(stock[0], 'yahoo', start, end)
        df = Indicator().MACD(df, 49, 57, 53)
        df = Indicator().DMI(df, 48)
        df = Indicator().RSI(df)
        df = Indicator().WILLIANSR(df)
        df = Indicator().STOCHASTIC(df)
        df['STOCH'] = df['%K'] - df['%D']
        df['MACD-SL'] = df['MACD'] - df['SIGNAL LINE']
        df['DMI'] = df['plusDI'] - df['minusDI']

        #MACD
        df = norm(df, 'MACD')
        df = norm(df, 'SIGNAL LINE')
        df = norm(df, 'MACD-SL')
        #DMI
        df = norm(df, 'plusDI')
        df = norm(df, 'minusDI')
예제 #15
0
 def create_indicator(self, veromix):
     self.tray_icon = Indicator(veromix)
예제 #16
0
def main():
    screen = pygame.display.set_mode((800, 600))
    screen.fill((255, 255, 255))
    mode = 'red'

    tool = 'pencil'
    draw_on = False
    last_pos = (0, 0)
    color = (255, 128, 0)
    radius = 10
    ind = Indicator()
    colors = {
        'red': (255, 0, 0),
        'orange': (255, 128, 0),
        'yellow': (255, 255, 0),
        'green': (0, 255, 0),
        'light_blue': (0, 255, 255),
        'blue': (0, 0, 255),
        'violet': (76, 0, 153),
        'white': (255, 255, 255)
    }
    pygame.display.update()
    while True:

        pressed = pygame.key.get_pressed()
        alt_held = pressed[pygame.K_LALT] or pressed[pygame.K_RALT]
        ctrl_held = pressed[pygame.K_LCTRL] or pressed[pygame.K_RCTRL]

        for event in pygame.event.get():
            # quit game
            if event.type == pygame.QUIT:
                return
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_w and ctrl_held:
                    return
                if event.key == pygame.K_1:
                    tool = 'pencil'
                if event.key == pygame.K_2:
                    tool = 'erasor'
                    mode = 'white'
                if event.key == pygame.K_3:
                    tool = 'rectangle'
                if event.key == pygame.K_4:
                    tool = 'circle'
                if event.key == pygame.K_r:
                    mode = 'red'
                if event.key == pygame.K_b:
                    mode = 'blue'
                if event.key == pygame.K_g:
                    mode = 'green'
                if event.key == pygame.K_y:
                    mode = 'yellow'
                if event.key == pygame.K_v:
                    mode = 'violet'
                if event.key == pygame.K_o:
                    mode = 'orange'
                if event.key == pygame.K_a:
                    mode = 'light_blue'

                if event.key == pygame.K_s:
                    rect = pygame.Rect(0, 100, 800, 500)
                    sub = screen.subsurface(rect)
                    pygame.image.save(sub, 'pic.png')

                if event.key == pygame.K_UP:
                    radius += 1
                if event.key == pygame.K_DOWN:
                    radius -= 1

            if event.type == pygame.MOUSEBUTTONDOWN:
                color = colors[mode]
                if tool == 'circle':
                    pygame.draw.circle(screen, color, event.pos, radius)
                if tool == 'rectangle':
                    pygame.draw.rect(
                        screen, color,
                        (event.pos[0], event.pos[1], radius * 2, radius * 2))
                draw_on = True
            if event.type == pygame.MOUSEBUTTONUP:
                draw_on = False
            if event.type == pygame.MOUSEMOTION:
                if draw_on:
                    if tool == 'pencil':
                        pygame.draw.line(screen, color, last_pos, event.pos,
                                         radius)
                    if tool == 'erasor':
                        pygame.draw.rect(screen, color,
                                         (event.pos[0], event.pos[1],
                                          radius * 2, radius * 2))
                    if tool == 'circle':
                        drawLine_for_circle(screen, last_pos, event.pos,
                                            radius, color)
                    if tool == 'rectangle':
                        pygame.draw.rect(screen, color,
                                         (event.pos[0], event.pos[1],
                                          radius * 2, radius * 2))
                last_pos = event.pos
        screen.fill((255, 255, 255), (0, 0, 800, 100))
        ind.draw(screen, colors[mode])
        show_tool(100, 25, tool, screen)
        if tool == 'erasor':
            show_color(100, 50, '-', screen)
        else:
            show_color(100, 50, mode, screen)
        if radius <= 0:
            radius = 0
        show_radius(100, 75, radius, screen)
        pygame.display.flip()
    pygame.quit()