def get_valuation_data(code_dict, start_date, end_date): data_dict = dict() for code, name in code_dict.items(): df = CIndex(code).get_val_data() df = df.loc[(df.date >= start_date) & (df.date <= end_date)] df = df.sort_values(by=['date'], ascending = True) df = df.reset_index(drop = True) data_dict[code] = df data_dict['date'] = df.date.tolist() return data_dict
# -*- coding: utf-8 -*- import os import sys import pandas as pd from os.path import abspath, dirname sys.path.insert(0, dirname(dirname(dirname(abspath(__file__))))) from cindex import CIndex pd.set_option('display.max_columns', None) pd.set_option('display.max_rows', None) code = '399006' start_date = '2019-01-01' end_date = '2019-08-11' df = CIndex(code).get_val_data() df = df.sort_values(by=['date'], ascending=True) df = df.reset_index(drop=True) print(df.loc[(df.date > start_date) & (df.date < end_date)])
if __name__ == '__main__': if not os.path.exists('norm.json'): creview = CReivew(ct.DB_INFO) start_date = '2018-02-09' end_date = '2018-09-10' stock_info = CStockInfo.get() stock_info = stock_info[['code', 'name', 'industry', 'timeToMarket']] stock_info = stock_info[(stock_info.timeToMarket < 20180327) & (stock_info.timeToMarket > 0)] if not os.path.exists('index.json'): #上证指数的数据 logger.info("start get index data") szzs_df = CIndex('000001').get_k_data_in_range( start_date, end_date) szzs_df = szzs_df.sort_values(by='date', ascending=True) szzs_df['code'] = 'i000001' szzs_df['name'] = "上证指数" szzs_df['industry'] = "所有" szzs_df['preclose'] = szzs_df['close'].shift(1) szzs_df = szzs_df[szzs_df.date != start_date] szzs_df['pchange'] = 100 * (szzs_df.close - szzs_df.preclose) / szzs_df.preclose #write data to json file with open('index.json', 'w') as f: f.write(szzs_df.to_json(orient='records', lines=True)) else: logger.info("begin read index file") with open('index.json', 'r') as f: szzs_df = pd.read_json(f.read(), orient='records',