def edit_index_and_fill_na(df: pd.DataFrame):
    # region Description:edit columns and index
    m = MongoDB_io()
    m.set_db('stock_daily_data')
    m.set_collection('stock_ipo_date')
    ipo_df = m.read_data_to_get_dataframe()
    ipo_df['stock_short_name'] = ipo_df.stock.apply(lambda x: x[:6])
    map_series = ipo_df.set_index('stock_short_name').stock
    df = df.reindex(map_series.index, axis=1)
    df.columns = df.columns.map(lambda x: map_series[x])
    df.loc['1990-01-01 00:00:00', :] = 1
    df.sort_index(inplace=True)
    df.index = pd.to_datetime(df.index)
    # endregion

    # region Description:
    df.fillna(method='ffill', inplace=True)
    m.set_collection('stock_trade_date')
    trade_date = m.read_data_to_get_dataframe()
    trade_date_list = trade_date.date.tolist()
    df = df.reindex(trade_date_list, axis=0)
    df.fillna(method='ffill', inplace=True)
    # endregion

    return df
    pass
Esempio n. 2
0
def get_sw_industry():
    logging_joinquant()
    df=get_industries(name='sw_l1')
    df=df.append(get_industries(name='sw_l2'))
    df=df.append(get_industries(name='sw_l3'))
    df.index.name='industry_code'
    df.reset_index(inplace=True)

    # 插入数据库
    m=MongoDB_io()
    m.set_db('stock_daily_data')
    m.set_collection('sw_industry_code')
    m.remove_all_documents_from_mongodb()
    m.insert_dataframe_to_mongodb(df)
def insert_index_data():
    m = MongoDB_io()
    m.set_db('index_daily_data')
    m.set_collection('index_info')
    m.delete_document_include_condition()

    logging_joinquant()
    df = get_all_securities(types='index', date=None)
    df.index.name = 'index'
    df.reset_index(inplace=True)
    df.start_date = pd.to_datetime(df.start_date)
    df.end_date = pd.to_datetime(df.end_date)

    # 插入数据库
    m.insert_huge_dataframe_by_block_to_mongodb(df)
    pass
def insert_zz500_data():
    m = MongoDB_io()
    m.set_db('index_daily_data')
    m.set_collection('000905_XSHG')
    m.delete_document_include_condition()

    logging_joinquant()
    df = get_price('000905.XSHG',
                   start_date='2005-01-01',
                   end_date='2019-09-25',
                   fq=None,
                   frequency='daily')
    df.dropna(inplace=True)
    ## 指数没有复权一说
    # df2=get_price('000905.XSHG',fq='pre')
    df.index.name = 'date'
    df.reset_index(inplace=True)
    df.date = pd.to_datetime(df.date)

    # 插入数据库
    m.insert_huge_dataframe_by_block_to_mongodb(df)
    pass
Esempio n. 5
0
 def __init__(self):
     self.m = MongoDB_io()
     self.nothing = ''
     self.start_trade_date = '1990-01-01'
     pass
Esempio n. 6
0
 def __init__(self):
     self.m = MongoDB_io()
     self.nothing = ''
     pass
from data_base.mongodb import MongoDB_io
import pandas as pd
from decorate_func.decorate_function import typing_func_name

start_date = '2016-01-01'
end_date = '2019-10-05'

m = MongoDB_io()


@typing_func_name
def get_capital_data():
    """
    获得流通市值
    :return:
    """
    m.set_db('stock_daily_data')
    m.set_collection('stock_capital_data')
    df = m.read_data_to_get_dataframe_include_condition(start_date=start_date,
                                                        end_date=end_date)
    return df[['circulating_market_cap', 'code',
               'date']].set_index(['date',
                                   'code']).circulating_market_cap.unstack()
    pass


@typing_func_name
def get_stock_industry():
    """
    获得股票行业分类
    :return:
 def __init__(self):
     self.m = MongoDB_io()
     self.m.set_db('stock_min_data')
     self.nothing = ''
     self.collection_list = self.m.list_collection_names()
     pass