Ejemplo n.º 1
0
def update_valuations(xlsx: str):
    mongo = Mongo()
    ms = mongo.find_last('valuation')['_id']
    start = datetime.fromtimestamp(ms / 1000.0).strftime('%Y%m%d')

    wb = load_workbook(xlsx)
    wss = [ws.title for ws in wb.worksheets]
    excel = pd.ExcelFile(xlsx)
    valuations = []
    for ws in wss:
        if not re.search(r'20\d{6}$', ws) or ws <= start:
            continue
        df = pd.read_excel(excel, ws)
        dic = dict(zip(df['名称'].tolist(), df[ws].tolist()))
        dic['_id'] = ws
        valuations.append(dic)

    print(len(valuations))
    if not valuations:
        return
    # the valuation hasn't ('中证500', '美国房地产', '10年期国债(美股)', '10年期国债(A股)', '消费50')
    df = pd.DataFrame(valuations)
    df['_id'] = pd.to_datetime(df['_id'])
    print(df)
    mongo.save('valuation', df)
Ejemplo n.º 2
0
def update_fund_nav(prefix: str, mongo=None):
    if not mongo:
        mongo = Mongo()

    for code in mongo.get_list(prefix):
        ms = mongo.find_last(code)['_id']
        start = datetime.fromtimestamp(ms / 1000.0).strftime('%Y-%m-%d')
        print(code, start)
        df = JqData.fund_nav_daily(code.lstrip(prefix), start)
        if df.empty:
            print('empty')
            continue
        print(df)
        print()
        mongo.save(code, df)