Ejemplo n.º 1
0
def upsert_yahoo_recommend(symbol: str):
    yahoo_ts = yFinanceData()
    try:
        df = yahoo_ts.recommendations(symbol_to_yahoo_symbol(symbol))
        logger.info(f"upsert_yahoo_recommend : {symbol}-{df.shape}")
        for t, row in df.iterrows():
            firm = GlobalEntity(entity_id=row["Firm"])
            dict_info = {
                "t":
                t,
                "symbol":
                FinancialInstrumentSymbol(symbol=symbol),
                "firm":
                firm,
                "uid":
                md5_str(f"{t.isoformat()}-{symbol}-{row['Firm']}"),
                "to_grade":
                None if row["To Grade"] == "" else row["To Grade"],
                "from_grade":
                None if row["From Grade"] == "" else row["From Grade"],
                "action":
                None if row["Action"] == "" else row["Action"]
            }
            upsert_document(firm)
            upsert_document(FinancialInstrumentRecommendInYahoo(**dict_info),
                            False)
    except Exception as ex:
        logger.error(ex)
        return
Ejemplo n.º 2
0
def upsert_chn_stock_info_in_yahoo():
    set_http_proxy()
    tushare = TuShareProData()
    df = tushare.stock_basic(exchange="SSE", cols=["ts_code", "name"])
    for idx, row in df.iterrows():
        symbol = row["ts_code"].replace("SH", "SS")  # YAHOO 上海股市的后缀是 SS
        logger.info(f"[{idx}] {symbol}({row['name']}) symbol data in yahoo")
        upsert_yahoo_financial_instrument_info(symbol, True)

    df = tushare.stock_basic(exchange="SZSE", cols=["ts_code", "name"])
    for idx, row in df.iterrows():
        symbol = row["ts_code"]  # 深圳股市的后缀是相同的
        logger.info(f"[{idx}] {symbol}({row['name']}) symbol data in yahoo")
        upsert_yahoo_financial_instrument_info(symbol, True)
Ejemplo n.º 3
0
def upsert_splits(symbol: str, start_t: datetime):
    yahoo_ts = yFinanceData()
    try:
        df = yahoo_ts.splits(symbol_to_yahoo_symbol(symbol), start=start_t)
        logger.info(f"upsert_splits : {symbol}-{df.shape}")
        for t, row in df.iterrows():
            dict_info = {
                "t": t,
                "split": row["Stock Splits"],
                "symbol": FinancialInstrumentSymbol(symbol=symbol),
                "uid": md5_str(f"{t.isoformat()}-{symbol}")
            }
            upsert_document(FinancialInstrumentDividends(**dict_info))
    except:
        return
Ejemplo n.º 4
0
def upsert_us_stock_nametable_and_chn_name():
    akshare_data = akshareData()
    df_us_stocks = akshare_data.get_us_stock_name()
    logger.info(f"table shape:{df_us_stocks.shape}")
    for idx, row in df_us_stocks.iterrows():
        if idx <= 9425:
            continue
        symbol = row["symbol"]
        chn_name = row["cname"]
        eng_name = row["name"]
        logger.info(f"[{idx}] {symbol} - {chn_name} - {eng_name}")
        fin_data = FinancialInstrumentSymbol(symbol=symbol,
                                             full_name=eng_name,
                                             eng_name=eng_name,
                                             chn_name=chn_name)
        upsert_document(fin_data)
        upsert_yahoo_financial_instrument_info(symbol, True)
Ejemplo n.º 5
0
def upsert_yahoo_symbol_holder(symbol: str):
    import yfinance as yf
    symbol_data = yf.Ticker(symbol_to_yahoo_symbol(symbol))
    try:
        df = symbol_data.institutional_holders
        logger.info(f"upsert_yahoo_symbol_holder : {symbol} {df.shape}")
        for idx, row in df.iterrows():
            t = row["Date Reported"]
            dict_info = {
                "t": t,
                "symbol": FinancialInstrumentSymbol(symbol=symbol),
                "holder": GlobalEntity(entity_id=row["Holder"]),
                "shares": row["Shares"],
                "value": row["Value"],
                "percentage_out": row["% Out"],
                "uid": md5_str(f"{t.isoformat()}-{symbol}-{row['Holder']}")
            }
            upsert_document(FinancialInstrumentHolders(**dict_info), True)
    except Exception as ex:
        logger.error(f"api exception when get data , {ex}")
Ejemplo n.º 6
0
def upsert_daily_market_data(symbol: str, start_t: datetime):
    yahoo_ts = yFinanceData()
    df = yahoo_ts.history(symbol_to_yahoo_symbol(symbol), start=start_t)
    logger.info(f"upsert_daily_market_data : {symbol}-{df.shape}")
    df["fifty_two_week_high"] = df["Close"].rolling(window=244).max()
    df["fifty_two_week_low"] = df["Close"].rolling(window=244).min()

    for t, row in df.iterrows():
        dict_info = {
            "t": t,
            "open": row["Open"],
            "high": row["High"],
            "low": row["Low"],
            "close": row["Close"],
            "volume": row["Volume"],
            "dividends": row["Dividends"],
            "splits": row["Stock Splits"],
            "fifty_two_week_low": row["fifty_two_week_low"],
            "fifty_two_week_high": row["fifty_two_week_high"],
            "symbol": FinancialInstrumentSymbol(symbol=symbol),
            "uid": md5_str(f"{t.isoformat()}-{symbol}")
        }
        upsert_document(FinancialInstrumentDailyMarketData(**dict_info))
Ejemplo n.º 7
0
def upsert_yahoo_earning_analysis(symbol: str):
    """see https://finance.yahoo.com/quote/MSFT/analysis?p=MSFT"""
    import yfinance as yf
    symbol_data = yf.Ticker(symbol_to_yahoo_symbol(symbol))
    try:
        df = symbol_data.calendar.T
        logger.info(f"upsert_yahoo_earning_analysis : {symbol}  {df.shape}")
        for idx, row in df.iterrows():
            t = row["Earnings Date"]
            dict_info = {
                "t": t,
                "symbol": FinancialInstrumentSymbol(symbol=symbol),
                "earnings_average": _convert_non_t_v(row["Earnings Average"]),
                "earnings_low": _convert_non_t_v(row["Earnings Low"]),
                "earnings_high": _convert_non_t_v(row["Earnings High"]),
                "revenue_average": _convert_non_t_v(row["Revenue Average"]),
                "revenue_low": _convert_non_t_v(row["Revenue Low"]),
                "revenue_high": _convert_non_t_v(row["Revenue High"]),
                "uid": md5_str(f"{t.isoformat()}-{symbol}")
            }
            upsert_document(FinancialInstrumentCalendarFromYahoo(**dict_info),
                            True)
    except Exception as ex:
        logger.error(f"api exception when get data , {ex}")