Esempio n. 1
0
 def __init__(self, model_name):
     self.logger = logger.APP_LOGGER
     self.model_name = model_name
     self.model = self._load_model(model_name)
     self.mysql = mysql_controller.MysqlController()
     if self.model is None:
         self.logger.error(
             "The model is not exist. Please check your model name")
Esempio n. 2
0
    def daily_recommend_stock(self, print_cols, today=None):
        if today is None:
            query = '''
            SELECT t3.cmp_nm_kor as cmp_nm_kor, m1.*
            FROM
                company_list t3, (SELECT t1.*, t2.close
                FROM metric t1, stock_price t2
                WHERE
                    t1.cmp_cd=t2.cmp_cd
                    AND t1.date=t2.date
                    AND t1.date=(SELECT date
											FROM metric
											ORDER BY date DESC
											LIMIT 1)) m1
            WHERE
                right(t3.cmp_cd,6)=m1.cmp_cd;
            '''
        else:
            query = f'''
            SELECT t3.cmp_nm_kor as cmp_nm_kor, m1.*
            FROM
                company_list t3, (SELECT t1.*, t2.close
                FROM metric t1, stock_price t2
                WHERE
                    t1.cmp_cd=t2.cmp_cd
                    AND t1.date=t2.date
                    AND t1.date="{today}") m1
            WHERE
                right(t3.cmp_cd,6)=m1.cmp_cd;
            '''

        # 데이터 가져와서
        _mysql = mysql_controller.MysqlController()
        metric_df = _mysql.select_dataframe(query)
        if len(metric_df) == 0:
            return None

        # infer
        metric_df = self._calc_metric(metric_df)
        metric_df = metric_df[[
            'cmp_cd', 'date', 'close', 'PER', 'PCR', 'PBR', 'PSR', 'EV/EBITDA',
            'ROE'
        ]]
        metric_df['pred'], metric_df['pos'], metric_df[
            'neg'] = self.predict_stock(metric_df)
        metric_df['model'] = self.model_name
        return metric_df[print_cols]
Esempio n. 3
0
def get_recom_list():
    query = f'''
    SELECT ttt1.*, ROUND(ttt2.pos, 3) as pos, ROUND(ttt2.neg, 3) as neg, ttt2.pred
    FROM
        (SELECT tt1.*, tt2.open as price
        FROM
            (SELECT t1.cmp_cd, t1.cmp_nm_kor, t1.brk_nm_kor, t1.pf_nm_kor,
                    t1.in_dt, t1.reason_in
                    FROM {const.NAVER_IN_TABLE} t1
                    LEFT JOIN {const.NAVER_OUT_TABLE} t2
                    ON
                        t1.cmp_cd = t2.cmp_cd
                        AND t1.brk_cd = t2.brk_cd
                        AND t1.pf_cd = t2.pf_cd
                    WHERE t2.cmp_cd IS NULL) as tt1,
                stock_price as tt2
            WHERE tt1.cmp_cd=tt2.cmp_cd
                AND tt1.in_dt=tt2.date) ttt1,
        (SELECT distinct * FROM {const.MODEL_RECOMMEND_TABLE}) ttt2
    WHERE
        ttt1.cmp_cd=ttt2.cmp_cd
        AND ttt1.in_dt=ttt2.date
    ORDER BY in_dt DESC;
    '''
    _mysql = mysql_controller.MysqlController()
    recomm_df = _mysql.select_dataframe(query)
    if recomm_df is None:
        recomm_html = "There are no recommended items today."
    else:
        recomm_html = recomm_df.to_html(classes='table', header='true')
        recomm_html = recomm_html.replace('\\r\\n', '<br/>')

    today = datetime.date.today().strftime('%Y-%m-%d')
    return render_template('metric_studio/index.html',
                           recomm_df=recomm_html,
                           today=today)
Esempio n. 4
0
 def __init__(self, delay=1):
     self.logger = logger.APP_LOGGER
     self.delay = delay
     self.mysql = mysql_controller.MysqlController()
Esempio n. 5
0
def get_company_list():
    _mysql = mysql_controller.MysqlController()
    query = f'''SELECT cmp_cd FROM {const.COMPANY_LIST_TABLE};'''
    return _mysql.select_dataframe(query)