Example #1
0
def get_lpr_ma(year=None):
    """上海银行间同业拆放利率(Shanghai Interbank Offered Rate,简称Shibor)

    Args:
        year: 年份(YYYY),默认为当前年份
    """
    if not year:
        year = util.get_year()
    logger.info('Begin get LprMA, year is: %s.' % year)
    try:
        data_df = ts.lpr_ma_data(year)
    except Exception as e:
        logger.exception('Error get LprMA. year is: %s.' % year)
        return None
    else:
        data_df['date'] = data_df['date'].astype(str)
        data_dicts = []
        if data_df is None or data_df.empty:
            logger.warn('Empty get LprMA. year is: %s.' % year)
        else:
            data_df['date'] = data_df['date'].astype(str)
            data_dicts = [{
                'date': row[0],
                'Y1_5': row[1],
                'Y1_10': row[2],
                'Y1_20': row[3],
                'year': year
            } for row in data_df.values]
            logger.info('Success get LprMA. year is: %s.' % year)
        return data_dicts
Example #2
0
def get_shibor_rate(year=None):
    """上海银行间同业拆放利率(Shanghai Interbank Offered Rate,简称Shibor)
    
    Args:
        year: 年份(YYYY),默认为当前年份
    """
    if not year:
        year = util.get_year()
    logger.info('Begin get ShiborRate, year is: %s.' % year)
    try:
        data_df = ts.shibor_data(year)
    except Exception as e:
        logger.exception('Error get ShiborRate. year is: %s.' % year)
        return None
    else:
        data_dicts = []
        if data_df is None or data_df.empty:
            logger.warn('Empty get ShiborRate. year is: %s.' % year)
        else:
            data_df['date'] = data_df['date'].astype(str)
            data_dicts = [{
                'date': row[0],
                'ON': row[1],
                'W1': row[2],
                'W2': row[3],
                'M1': row[4],
                'M3': row[5],
                'M6': row[6],
                'M9': row[7],
                'Y1': row[8],
                'year': year
            } for row in data_df.values]
            logger.info('Success get ShiborRate. year is: %s.' % year)
        return data_dicts
Example #3
0
def save_shibor_ma(year=None):
    """Shibor均值数据(Shanghai Interbank Offered Rate,简称Shibor)

    Args:
        year: 年份(YYYY),默认为当前年份
    """
    if not year:
        year = util.get_year()
    data_dicts = bankl_dal.get_shibor_ma(year)
    if data_dicts:
        if util_dal.delete_year_data(ShiborMA, year):
            util_dal.save_year_data(ShiborMA, data_dicts, year)
Example #4
0
def save_distribution_plans(year=None, top=5000):
    """得到分配预案数据
    
    Args:
        year : 预案公布的年份,默认为2014
        top :取最新n条数据,默认取最近公布的5000条
    """
    year = util.get_year() if year is None else year
    data_dicts = irdal.get_distribution_plans_data(year, top)
    if data_dicts:
        if util_dal.delete_year_data(DistributionPlans, year):
            irdal.save_distribution_plans_data(data_dicts, year)
Example #5
0
def save_lpr_ma(year=None):
    """贷款基础利率均值数据,目前只提供2013年以来的数据。

    Args:
        year: 年份(YYYY),默认为当前年份
    """
    if not year:
        year = util.get_year()
    data_dicts = bankl_dal.get_lpr_ma(year)
    if data_dicts:
        if util_dal.delete_year_data(LprMA, year):
            util_dal.save_year_data(LprMA, data_dicts, year)
Example #6
0
def save_shibor_rate(year=None):
    """上海银行间同业拆放利率(Shanghai Interbank Offered Rate,简称Shibor)
    
    Args:
        year: 年份(YYYY),默认为当前年份
    """
    if not year:
        year = util.get_year()
    data_dicts = bankl_dal.get_shibor_rate(year)
    if data_dicts:
        if util_dal.delete_year_data(ShiborRate, year):
            util_dal.save_year_data(ShiborRate, data_dicts, year)
Example #7
0
def save_shibor_quote(year=None):
    """银行报价数据

    Args:
        year: 年份(YYYY),默认为当前年份
    """
    if not year:
        year = util.get_year()
    data_dicts = bankl_dal.get_shibor_quote(year)
    if data_dicts:
        if util_dal.delete_year_data(ShiborQuote, year):
            util_dal.save_year_data(ShiborQuote, data_dicts, year)
Example #8
0
def save_lpr(year=None):
    """贷款基础利率(LPR)(Shanghai Interbank Offered Rate,简称Shibor)

    Args:
        year: 年份(YYYY),默认为当前年份
    """
    if not year:
        year = util.get_year()
    data_dicts = bankl_dal.get_lpr(year)
    if data_dicts:
        if util_dal.delete_year_data(LPR, year):
            util_dal.save_year_data(LPR, data_dicts, year)
Example #9
0
def save_operation_ability(year, quarter):
    """得到营运能力

    Args:
        year: 年份, YYYY格式数字
        quarter: 季度, 只能是1, 2, 3, 4的数字
    """
    year = util.get_year() if year is None else year
    data_dicts = base_dal.get_operation_ability(year, quarter)
    if data_dicts:
        if util_dal.delete_year_quarter_data(OperationAbility, year, quarter):
            util_dal.save_year_quarter_data(OperationAbility, data_dicts, year, quarter)
Example #10
0
def save_profit_ability(year, quarter):
    """盈利能力
    
    Args:
        year: 年份, YYYY格式数字
        quarter: 季度, 只能是1, 2, 3, 4的数字
    """
    year = util.get_year() if year is None else year
    data_dicts = base_dal.get_profit_ability(year, quarter)
    if data_dicts:
        if util_dal.delete_year_quarter_data(ProfitAbility, year, quarter):
            util_dal.save_year_quarter_data(ProfitAbility, data_dicts, year, quarter)
Example #11
0
def save_performance_report(year, quarter):
    """业绩报告(主表)
    
    Args:
        year: 年份, YYYY格式数字
        quarter: 季度, 只能是1, 2, 3, 4的数字
    """
    year = util.get_year() if year is None else year
    data_dicts = base_dal.get_performance_report(year, quarter)
    if data_dicts:
        if util_dal.delete_year_quarter_data(PerformanceReport, year, quarter):
            util_dal.save_year_quarter_data(PerformanceReport, data_dicts, year, quarter)
Example #12
0
def get_restricted_stock(year=None,
                         month=None,
                         retry_count=RETRY_COUNT,
                         pause=PAUSE):
    """
    获取限售股解禁数据
    Args
        year:年份,默认为当前年
        month:解禁月份,默认为当前月
        retry_count : int, 默认 3
                     如遇网络等问题重复执行的次数 
        pause : int, 默认 0
    Returns:
        字典的列表
    """
    year = util.get_year() if year is None else year
    month = util.get_month() if month is None else month
    logger.info(
        'Begin get restricted stock data, the year is: %s, month is: %s' %
        (year, month))
    try:
        data_df = ts.xsg_data(year=year,
                              month=month,
                              retry_count=retry_count,
                              pause=pause)
    except Exception as e:
        logging.exception(
            'Error get restricted stock data, the year is: %s, month is: %s' %
            (year, month))
        return None
    else:
        data_dicts = []
        if data_df is not None and not data_df.empty:
            data_dicts = [{
                'code': row[0],
                'name': row[1],
                'year': year,
                'month': month,
                'date': row[2],
                'count': row[3],
                'ratio': row[4],
                'insert_date': today_line
            } for row in data_df.values]
            logger.info(
                'Success get restricted stock data, the year is: %s, month is: %s'
                % (year, month))
        else:
            logger.warn(
                'Empty get restricted stock data, the year is: %s, month is: %s'
                % (year, month))
        return data_dicts
Example #13
0
def get_shibor_ma(year=None):
    """Shibor均值数据(Shanghai Interbank Offered Rate,简称Shibor)

    Args:
        year: 年份(YYYY),默认为当前年份
    """
    if not year:
        year = util.get_year()
    logger.info('Begin get ShiborMA, year is: %s.' % year)
    try:
        data_df = ts.shibor_ma_data(year)
    except Exception as e:
        logger.exception('Error get ShiborMA. year is: %s.' % year)
        return None
    else:
        data_dicts = []
        if data_df is None or data_df.empty:
            logger.warn('Empty get ShiborMA. year is: %s.' % year)
        else:
            data_df['date'] = data_df['date'].astype(str)
            data_dicts = [{
                'date': row[0],
                'on_5': row[1],
                'on_10': row[2],
                'on_20': row[3],
                'W1_5': row[4],
                'W1_10': row[5],
                'W1_20': row[6],
                'W2_5': row[7],
                'W2_10': row[8],
                'W2_20': row[9],
                'M1_5': row[10],
                'M1_10': row[11],
                'M1_20': row[12],
                'M3_5': row[13],
                'M3_10': row[14],
                'M3_20': row[15],
                'M6_5': row[16],
                'M6_10': row[17],
                'M6_20': row[18],
                'M9_5': row[19],
                'M9_10': row[20],
                'M9_20': row[21],
                'Y1_5': row[22],
                'Y1_10': row[23],
                'Y1_20': row[24],
                'year': year
            } for row in data_df.values]
            logger.info('Success get ShiborMA. year is: %s.' % year)
        return data_dicts
Example #14
0
def save_restricted_stock(year=None, month=None):
    """ 限售股解禁数据
    
    Args
        year:年份,默认为当前年
        month:解禁月份,默认为当前月
    """
    year = util.get_year() if year is None else year
    month = util.get_month() if month is None else month
    data_dicts = irdal.get_restricted_stock(year, month)
    if data_dicts:
        if util_dal.delete_year_month_data(RestrictedStock, year, month):
            util_dal.save_year_month_data(RestrictedStock, data_dicts, year,
                                          month)
Example #15
0
def save_cash_flow(year, quarter):
    """得到现金流量

     Args:
         year: 年份, YYYY格式数字
         quarter: 季度, 只能是1, 2, 3, 4的数字
     Returns:
         data_dicts: 字段的列表, return None if have exception, return empty if no data
     """
    year = util.get_year() if year is None else year
    data_dicts = base_dal.get_cash_flow(year, quarter)
    if data_dicts:
        if util_dal.delete_year_quarter_data(CashFlow, year, quarter):
            util_dal.save_year_quarter_data(CashFlow, data_dicts, year, quarter)
Example #16
0
def get_shibor_quote(year=None):
    """银行报价数据

    Args:
        year: 年份(YYYY),默认为当前年份
    """
    if not year:
        year = util.get_year()
    logger.info('Begin get ShiborQuote, year is: %s.' % year)
    try:
        data_df = ts.shibor_quote_data(year)
    except Exception as e:
        logger.exception('Error get ShiborQuote. year is: %s.' % year)
        return None
    else:
        data_dicts = []
        if data_df is None or data_df.empty:
            logger.warn('Empty get ShiborQuote. year is: %s.' % year)
        else:
            data_df['date'] = data_df['date'].astype(str)
            data_dicts = [{
                'date': row[0],
                'bank': row[1],
                'ON': row[2],
                'ON_B': row[3],
                'ON_A': row[4],
                'W1_B': row[5],
                'W1_A': row[6],
                'W2_B': row[7],
                'W2_A': row[8],
                'M1_B': row[9],
                'M1_A': row[10],
                'M3_B': row[11],
                'M3_A': row[12],
                'M6_B': row[13],
                'M6_A': row[14],
                'M9_B': row[15],
                'M9_A': row[16],
                'Y1_B': row[17],
                'Y1_A': row[18],
                'year': year
            } for row in data_df.values]
            logger.info('Success get ShiborQuote. year is: %s.' % year)
        return data_dicts
Example #17
0
def save_fund_holdings(year, quarter):
    """基金持股
    Args:
        year: 年份
        quarter: 季度, 默认删除给定年份的所有季度数据
    """
    year = util.get_year() if year is None else year
    if quarter is None:
        for quarter in QUARTERS:
            data_dicts = irdal.get_fund_holdings(year, quarter)
            if data_dicts:
                if util_dal.delete_year_quarter_data(FundHoldings, year,
                                                     quarter):
                    util_dal.save_year_quarter_data(FundHoldings, data_dicts,
                                                    year, quarter)
    else:
        data_dicts = irdal.get_fund_holdings(year, quarter)
        if data_dicts:
            if util_dal.delete_year_quarter_data(FundHoldings, year, quarter):
                util_dal.save_year_quarter_data(FundHoldings, data_dicts, year,
                                                quarter)
Example #18
0
def save_performance_forecast(year, quarter):
    """业绩预告
    
    Args:
        year: 年份
        quarter: 季度, 默认删除给定年份的所有季度数据
    """
    year = util.get_year() if year is None else year
    if quarter is None:
        for quarter in QUARTERS:
            data_dicts = irdal.get_performance_forecast(year, quarter)
            if data_dicts:
                if util_dal.delete_year_quarter_data(PerformanceForecast, year,
                                                     quarter):
                    util_dal.save_year_quarter_data(PerformanceForecast,
                                                    data_dicts, year, quarter)
    else:
        data_dicts = irdal.get_performance_forecast(year, quarter)
        if data_dicts:
            if util_dal.delete_year_quarter_data(PerformanceForecast, year,
                                                 quarter):
                util_dal.save_year_quarter_data(PerformanceForecast,
                                                data_dicts, year, quarter)
Example #19
0
from utils import util
YEAR = util.get_year()
MONTH = util.get_month()
TODAY = util.get_today()
TODAY_LINE = util.get_today_line()
QUARTER = 2
DATE = '2017-09-29'