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
from jqdatasdk import * from data_base.mongodb import MongoDB_io auth('15915765128', '87662638qjf') start_date = '2005-01-01' 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) pass # 插入数据库 m = MongoDB_io() m.set_db('stock_daily_data') m.set_collection('stock_sw_industry_code') m.insert_huge_dataframe_by_block_to_mongodb(df) ## 后面加上更新验证模块。 pass
from data_base.mongodb import MongoDB_io auth('15915765128','87662638qjf') start_date='2005-01-01' trade_date_list=get_trade_days(start_date=start_date, end_date=None, count=None) trade_date_info_df=pd.DataFrame() trade_date_info_df['trade_date']=trade_date_list trade_date_info_df['weekday']=trade_date_info_df['trade_date'].apply(lambda x:x.weekday())+1.0 trade_date_info_df['trade_month']=trade_date_info_df['trade_date'].apply(lambda x:str(x)[:7]) def get_ordinal_of_date(x): x['ordinal_in_month']=range(x.shape[0]) x['ordinal_in_month']=x['ordinal_in_month']+1.0 return x pass trade_date_info_df=trade_date_info_df.groupby('trade_month').apply(get_ordinal_of_date) trade_date_info_df['trade_date']=pd.to_datetime(trade_date_info_df['trade_date']) # 插入数据库 m=MongoDB_io() m.set_db('stock_daily_data') m.set_collection('stock_trade_date') m.insert_huge_dataframe_by_block_to_mongodb(trade_date_info_df) ## 后面加上更新验证模块。 pass
auth('15915765128', '87662638qjf') m = MongoDB_io() m.set_db('stock_daily_data') m.set_collection('stock_sw_industry_code') sw_indus = m.read_data_to_get_dataframe() m.set_collection('stock_trade_date') trade_day_df = m.read_data_to_get_dataframe() trade_day_df = trade_day_df[ trade_day_df.trade_date > pd.to_datetime('2010-01-01')] trade_day_list = trade_day_df.trade_date.astype(str) industry_code_list = sw_indus.industry_code.iloc[:34].tolist() industry_stock_grouping = pd.DataFrame() for date in trade_day_list: print(date) daily_industry_series = pd.Series() for industry_code in industry_code_list[:]: stock_list = get_industry_stocks(industry_code, date=date) daily_industry_series = daily_industry_series.append( pd.Series(industry_code, index=stock_list)) pass daily_industry_series.name = pd.to_datetime(date) daily_industry_df = daily_industry_series.to_frame() daily_industry_df_stack_up = daily_industry_df.stack().reset_index() daily_industry_df_stack_up.columns = ['stock', 'date', 'industry_category'] m.set_collection('stock_sw_industry_category') m.insert_huge_dataframe_by_block_to_mongodb(daily_industry_df_stack_up) pass