Ejemplo n.º 1
0
def update_by_industry(index_name, indCode, intraday, type='full'):
    '''
    update by industry code;
    full: all data
    compact: today only
    '''
    data = get_index_table(index_name)
    df = indCode_to_tickers(data,
                            indCode)  # ticers in that Industry in DF format
    if (type == 'compact' and intraday == 'none'):
        df_dic = get_df_bySec(df,
                              intraday='none',
                              size='compact',
                              today_only=True,
                              sleep_timer=15)
    elif (type == 'full' and intraday == 'none'):
        df_dic = get_df_bySec(df,
                              intraday='none',
                              size='full',
                              today_only=False,
                              sleep_timer=15)
    elif (type == 'compact' and intraday != 'none'):
        df_dic = get_df_bySec(df,
                              intraday,
                              size='compact',
                              today_only=True,
                              sleep_timer=15)
    elif (type == 'full' and intraday != 'none'):
        df_dic = get_df_bySec(df,
                              intraday,
                              size='full',
                              today_only=False,
                              sleep_timer=15)
    else:
        pass
Ejemplo n.º 2
0
def report(index_name):
    '''
    report hub function
    '''
    # index table in df
    indexT = get_index_table(index_name)
    # index df to list of symbols
    tickerL = indexT['Symbol'].tolist()
    # daily db engine
    engine_dailydb = create_dbengine(db="tsxci_daily_db")
    # report db engine
    engine_report = create_dbengine(db="tsxci_report")
    # temp df for report with predefined columns
    columns = [
        'ticker', '52w high', '52w low', 'downtrend', 'uptrend', 'pattern',
        'high volume', 'low volume', 'Industry'
    ]
    dtypes = ['str', 'int', 'int', 'int', 'int', 'str', 'int', 'int', 'str']
    report_df = df_empty(columns, dtypes)
    for ticker in tickerL:
        # equity name
        equity = ticker
        # ticker + '.to'
        ticker_to = (ticker + '.to').lower()
        # print(ticker)
        # industry name & ticker
        ind_df = indexT[(indexT['Symbol'] == equity)][['Industry', 'Symbol']]
        ind_df.columns = ['Industry', 'ticker']
        # read daily db return df
        df = read_table_df_Engine(ticker_to, engine_dailydb)
        # unusual volume stickers append to df
        report_df = report_df.append(unusual_volume(equity, df),
                                     ignore_index=True)
        # unusual trend stickers append to df
        report_df = report_df.append(trend_potential(equity, df),
                                     ignore_index=True)
        # 52w high/low/trending append to df
        report_df = report_df.append(fiftytwo_week(equity, df),
                                     ignore_index=True)
        # decide if known pattern append to df
        report_df = report_df.append(find_pattern(equity, df),
                                     ignore_index=True)
        # added industry name to each ticker, if ticker in index otherwise not add industry
        if not report_df.empty:
            if (equity in report_df['ticker'].unique()):
                report_df = report_df.append(ind_df, ignore_index=True)
    # grouby using first() and NaN to Zero
    report_df = groupby_na_to_zero(report_df, 'ticker')
    # pass columns don't want to be type(int), industry must exist after the loop above
    # report_df = type_to_int(report_df,['pattern','Industry'])
    # tname is today's date
    tname = dt.datetime.today().strftime("%m-%d-%Y")
    # print(report_df.columns)
    # write df into db
    report_df_to_sql(tname, report_df, engine_report)
Ejemplo n.º 3
0
def update_all(index_name, intraday, type='compact'):
    '''
    update all
    full: all data
    compact: today only
    '''
    data = get_index_table(index_name)  # All tickers in DF format
    # Use old function 'get_df_byTicker' ) NO index_name
    if (index_name == 'tsxci'):
        if (type == 'compact' and intraday == 'none'):
            df_dic = get_df_byTicker(data,
                                     intraday='none',
                                     size='compact',
                                     today_only=True,
                                     sleep_timer=15)
        elif (type == 'full' and intraday == 'none'):
            df_dic = get_df_byTicker(data,
                                     intraday='none',
                                     size='full',
                                     today_only=False,
                                     sleep_timer=15)
        elif (type == 'compact' and intraday != 'none'):
            df_dic = get_df_byTicker(data,
                                     intraday,
                                     size='compact',
                                     today_only=True,
                                     sleep_timer=15)
        elif (type == 'full' and intraday != 'none'):
            df_dic = get_df_byTicker(data,
                                     intraday,
                                     size='full',
                                     today_only=False,
                                     sleep_timer=15)
        else:
            pass
    # New function is called "fetch_write" for ca_etf
    elif (index_name == 'ca_etf'):
        if (type == 'compact' and intraday == 'none'):
            df_dic = fetch_write(index_name,
                                 data,
                                 intraday='none',
                                 size='compact',
                                 today_only=True,
                                 sleep_timer=15)
        elif (type == 'full' and intraday == 'none'):
            df_dic = fetch_write(index_name,
                                 data,
                                 intraday='none',
                                 size='full',
                                 today_only=False,
                                 sleep_timer=15)
        else:
            pass
Ejemplo n.º 4
0
def update_all(index_name,intraday,type='compact'):
    '''
    update all
    full: all data
    compact: today only
    '''
    data = get_index_table(index_name) # All tickers in DF format
    if (type=='compact' and intraday=='none'):
        df_dic = get_df_byTicker(data,intraday='none',size='compact',today_only=True,sleep_timer=15)
    elif (type=='full' and intraday=='none'):
        df_dic = get_df_byTicker(data,intraday='none',size='full',today_only=False,sleep_timer=15)
    elif (type=='compact' and intraday !='none'):
        df_dic = get_df_byTicker(data,intraday,size='compact',today_only=True,sleep_timer=15)
    elif (type=='full' and intraday !='none'):
        df_dic = get_df_byTicker(data,intraday,size='full',today_only=False,sleep_timer=15)
    else:
        pass
Ejemplo n.º 5
0
def update_all(index_name, type='compact'):
    '''
    update all
    full: all data
    compact: today only
    '''
    data = get_index_table(index_name)
    if (type == 'compact'):
        df_dic = get_df_byTicker(data,
                                 size='compact',
                                 today_only=True,
                                 sleep_timer=15)
    else:
        df_dic = get_df_byTicker(data,
                                 size='full',
                                 today_only=False,
                                 sleep_timer=15)
Ejemplo n.º 6
0
def update_by_industry(index_name, indCode, type='full'):
    '''
    update by industry code;
    full: all data
    compact: today only
    '''
    data = get_index_table(index_name)
    df = indCode_to_tickers(data, indCode)
    if (type == 'compact'):
        df_dic = get_df_bySec(df,
                              size='compact',
                              today_only=True,
                              sleep_timer=15)
    else:
        df_dic = get_df_bySec(df,
                              size='full',
                              today_only=False,
                              sleep_timer=15)