Ejemplo n.º 1
0
 def test_load_topx(self):
     df = ak.index_investing_global(country="日本",
                                    index_name="日本东证指数",
                                    period="每日",
                                    start_date="2020-01-01",
                                    end_date="2020-10-01")
     print(df.to_string())
Ejemplo n.º 2
0
    def get_index_daily(self, country, index_name, start_date, end_date,
                        method_name):
        '''
        获取指数一段时间内每天的行情
        :param country: 地区或者国家
        :param index_name: 指数名称
        :param start_date: 开始时间
        :param end_date: 结束时间
        :param method_name: 方法名称
        :return:
        '''
        try:
            index_daily_df = ak.index_investing_global(country=country,
                                                       index_name=index_name,
                                                       period="每日",
                                                       start_date=start_date,
                                                       end_date=end_date)
        except Exception as ex:
            index_daily_df = None
            print("index_investing_global exception, reason:", ex)
        #print(index_daily_df)

        df_list_list = index_daily_df.values.__array__(
        ) if index_daily_df is not None else []
        df_date_list = index_daily_df.axes[
            0].array if index_daily_df is not None else []
        # print(tuple(df_list_list))
        # print(tuple(df_date_list))

        df_list_tuple = []
        for i in range(len(df_list_list)):
            lt = df_list_list[i]
            date = datetime.datetime.date(df_date_list[i])

            if np.isnan(lt[0]) == False:
                df_list_tuple.append(
                    (date, float(lt[1]), float(lt[2]), float(lt[3]),
                     float(lt[0]), float(lt[4])))

        df_tuple_tuple = tuple(df_list_tuple)
        #print(df_tuple_tuple)
        if (len(df_tuple_tuple) > 0):
            flag = False
            try:
                flag = self.common_stock_service.insert_index_daily_batch(
                    index_name, df_tuple_tuple)
                print(index_name, flag, df_tuple_tuple)
            except Exception as ex:
                print(method_name + " exception, reason:", ex)
Ejemplo n.º 3
0
def index_us_daily(code, start_date='2000-01-01', 
                        country='美国', period='每日', **kwargs):
    '''
    return us index daily data for given code symbol to latest datetime
    
    '''
    import datetime
    end_date = datetime.datetime.now().strftime('%Y-%m-%d')
    index_data = ak.index_investing_global(index_name=code, 
                                           country=country, 
                                           period=period,
                                           end_date=end_date,
                                            **kwargs)
    index_data.index.name = 'date'
    index_data.columns = ['close', 'open', 'high', 'low', 'volume']
    return index_data.reset_index()
Ejemplo n.º 4
0
#%%
import akshare as ak
bond_investing_global_df = ak.bond_investing_global(
    country="中国", index_name="中国1年期国债", period="每周", start_date="2000-01-01", end_date="2020-06-06")
print(bond_investing_global_df)

#%% positional
bond_investing_global_df = ak.bond_investing_global(
        country="中国", index_name="中国10年期国债", period="每日", 
        start_date=last_date, end_date=time.strftime(
            '%Y-%m-%d', time.localtime()))

#%%
import akshare as ak
index_us_dollar_df = ak.index_investing_global(
    country="美国", index_name="美元指数", period="每日", 
    start_date="2021-04-20", end_date="2021-04-21")
print(index_us_dollar_df)

#%%
print(index_us_dollar_df.info())
# %%
import akshare as ak
crypto_hist_df = ak.crypto_hist(symbol="比特币", period="每日", 
                                start_date="20100101", 
                                end_date="20210322")
print(crypto_hist_df)

'''

crypto_hist_df.index DatetimeIndex
Ejemplo n.º 5
0

# 获取Shibor隔夜利率数据
last_date = '2021-04-01'
page = '100' if last_date == '1970-01-01' else '5'
rate_interbank = ak.rate_interbank(market="上海银行同业拆借市场",
                                   symbol="Shibor人民币",
                                   indicator="隔夜",
                                   need_page=page)
df = rate_interbank[rate_interbank['日期'] > last_date]
# es_bulk(df, gen_rate_interbank_doc)

#%%
index_us_dollar_df = ak.index_investing_global(country="美国",
                                               index_name="美元指数",
                                               period="每日",
                                               start_date="2007-01-01",
                                               end_date="2021-04-06")
print(index_us_dollar_df)
print(index_us_dollar_df.info())


#%%
# 比特币
def gen_index_us_dollar_doc(df, idx):
    """ 美元指数 """
    return {
        '_index': 'pyfy_index_us_dollar',
        '_source': {
            'date': idx.strftime('%Y-%m-%d'),
            'open': float(df['开盘'][idx]),