Example #1
0
def plot_kline_chart(code=None,
                     mark=None,
                     start_date='2010-01-01',
                     target='MACD',
                     mark_line_show=False):
    '''
    :param code: 股票代码
    :param mark: 指数 [一级行业指数,主题指数,二级行业指数,价值指数,债券指数,基金指数,成长指数,策略指数,综合指数,规模指数]
    :param start_date:
    :return:
    '''

    if code is None and mark is None:
        logger.error("code and mark is None!")
    if code:
        title = get_name(code)
        data = Data(code, start_date)
        data.get_query_history_k_data_plus()
        data.logout()
        chart = ProfessionalKlineChart(mark_line_show=mark_line_show,
                                       title=title,
                                       target=target)
        return chart.draw(data.query_history_k_data_plus)
    if mark:
        plot_mark(mark=mark,
                  start_date=start_date,
                  mark_line_show=mark_line_show)
        logger.info("draw chart finish")
Example #2
0
File: view.py Project: zpf4934/st
def set_lstmparam(request):
    ctx = {}
    param = {}
    int_param = ['hidden_size', 'num_layers', 'batch_size', 'epoch', 'n_tep']
    float_param = ['lr']
    if monitor:
        ctx['monitor'] = monitor
    for key in request.GET.keys():
        value = request.GET[key]
        if value == 'None':
            continue
        else:
            try:
                if key in int_param:
                    param[key] = int(value)
                elif key in float_param:
                    param[key] = float(value)
                else:
                    param[key] = value
            except Exception as e:
                logger.error(e)
                return render(request, 'index.html', ctx)
    with open(os.path.join(PROJECT_PATH, 'model/config/lstmparam'), 'w') as fw:
        param['fit'] = True
        fw.write(json.dumps(param))
    return render(request, 'index.html', ctx)
Example #3
0
File: view.py Project: zpf4934/st
def set_xgbparam(request):
    ctx = {}
    param = {}
    int_param = ['max_depth', 'n_jobs', 'min_child_weight', 'max_delta_step']
    float_param = [
        'max_delta_step', 'gamma', 'subsample', 'colsample_bytree',
        'colsample_bylevel', 'colsample_bynode', 'reg_alpha', 'reg_lambda',
        'scale_pos_weight'
    ]
    if monitor:
        ctx['monitor'] = monitor
    for key in request.GET.keys():
        value = request.GET[key]
        if value == 'None':
            continue
        else:
            try:
                if key in int_param:
                    param[key] = int(value)
                elif key in float_param:
                    param[key] = float(value)
                else:
                    param[key] = value
            except Exception as e:
                logger.error(e)
                return render(request, 'index.html', ctx)
    with open(os.path.join(PROJECT_PATH, 'model/config/xgbparam'), 'w') as fw:
        param['fit'] = True
        fw.write(json.dumps(param))
    return render(request, 'index.html', ctx)
Example #4
0
File: view.py Project: zpf4934/st
def set_prophetparam(request):
    ctx = {}
    param = {}
    int_param = ['n_changepoints', 'mcmc_samples', 'uncertainty_samples']
    float_param = [
        'changepoint_range', 'seasonality_prior_scale', 'holidays_prior_scale',
        'changepoint_prior_scale', 'interval_width'
    ]
    if monitor:
        ctx['monitor'] = monitor
    for key in request.GET.keys():
        value = request.GET[key]
        if value == 'None':
            param[key] = None
        else:
            try:
                if key in int_param:
                    param[key] = int(value)
                elif key in float_param:
                    param[key] = float(value)
                else:
                    param[key] = value
            except Exception as e:
                logger.error(e)
                return render(request, 'index.html', ctx)
    with open(os.path.join(PROJECT_PATH, 'model/config/prophetparam'),
              'w') as fw:
        param['fit'] = True
        fw.write(json.dumps(param))
    return render(request, 'index.html', ctx)
Example #5
0
def plot_mark(mark, start_date, mark_line_show=False, clear_cache=False):
    cache_data = get_cache(mark, clear_cache)
    path_data_info = os.path.join(PROJECT_PATH, 'data_info')
    mark_info = pd.read_csv(os.path.join(path_data_info, mark + ".csv"))
    i = 0
    start = time.time()
    for code in mark_info['指数代码']:
        name = mark_info.loc[mark_info['指数代码'] == code, '指数简称'].values[0]
        i += 1
        logger.info('\nDraw chart: {}=>{}'.format(mark, name))
        draw = ProfessionalKlineChart(mark_line_show=mark_line_show,
                                      title=name)
        if cache_data is not None and cache_data[cache_data['code'] ==
                                                 code].size > 0:
            start_date = (pd.to_datetime(
                cache_data[cache_data['code'] == code]['date'].max()) +
                          datetime.timedelta(days=1)).strftime('%Y-%m-%d')
        if start_date <= datetime.datetime.now().strftime('%Y-%m-%d'):
            data = Data(code, start_date)
            data.get_query_history_k_data_plus()
            data.logout()
            if cache_data is not None:
                data.query_history_k_data_plus = pd.concat(
                    [
                        cache_data[cache_data['code'] == code],
                        data.query_history_k_data_plus
                    ],
                    ignore_index=True).sort_values(by='date')
            if data.query_history_k_data_plus.size == 0:
                logger.warning(
                    'data.query_history_k_data_plus and cache_data is NULL')
            else:
                data.query_history_k_data_plus.drop_duplicates(
                    subset=['date', 'code'], inplace=True)
                chart = draw.draw(data.query_history_k_data_plus)
                save_html(mark, chart, name)
                cache_data = pd.concat(
                    [cache_data, data.query_history_k_data_plus],
                    ignore_index=True)
                cache_data.drop_duplicates(subset=['date', 'code'],
                                           inplace=True)
        else:
            logger.error("date is out of today!")
        clearout()
        end = time.time()
        logger.info('\r' + '进度 {}/{}:[{}]{:.2f}% {:.2f}s'.format(
            i, len(mark_info),
            emoji.emojize(':rocket:') * int(i * 30 / len(mark_info)) + '   ' *
            int((1 -
                 (i / len(mark_info))) * 30), float(i / len(mark_info) *
                                                    100), end - start))
    save_cache(mark, cache_data)
Example #6
0
 def log(self, message, rs):
     if self.verbose == 1:
         logger.info(message + rs.error_msg)
     else:
         if rs.error_code != '0':
             logger.error(message + rs.error_msg)
Example #7
0
File: model.py Project: zpf4934/st
'''