예제 #1
0
 def get_fund_holdings(self, ticker, begin_date='', end_date=''):
     df = DataAPI.FundHoldingsGet(ticker=ticker,
                                  beginDate=begin_date,
                                  endDate=end_date)
     df['reportDate'] = df['reportDate'].apply(
         lambda x: str(x).replace('-', ''))
     return df[[
         'reportDate', 'holdingsecType', 'holdingSecID', 'holdVolume',
         'marketValue', 'ratioInNa'
     ]]
_ = PythonOperator(task_id='update_uqer_halt_list',
                   provide_context=True,
                   python_callable=update_uqer_halt_list,
                   dag=dag)

factor_master_task = PythonOperator(task_id='update_factor_master',
                                    provide_context=True,
                                    python_callable=update_factor_master,
                                    dag=dag)

factor_master_task.set_upstream(uqer_task)

if __name__ == '__main__':
    codes = api.FundGet().secID.values
    steps = 1000

    dates = pd.date_range('2005-01-01', '2018-11-30', freq='Q')
    for d in dates:
        start = 0
        total_df = pd.DataFrame()
        while start < len(codes):
            df = api.FundHoldingsGet(secID=codes[start:start + steps],
                                     reportDate=d)
            start += steps
            total_df = total_df.append(df)
        total_df.to_sql('fund_holding',
                        con=engine,
                        index=False,
                        if_exists='append')
        print(d)