Exemplo n.º 1
0
def insert_company_from_market():
    se = StartEndLogging()

    scw.delete()
    market_qs = smdw.gets(date=smdw.get_date(is_add_one=False))
    log.debug(f'market data size: {len(market_qs)}')

    company_objects = []
    for market_data in market_qs:
        company_object = scw.make_object(market_data)
        if company_object is not None:
            company_objects.append(company_object)
    scw.insert(company_objects)

    se.end()
Exemplo n.º 2
0
def lstm_test3():
    se = StartEndLogging()

    modeling_target_qs = scw.gets_modeling_target()

    for modeling_company in modeling_target_qs[:10]:
        model = LstmTraining(modeling_company.com_code, LSTM_KWARGS)
        model.modeling3()

    se.end()
Exemplo n.º 3
0
def update_company_from_market():
    se = StartEndLogging()

    market_qs = smdw.gets(date=smdw.get_date(is_min=False, is_add_one=False))
    company_df = read_frame(scw.gets('id'))
    log.debug(f'market data size: {len(market_qs)}, company data size: {len(company_df)}')

    company_objects = []
    for market_data in market_qs:
        company = company_df[company_df['com_code']==market_data.com_code]
        if company.empty:
            company_object = scw.make_object(market_data)
        else:
            company_object = scw.make_object(company, market_data)
        if company_object is not None:
            company_objects.append(company_object)

    scw.insert(company_objects)

    se.end()
Exemplo n.º 4
0
def insert_modelingdata_from_market():
    se = StartEndLogging()

    company_qs = scw.gets('id')
    company_size = len(company_qs)
    log.debug(f'company size: {company_size}')
    smlw.delete()

    def get_normal_marketdata(com_code):
        company_market_qs = smdw.gets(com_code=com_code)
        first_data = company_market_qs.first()
        yesterday_data, first_normal_data = first_data, first_data
        if first_data.t_volume != 0:
            diff_ratio = company_market_qs.last(
            ).t_volume / first_data.t_volume
        else:
            # 첫번째 t_volume값이 0이기 때문에 전체 변동량 체크가 불가능함.
            # 따라서 세부 체크가 수행될 수 있도록 diff_ratio를 설정함
            diff_ratio = TOTAL_CHECK_MAX_RATIO + 1.

        if diff_ratio > TOTAL_CHECK_MAX_RATIO or diff_ratio < TOTAL_CHECK_MIN_RATIO:
            for market_data in company_market_qs[
                    1:]:  # 첫번째 값은 위에서 first()을 이용해 이미 사용
                if yesterday_data.t_volume != 0 and market_data.t_volume != 0:
                    diff_ratio = market_data.t_volume / yesterday_data.t_volume
                    if diff_ratio > DAY_CHECK_MAX_RATIO or diff_ratio < DAY_CHECK_MIN_RATIO:
                        first_normal_data = market_data
                    # 당일 거래량이 없는 종목은 감자/증자 대상으로 간주한다.
                    if market_data.volume == 0:
                        first_normal_data = market_data
                yesterday_data = market_data

        normal_qs = company_market_qs.filter(date__gte=first_normal_data.date)
        log.debug(f'com_code: {com_code},  modeling data size: '
                  f'total({len(company_market_qs)}), normal({len(normal_qs)})')
        return normal_qs

    for company in tqdm(company_qs):
        market_df = read_frame(get_normal_marketdata(company.com_code))
        company.data_size = len(market_df)
        company.save()
        market_df = market_df[['date', 'com_code'] + MODELING_COLUMNS]
        smlw.insert(market_df)

    se.end()
Exemplo n.º 5
0
def lstm_test():
    se = StartEndLogging()

    modeling_target_qs = scw.gets_modeling_target()
    log.info(len(modeling_target_qs))

    cnt_skip_trend, cnt_skip_accuracy = 0, 0
    for modeling_company in modeling_target_qs[:15]:
        model = LstmTraining(modeling_company.com_code, kwargs)
        is_skip = model.modeling()
        se.mid(f'{modeling_company.com_code}')
        if is_skip['trend']:
            cnt_skip_trend += 1
        if is_skip['accuracy']:
            cnt_skip_accuracy += 1
    log.info(
        f'modeling total count: {len(modeling_target_qs)}, '
        f'trend skip: {cnt_skip_trend}, accuracy skip: {cnt_skip_accuracy}')

    se.end()
Exemplo n.º 6
0
def today_modeling():
    se = StartEndLogging()

    modeling_target_qs = scw.gets_modeling_target()
    modeling_size = len(modeling_target_qs)

    cnt_processing = 0
    cnt_skip_trend, cnt_skip_accuracy = 0, 0
    for modeling_company in modeling_target_qs:
        model = LstmTraining(modeling_company.com_code, LSTM_KWARGS)
        is_skip = model.modeling2()
        cnt_processing += 1
        se.mid(f'{modeling_company.com_code}, {cnt_processing}/{modeling_size}')
        if is_skip['trend']:
            cnt_skip_trend += 1
        if is_skip['accuracy']:
            cnt_skip_accuracy += 1
    log.info(f'modeling total count: {len(modeling_target_qs)}, '
             f'trend skip: {cnt_skip_trend}, accuracy skip: {cnt_skip_accuracy}')

    se.end()
Exemplo n.º 7
0
def get_data():
    company = scw.get('060310')
    log.debug(company)
    company_qs = scw.gets('id')
    for com in company_qs[:2]:
        log.debug(com)
Exemplo n.º 8
0
def save_from_marketdata():
    market_qs = scw.save_from_marketdata()
    log.debug(f'market_qs size: {len(market_qs)}')