示例#1
0
    def vote(self, code, day):
        features = []
        values = db_helper.select(query_kpi_fn, (code, day, 30))
        if len(values) < 30:
            return features
        values = np.array(values)[::-1]
        rsi_6_lines = values[:, 1].astype(float)
        rsi_12_lines = values[:, 2].astype(float)
        rsi_24_lines = values[:, 3].astype(float)

        if rsi_6_lines[-1] <= 20:
            features.append(self.OVER_SOLD)

        if rsi_6_lines[-1] < 50 and rsi_12_lines[-1] < 50 and rsi_24_lines[
                -1] < 50:
            if ins.match(rsi_6_lines[-3:],
                         rsi_12_lines[-3:]) == 1 and ins.match(
                             rsi_6_lines[-3:], rsi_24_lines[-3:]):
                features.append(self.GOOD_CROSS)

        if trend.is_uptrend(rsi_6_lines[-10:]):
            k_values = db_helper.select(query_k_fn, (code, day, 10))
            if len(k_values) == 10:
                k_values = np.array(k_values)[::-1]
                close_values = k_values[:, 0].astype(float)
                if trend.is_downtrend(close_values):
                    features.append(self.BOTTOM_DEVIATION)

        return features
示例#2
0
文件: trix_as.py 项目: tlenny/amita
def _init_day(code, day):
    data = db_helper.select(query_data_fn, (code, day))
    if len(data) == 0:
        return
    data = np.array(data)
    close = np.float(data[0][1])

    last_ax, last_bx, last_trix = None, None, None
    last_data = db_helper.select(query_trix_fn, (code, day, 1))
    if len(last_data) == 1:
        last_ax = np.float(last_data[0][0])
        last_bx = np.float(last_data[0][1])
        last_trix = np.float(last_data[0][2])
    ax, bx, tx = _calc_trix(last_ax, last_bx, last_trix, close)
    trix = TRIX()
    trix.code = code
    trix.time_date = day
    trix.ax = ax
    trix.bx = bx
    trix.trix = tx
    last_tma_list = db_helper.select(query_trix_fn, (code, day, TRIX_M - 1))
    last_tma_list = np.array(last_tma_list)
    last_tma_list = last_tma_list[:, 2]
    trix.tma = _get_tma(last_tma_list, tx)
    return trix
示例#3
0
def his(code, day, day_len, forward):
    out = PrettyTable(['交易日', '收盘价', '涨跌幅', '评分', '特征'])
    query_data = db_helper.select(
        query_data_his_fn, (code, day, day_len, TradingDataDaily, forward))
    query_data = np.array(query_data)
    close_values = np.array(list(map(lambda x: np.float(x.close), query_data)))
    open_values = np.array(list(map(lambda x: np.float(x.open), query_data)))
    days = np.array(list(map(lambda x: x.time_date, query_data)))

    query_data = db_helper.select(query_eval_his_fn,
                                  (code, day, day_len, forward))
    query_data = np.array(query_data)
    days2 = np.array(list(map(lambda x: x.time_date, query_data)))
    score_values = np.array(list(map(lambda x: np.float(x.score), query_data)))
    feature_values = np.array(list(map(lambda x: x.feature, query_data)))
    for i in range(len(days)):
        d = days[i]
        close = close_values[i]
        open_price = open_values[i]
        delta = np.float((close - open_price) / open_price * 100)
        index = -1
        for j in range(len(days2)):
            if days[i] == days2[j]:
                index = j
        score, feature = 0, ''
        if index >= 0:
            score = score_values[index]
            feature = feature_values[index]
        out.add_row([d, _f(close), _f(delta, '%.2f%%'), _f(score), feature])
    print(out)
    pass
示例#4
0
文件: kdj_voter.py 项目: tlenny/amita
    def vote(self, code, day):
        features = []
        values = db_helper.select(query_kdj_fn, (code, day, 30))
        if len(values) < 30:
            return features
        values = np.array(values)[::-1]
        k_values = values[:, 1].astype(float)
        d_values = values[:, 2].astype(float)
        j_values = values[:, 3].astype(float)

        if k_values[-1] <= 20 and d_values[-1] <= 20 and j_values[-1] <= 20:
            features.append(self.OVER_SOLD)

        if ins.match(k_values[-3:], d_values[-3:]) == 1 and ins.match(
                j_values[-3:], d_values[-3:]):
            features.append(self.GOOD_CROSS)

        s = 0
        if trend.is_uptrend(k_values[-10:]):
            s = s + 1
        if trend.is_uptrend(d_values[-10:]):
            s = s + 1
        if trend.is_uptrend(j_values[-10:]):
            s = s + 1
        if s >= 2:
            k_values = db_helper.select(query_k_fn, (code, day, 10))
            k_values = np.array(k_values)[::-1]
            close_values = k_values[:, 0].astype(float)
            if trend.is_downtrend(close_values):
                features.append(self.BOTTOM_DEVIATION)
        return features
示例#5
0
def _init_day(code, day):
    data = db_helper.select(query_data_fn, (code, day))
    if len(data) < KDJ_N:
        return None
    last_kdj = db_helper.select(query_kdj_fn, (code, day))
    last_k, last_d = 50, 50
    if len(last_kdj) == 1:
        last_kdj = np.array(last_kdj)
        last_k, last_d = last_kdj[0][0], last_kdj[0][1]
    return _calc_kdj(code, data, last_k, last_d)
示例#6
0
def pick():
    time_date = request.args.get('time_date')
    pl = request.args.get('type')
    data = None
    if pl == 'SCORE':
        data = db_helper.select(query_data_fn, (time_date, ))
    else:
        data = db_helper.select(query_pl_data_fn, (time_date, pl))
        pass
    return jsonify({'list': data})
    pass
示例#7
0
def trace(vote_day, count=10, days=5):
    #     str = vote_day[0:4] + vote_day[5:7] + vote_day[8:10]
    #     file_name = DATA_PATH + 'R_%s.txt' % str
    #     stock_codes = []
    #     with open(file_name, 'r') as file_to_read:
    #         while True:
    #             lines = file_to_read.readline()  # 整行读取数据
    #             if not lines:
    #                 break
    #             stock_codes.append(lines.split()[0])
    query_data = db_helper.select(query_eval_fn, (vote_day, count))
    query_data = np.array(query_data)
    stock_codes = query_data[:, 0]
    scores = query_data[:, 1].astype(float)
    features = query_data[:, 2]

    #     print(stock_codes)
    out = PrettyTable([
        '股票代码', '评分', '当日收盘价', '次日涨跌幅', '期内最高价', '期内最低价', '期后收盘价', '期内最大涨幅',
        '期内最大跌幅', '期后涨跌幅', '特征'
    ])
    for i in range(len(stock_codes)):
        values = db_helper.select(
            query_data_fn,
            (stock_codes[i], vote_day, days + 1, TradingDataDaily))
        values = np.array(values)
        close_values = np.array(list(map(lambda x: np.float(x.close), values)))
        high_values = np.array(list(map(lambda x: np.float(x.high), values)))
        low_values = np.array(list(map(lambda x: np.float(x.low), values)))
        close = np.float(close_values[0])
        delta_next = np.float(
            (np.float(close_values[1]) - close) / close * 100)
        high = np.float(np.max(high_values[2:]))
        low = np.float(np.max(low_values[2:]))
        delta_high = np.float((high - close) / close * 100)
        last = np.float(close_values[-1])
        delta_low = np.max([np.float((close - low) / close * 100), 0])
        delta_close = np.float((last - close) / close * 100)
        out.add_row([
            stock_codes[i], scores[i],
            _f(close),
            _f(delta_next, '%.2f%%'),
            _f(high),
            _f(low),
            _f(last),
            _f(delta_high, '%.2f%%'),
            _f1(delta_low),
            _f(delta_close, '%.2f%%'), features[i]
        ])

    print('跟踪%s评估的%d只股票%d日内的价格情况' % (vote_day, count, days))
    print(out)
    pass
示例#8
0
文件: kdj_as.py 项目: tlenny/amita
def _init_day(code, day):
    data = db_helper.select(query_data_fn, (code, day))
    if len(data) < KDJ_N:
        return None
    data = np.array(data)
    if data[0][0] != day:
        return None
    data = data[::-1]
    last_kdj = db_helper.select(query_kdj_fn, (code, day))
    last_k, last_d = 50, 50
    if len(last_kdj) == 1:
        last_kdj = np.array(last_kdj)
        last_k, last_d = np.float(last_kdj[0][0]), np.float(last_kdj[0][1])
    return _calc_kdj(code, data, last_k, last_d)
示例#9
0
def eva(vote_day, count=10, days=5):
    query_data = db_helper.select(query_eval_fn, (vote_day, count))
    if len(query_data) == 0:
        elect(vote_day, count)
        query_data = db_helper.select(query_eval_fn, (vote_day, count))
    query_data = np.array(query_data)
    stock_codes = query_data[:, 0]
    scores = query_data[:, 1].astype(float)
    features = query_data[:, 2]

    #     print(stock_codes)
    out = PrettyTable([
        '股票代码', '评分', '当日收盘价', '次日涨跌幅', '最高价', '最低价', '最后收盘价', '最大涨幅', '最大跌幅',
        '后涨跌幅', '特征'
    ])
    for i in range(len(stock_codes)):
        values = db_helper.select(
            query_data_fn,
            (stock_codes[i], vote_day, days + 1, TradingDataDaily))
        values = np.array(values)
        close_values = np.array(list(map(lambda x: np.float(x.close), values)))
        high_values = np.array(list(map(lambda x: np.float(x.high), values)))
        low_values = np.array(list(map(lambda x: np.float(x.low), values)))
        close = np.float(close_values[0])
        delta_next, high, low, delta_high, last, delta_low, delta_close = 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
        if len(values) > 1:
            delta_next = np.float(
                (np.float(close_values[1]) - close) / close * 100)
            last = np.float(close_values[-1])
            delta_close = np.float((last - close) / close * 100)
            high = np.float(np.max(high_values[1:]))
            low = np.float(np.max(low_values[1:]))
            delta_high = np.float((high - close) / close * 100)
            delta_low = np.max([np.float((close - low) / close * 100), 0])
        out.add_row([
            stock_codes[i], scores[i],
            _f(close),
            _f(delta_next, '%.2f%%'),
            _f(high),
            _f(low),
            _f(last),
            _f(delta_high, '%.2f%%'),
            _f1(delta_low),
            _f(delta_close, '%.2f%%'), features[i]
        ])

    print('跟踪%s评估的%d只股票%d日内的价格情况' % (vote_day, count, days))
    print(out)
    pass
示例#10
0
文件: emv_as.py 项目: tlenny/amita
def _init_day(code, day):
    data = db_helper.select(query_data_fn, (code, day))
    if len(data) < 2:
        return None
    data = np.array(data)
    if data[0][0] != day:
        return None
    data = data[::-1]

    his = db_helper.select(query_emv_fn, (code, day))
    his = np.array(his)
    his = his[::-1]
    em_his = np.array(his[1 - EMV_N:, 0].astype(float))
    emv_his = np.array(his[1 - EMV_M:, 0].astype(float))
    emv, em_his, emv_his = _emv(code, data, em_his, emv_his)
    return emv
示例#11
0
def detail():
    code = request.args.get('code')
    print(code)
    data = db_helper.select(query_detail_data_fn, (code, ))
    data = np.array(data)
    # data = [['2018-11-11',5.5,'aaa']]
    text = htmle_head()
    text = text + "<h5>%s</h5>" % code
    text = text + """
		<div>  
   			<ul>  
		"""
    for i in range(len(data)):
        text = text + """
			<li>  
			<a>%d</a>   
			<h3>%s</h3> 
			<p>%s</p>  
			</li>  
			""" % (data[i][1], data[i][0], data[i][2])
    text = text + """
		   </ul>  
		 </div> 
		</body>
		</html>
		"""
    return text
    pass
示例#12
0
文件: voter.py 项目: tlenny/amita
 def _get_close_price(self, code, start_day, end_day):
     data = db_helper.select(
         query_single_fn,
         (code, start_day, end_day, TradingDataDaily.close))
     if len(data) == 0:
         return None
     else:
         return np.array(data)[:, 0]
示例#13
0
def dig(step=30, slide_days=10, turn_days=2):
    day = time.strftime("%Y-%m-%d", time.localtime())
    code_list = db_helper.select(query_code_fn, (day, ))
    rst = []
    for i in range(len(code_list)):
        code = code_list[i][0]
        is_rebound, ma_values = _is_rebound(code, step, slide_days, turn_days)
        print("分析[%s,%s]:%r" % ('ma', code, is_rebound))
        if is_rebound:
            data = db_helper.select(query_data_fn, (code, day, turn_days))
            data = np.array(data)
            data = data[:, 1]
            ma_values = ma_values[-turn_days:]
            is_less = np.min(np.less(ma_values, data))
            if is_less:
                rst.append(code)
    return rst
示例#14
0
文件: arbr_as.py 项目: tlenny/amita
def _init_day(code, day):
    data = db_helper.select(query_data_fn, (code, day))
    if len(data) < ARBR_N + 1:
        return None
    data = np.array(data)
    if data[0][0] != day:
        return None
    data = data[::-1]
    return _arbr(code, data)
示例#15
0
文件: bias_as.py 项目: tlenny/amita
def _init_day(code, day):
    data = db_helper.select(query_data_fn, (code, day))
    if len(data) < BIAS_N4:
        return None
    data = np.array(data)
    if data[0][0] != day:
        return None
    data = data[::-1]
    rsi = _bias(code, data)
    return rsi
示例#16
0
文件: dma_as.py 项目: tlenny/amita
def _init_day(code, day):
    data = db_helper.select(query_data_fn, (code, day))
    if len(data) < DMA_N + DMA_M - 1:
        return None
    data = np.array(data)
    if data[0][0] != day:
        return None
    data = data[::-1]
    dma = _dma(code, data)
    return dma
示例#17
0
    def vote(self, code, day):
        features = []
        values = db_helper.select(query_wr_fn, (code, day, 30))
        if len(values) < 30:
            return features
        values = np.array(values)[::-1]
        wr_6_values = values[:, 1].astype(float)

        if trend.is_uptrend(wr_6_values[-10:]):
            k_values = db_helper.select(query_k_fn, (code, day, 10))
            if len(k_values) == 10:
                k_values = np.array(k_values)[::-1]
                close_values = k_values[:, 0].astype(float)
                if trend.is_downtrend(close_values):
                    features.append(self.BOTTOM_DEVIATION)

        if wr_6_values[-1] > 80:
            features.append(self.OVER_SOLD)
        return features
示例#18
0
文件: arbr_as.py 项目: tlenny/amita
def _init_all(code):
    data = db_helper.select(query_data_fn, (code, None))
    if len(data) < ARBR_N + 1:
        return None
    data = np.array(data)
    arbr_list = []
    for i in range(len(data) - ARBR_N - 1):
        last_data = data[i:i + ARBR_N + 1]
        arbr_list.append(_arbr(code, last_data))
    return arbr_list
示例#19
0
def _init_day(code, day):
    data = db_helper.select(query_data_fn, (code, day))
    if len(data) < BOLL_N + 1:
        return None
    data = np.array(data)
    if data[0][0] != day:
        return None
    data = data[::-1]
    boll = _boll(code, data)
    return boll
示例#20
0
文件: roc_as.py 项目: tlenny/amita
def _init_day(code, day):
    data = db_helper.select(query_data_fn, (code, day))
    if len(data) < ROC_N + ROC_M - 1:
        return None
    data = np.array(data)
    if data[0][0] != day:
        return None
    data = data[::-1]
    roc = _roc(code, data)
    return roc
示例#21
0
def _init_day(code, day):
    data = db_helper.select(query_data_fn, (code, day))
    if len(data) < WR_40:
        return None
    data = np.array(data)
    if data[0][0] != day:
        return None
    data = data[::-1]
    entity = _wr(code, data)
    return entity
示例#22
0
    def vote(self, code, day):
        features = []
        values = db_helper.select(self.query_kpi_fn, (code, day, 30, BOLL))
        k_values = db_helper.select(self.query_kpi_fn,
                                    (code, day, 30, TradingDataDaily))
        if len(values) < 30 or len(k_values) < 30 or len(values) != len(
                k_values):
            return features
        values = np.array(values)[::-1]
        k_values = np.array(k_values)[::-1]
        md_values = np.array(list(map(lambda x: np.float(x.md), values)))
        close_values = np.array(
            list(map(lambda x: np.float(x.close), k_values)))

        bt, l = zero_line.breakthrough(close_values, md_values)
        if bt and l <= 3:
            features.append(self.BREAK_ZERO)

        return features
示例#23
0
文件: rsi_as.py 项目: tlenny/amita
def _init_day(code, day):
    data = db_helper.select(query_data_fn, (code, day))
    if len(data) < RSI_N3 + 1:
        return None
    data = np.array(data)
    if data[0][0] != day:
        return None
    data = data[::-1]
    rsi = _rsi(code, data)
    return rsi
示例#24
0
文件: rsi_as.py 项目: tlenny/amita
def _init_all(code):
    data = db_helper.select(query_data_fn, (code, None))
    if len(data) < RSI_N3 + 1:
        return None
    data = np.array(data)
    rsi_list = []
    for i in range(len(data) - RSI_N3):
        last_data = data[i:i + (RSI_N3 + 1)]
        rsi = _rsi(code, last_data)
        rsi_list.append(rsi)
    return rsi_list
示例#25
0
def _init_all(code):
    data = db_helper.select(query_data_fn, (code, None))
    if len(data) < BOLL_N + 1:
        return None
    data = np.array(data)
    boll_list = []
    for i in range(len(data) - BOLL_N):
        last_data = data[i:i + (BOLL_N + 1)]
        boll = _boll(code, last_data)
        boll_list.append(boll)
    return boll_list
示例#26
0
    def vote(self, code, day):
        features = []
        arbr_values = db_helper.select(query_arbr_fn, (code, day, 14))
        if len(arbr_values) < 14:
            return features
        arbr_values = np.array(arbr_values)[::-1]
        ar_values = arbr_values[:, 1].astype(float)
        br_values = arbr_values[:, 2].astype(float)
        if ins.match(br_values[-3:], ar_values[-3:]) == 1:
            features.append(self.GOOD_CROSS)

        if trend.is_uptrend(ar_values) and trend.is_uptrend(br_values):
            k_values = db_helper.select(query_k_fn, (code, day, 14))
            if len(k_values) == 14:
                k_values = np.array(k_values)[::-1]
                close_values = k_values[:, 0].astype(float)
                if trend.is_downtrend(close_values):
                    features.append(self.BOTTOM_DEVIATION)

        return features
示例#27
0
def _init_all(code):
    data = db_helper.select(query_data_fn, (code, None))
    if len(data) < WR_40:
        return None
    data = np.array(data)
    entity_list = []
    for i in range(len(data) - WR_40 + 1):
        last_data = data[i:i + WR_40]
        entity = _wr(code, last_data)
        entity_list.append(entity)
    return entity_list
示例#28
0
文件: bias_as.py 项目: tlenny/amita
def _init_all(code):
    data = db_helper.select(query_data_fn, (code, None))
    if len(data) < BIAS_N4:
        return None
    data = np.array(data)
    rsi_list = []
    for i in range(len(data) - BIAS_N4 + 1):
        last_data = data[i:i + BIAS_N4]
        rsi = _bias(code, last_data)
        rsi_list.append(rsi)
    return rsi_list
示例#29
0
def eye():
    time_date = db_helper.select(query_date, (1))[0][0]
    data = db_helper.select(query_data_fn, (time_date, ))
    data = np.array(data)
    text = htmle_head()
    text = text + "<h5>%s</h5>" % time_date
    text = text + """
		<div>  
   			<ul>  
		"""
    for i in range(len(data)):
        text = text + build_html_with_stock_data(data[i][0], data[i][1],
                                                 data[i][2])
    text = text + """
		   </ul>  
		 </div> 
		</body>
		</html>
		"""
    return text
示例#30
0
文件: dma_as.py 项目: tlenny/amita
def _init_all(code):
    data = db_helper.select(query_data_fn, (code, None))
    if len(data) < DMA_N + DMA_M - 1:
        return None
    data = np.array(data)
    roc_list = []
    for i in range(len(data) - (DMA_N + DMA_M - 1)):
        last_data = data[i:i + (DMA_N + DMA_M)]
        roc = _dma(code, last_data)
        roc_list.append(roc)
    return roc_list