Ejemplo n.º 1
0
        symbols = ''
        lhb_sets = self.clinet.run_crawler_lhb(self.__end_date)
        for lhb in lhb_sets:
            signal, symbol = self.__strategy.on_lhb_event(lhb_sets[lhb], self.__end_date)
            print (signal, symbol)
            if signal:
                symbols += '\''
                symbols += symbol[2:len(symbol)]
                symbols += '\''
                symbols += ','
                # stock_sets.append(symbol)
        df = self.get_symbol_info(symbols[0:-1])
        df['TRADEDATE'] = self.__end_date
        df = df.rename(columns={'SYMBOL':'股票代码','KEYNAME':'板块','SESNAME':'股票名称','TRADEDATE':'交易日'})
        df.to_html(str(self.__end_date) + '.html') 

    def get_symbol_info(self, symbols):
        sql_pe = 'select B.SYMBOL,C.KEYNAME,B.SESNAME from TQ_SK_BASICINFO AS B JOIN TQ_COMP_BOARDMAP AS C ON  B.SECODE = C.SECODE where B.SYMBOL in (' + str(symbols) + ') and SETYPE = \'101\' AND (C.KEYCODE = \'GE002\' or C.KEYCODE = \'SZ002\' or C.KEYCODE = \'MB001\')'
        print sql_pe
        data_engine = GetDataEngine('DNDS')
        df = pd.read_sql(sql_pe, data_engine)
        return df


if __name__ == "__main__":
    reload(sys)
    sys.setdefaultencoding('utf8')
    MLog.config(name='nirvana_run')
    nirvana_run = NirvanaRun()
    nirvana_run.start()
Ejemplo n.º 2
0
        self.__history_file = OrderedDict(
            sorted(self.__history_file.items(), key=lambda t: t[0]))
        # for key,value in self.__history_file.items():
        #    print (key,value)

    def run_loop_back(self):
        for mkdate, file in self.__history_file.items():
            print file
            data = pd.read_csv(file)
            for index in data.index:
                self.__on_bar(data.loc[index].values)
            self.__strategy.record()

    def calc_result(self):
        self.__strategy.calc_result()

    def save(self):
        self.__strategy.save()


if __name__ == '__main__':
    MLog.config(name="look_back")
    lb = LoopBack()
    lb.set_symbol('ag')
    # lb.load_history_data('./../fc/data/out_dir/ag/ag2017/ag0001_20171121.csv')
    lb.load_history_dir('./../fc/data/out_dir/ag/ag2017/')
    lb.run_loop_back()
    # print('<----------------------------------->')
    lb.calc_result()
    # lb.save()
Ejemplo n.º 3
0
            end_date)
        MLog.write().info('%s' % (url))
        lhb_detail_obj = json.loads(self.__client.request(url))
        if lhb_detail_obj is None:
            return None
        lhb_detail = lhb_detail_obj.get('detail')
        if lhb_detail is None:
            return None
        return lhb_detail

    def run_crawler_lhb(self, end_date):
        lhb_dict = {}
        url = self.__base_list + '?date=' + str(end_date)
        MLog.write().info('%s' % (url))
        lhb_obj = json.loads(self.__client.request(url))
        lhb_list = lhb_obj.get('list')
        if lhb_list is None:
            return
        for lhb in lhb_list:
            symbol = lhb.get('symbol')
            detail = self.run_crawler_lhb_detail(symbol, end_date)
            if detail:
                lhb_dict[symbol] = detail
        return lhb_dict


if __name__ == "__main__":
    MLog.config(name='xq_cralwer')
    client = XQLHBClient(20070704, 20091231)
    client.crawler_lhb()
Ejemplo n.º 4
0
                # 推送给策略,对持仓做操作,A股市场T+1,可当天卖当天买,不能当天买再当天卖
                MLog.write().debug('push daily_price strategy========>')
                self.__strategy.on_market_data(date, daily_price_list)
                # 读取行情,撮合成交
                MLog.write().debug('cross_limit_order ========>')
                self.cross_limit_order(date, daily_price_list)
                # self.__working_limit_order.clear() # 是否清理掉当天的委托单
                # 当天结算
                MLog.write().debug('today calc settle=========>')
                self.__strategy.calc_settle(date, daily_price_list)
            # 计算当日龙虎榜
            MLog.write().debug('cal today lhb =========>')
            if self.history_file.has_key(date):
                lhb_set = self.history_file[date]
                self.__loop_back(date, lhb_set)
            MLog.write().debug('\n')

    def calc_result(self):
        self.__strategy.calc_result()


if __name__ == '__main__':
    reload(sys)
    sys.setdefaultencoding('utf8')
    MLog.config(name='nirvana')
    lb = LookBack(20170104, 20180105)
    # lb.init_st_stock('./file/market_st.csv')
    lb.init_read_lhb('../../data/nirvana/xq/')
    lb.start()
    lb.calc_result()