Exemplo n.º 1
0
def do_save_basics_pre(share_code, time_to_market):
    engine = DBUtils.db_connection()
    cur_date = Utils.get_current_date()
    change_time = time_to_market
    while change_time < cur_date:
        next_year = Utils.get_next_year(change_time)
        logger.debug('prepare to save next time range data....change_time=' +
                     str(change_time) + 'next_year=' + str(next_year))
        DBUtils.save_stock_h_data(engine, share_code, change_time, next_year)
        change_time = Utils.get_next_day(Utils.get_next_year(change_time))
Exemplo n.º 2
0
    def sell_share(self, share_numbers, share_price):
        if self.is_enough_shares() is True:
            return

        self.ware_house += share_numbers * share_price
        self.share_value -= share_numbers * share_price
        self.share_numbers -= share_numbers
        self.counter = self.counter - 1
        self.last_kick = 'sell'
        self.last_kick_day = Utils.get_current_date()
Exemplo n.º 3
0
 def __init__(self, ware_house, share_code):
     self.ware_house = ware_house
     self.share_code = share_code
     self.share_value = 0
     self.share_price = 0
     self.share_numbers = 0
     self.counter = 0
     self.last_kick = 'buy/sell'
     self.last_kick_day = Utils.get_current_date()
     '''logger配置'''
     logging.config.fileConfig('logging.conf')
     self.logger = logging.getLogger(__name__)
Exemplo n.º 4
0
    def buy_share(self, buy_value, share_price):
        is_have = self.is_enough_money(buy_value)
        '''检查持仓货币是否足够,如果不足够提示退出'''
        if is_have is not True:
            print("Error!!!, There is not enough money to buy shares")
            return False
        if self.last_kick == 'buy':
            trigger = (self.share_price - share_price) / self.share_price
            if trigger < 0.05:
                self.logger.info('Not to trigger to buy')
                return False
        # price_trigger=round(self.share_price*0.91,2)
        # if share_price > price_trigger and self.share_value!=0:
        #     print("Error!!! Not have to trigger the 0.91 line!")
        #     return False
        '''购买股票,向下取整'''
        cur_share_numbers = (buy_value // (share_price * 100)) * 100
        self.counter = self.counter + 1
        self.ware_house -= cur_share_numbers * share_price
        self.last_kick = 'buy'
        self.last_kick_day = Utils.get_current_date()
        '''
           计算持仓成本
           STEP1:计算持仓股票当前市值 当前价格*持有数量
           STEP2:本次购买市值  当前价格*本次购买数量
           STEP3:计算平均成本  (持仓市值+本次购买市值)/持有数量
        '''
        # tmp_price=(self.share_value + cur_share_numbers * share_price) / (self.share_numbers + cur_share_numbers)

        self.share_value += cur_share_numbers * share_price
        pre_buy_value = self.share_price * self.share_numbers
        self.share_numbers += cur_share_numbers
        self.share_price = round(
            (pre_buy_value + cur_share_numbers * share_price) /
            self.share_numbers, 2)
        # self.share_price = round(self.share_value / self.share_numbers, 2)

        return cur_share_numbers
Exemplo n.º 5
0
def get_current_boll(share_code, start_date):
    return get_boll(share_code, start_date, Utils.get_current_date())
Exemplo n.º 6
0
def save_index_data(begin_date):
    save_index_data_end_date(begin_date, Utils.get_current_date())
Exemplo n.º 7
0
def save_data_current_day(begin, end, step):
    save_data_from_now_on(begin, end, step, Utils.get_current_date())
Exemplo n.º 8
0
def save_data_from_now_on(begin, end, step, start_date):
    save_data(begin, end, step, start_date, Utils.get_current_date())
Exemplo n.º 9
0
def db_read(code, start_date, engine):
    rs = db_read_k_history(code, engine, start_date, Utils.get_current_date(), 'asc')
    return rs
Exemplo n.º 10
0
def do_save_basics_batch():
    engine = DBUtils.db_connection()
    basic_info_rs = DBUtils.get_stock_basics(engine)
    logger.info('get basic info total::::' + str(basic_info_rs.count()))
    share_code_list = list(basic_info_rs[u'code'])
    # time_to_market_list=list(basic_info_rs[u'timeToMarketNew'])
    counter = 0
    end = len(share_code_list)
    while counter <= end:
        threads = []
        '''第一个线程'''
        share_code = share_code_list[counter]
        time_to_market = Utils.get_pre_year(Utils.get_current_date())
        # time_to_market=time_to_market_list[counter]
        logger.debug("prepare to run:::::share_code=" + str(share_code) +
                     "time_to_market=" + str(time_to_market))
        # t1=threading.Thread(target=do_save_basics_pre, args=(share_code,time_to_market))
        do_save_basics_pre(share_code, time_to_market)
        # threads.append(t1)

        # counter=counter+1
        # if counter > end:
        #     logger.info("out of end!!! end="+end+'counter='+counter)
        # else:
        #     '''第二个线程'''
        #     share_code = share_code_list[counter]
        #     time_to_market = time_to_market_list[counter]
        #     t2=threading.Thread(target=do_save_basics_pre, args=(share_code,time_to_market))
        #     threads.append(t2)
        #
        # counter = counter + 1
        # if counter > end:
        #     logger.info("out of end!!! end=" + end + 'counter=' + counter)
        #     break
        # else:
        #     '''第三个线程'''
        #     share_code = share_code_list[counter]
        #     time_to_market = time_to_market_list[counter]
        #     t3 = threading.Thread(target=do_save_basics_pre, args=(share_code, time_to_market))
        #     threads.append(t3)
        #
        # counter = counter + 1
        # if counter > end:
        #     logger.info("out of end!!! end=" + end + 'counter=' + counter)
        #     break
        # else:
        #     '''第5个线程'''
        #     share_code = share_code_list[counter]
        #     time_to_market = time_to_market_list[counter]
        #     t5 = threading.Thread(target=do_save_basics_pre, args=(share_code, time_to_market))
        #     threads.append(t5)
        #
        #
        # counter = counter + 1
        # if counter > end:
        #     logger.info("out of end!!! end=" + end + 'counter=' + counter)
        #     break
        # else:
        #     '''第6个线程'''
        #     share_code = share_code_list[counter]
        #     time_to_market = time_to_market_list[counter]
        #     t6 = threading.Thread(target=do_save_basics_pre, args=(share_code, time_to_market))
        #     threads.append(t6)
        #
        counter = counter + 1