def updateAllStocks(): ''' 函数功能: -------- 更新所有股票列表。 输入参数: -------- 无 输出参数: -------- True/False : boolean,是否更新成功。 数据文件 Strategy_Common_AllStock.csv : 参与策略计算的所有股票列表 ''' # Load from Fundamental Stock Basics allstock = loadStockBasics() if not u.isNoneOrEmpty(allstock): # Save to CSV File allstock.set_index('code', inplace=True) file_postfix = '_'.join(['Common', 'AllStock']) u.to_csv(allstock, c.path_dict['strategy'], c.file_dict['strategy'] % file_postfix) return True return False
def get_stock_list(cutoff_date): ''' 函数功能: -------- 获取所有指定日期之前(含)已经上市的股票列表。 输入参数: -------- date,截止时间 e.g. '2016-12-31' 输出参数: -------- DataFrame code,代码 name,名称 industry,所属行业 area,地区 timeToMarket,上市日期 ''' # Check pre-requisite basics = loadStockBasics() if u.isNoneOrEmpty(basics): print('Need to have stock basics!') raise SystemExit # Extract Stock List stocks = basics[basics.timeToMarket <= cutoff_date] stocks = stocks[['code', 'name', 'industry', 'area', 'timeToMarket']] stocks = stocks.sort_values('timeToMarket', axis=0, ascending=True) # Return Dataframe return stocks
def get_cxg(date): ''' 函数功能: -------- 获取所有次新股的股票列表,根据给定的上市时间。 输入参数: -------- date,上市时间 e.g. '2016-01-01' 输出参数: -------- DataFrame code,代码 name,名称 industry,所属行业 area,地区 timeToMarket,上市日期 ''' # Check pre-requisite basics = loadStockBasics() if u.isNoneOrEmpty(basics): print('Need to have stock basics!') raise SystemExit # Extract CXG Data cxg = basics[basics.timeToMarket >= date] cxg = cxg[['code', 'name', 'industry', 'area', 'timeToMarket']] cxg = cxg.sort_values('timeToMarket', axis=0, ascending=True) # Return Dataframe return cxg
def plotHPE(period='M', ratio='PE'): # Check pre-requisite basics = loadStockBasics() if u.isNoneOrEmpty(basics): print('Need to have stock basics!') raise SystemExit # Iterate over all stocks basics_number = len(basics) for i in range(basics_number): stock_id = u.stockID(basics.loc[i, 'code']) # Plot HPE Data plot_HPE(stock_id=stock_id, period=period, ratio=ratio)
def updateFinanceSummary(force_update=True): # Check pre-requisite basics = loadStockBasics() if u.isNoneOrEmpty(basics): print('Need to have stock basics!') raise SystemExit # Iterate over all stocks basics_number = len(basics) for i in range(basics_number): stock_id = u.stockID(basics.loc[i, 'code']) # Check if valid data file already exists if not validFinanceSummary(stock_id, force_update): getFinanceSummary(stock_id) print('Update Finance Summary:', stock_id)
def updatePriceStock(incremental=False): # Check pre-requisite basics = loadStockBasics() if u.isNoneOrEmpty(basics): print('Need to have stock basics!') raise SystemExit # Iterate over all stocks basics_number = len(basics) for i in range(basics_number): stock_id = u.stockID(basics.loc[i, 'code']) time_to_market = u.dateFromStr(basics.loc[i, 'timeToMarket']) getDailyHFQ(stock_id=stock_id, is_index=False, date_start=time_to_market, date_end=date_end, time_to_market=time_to_market, incremental=incremental) print('Update Price:', stock_id)
def cleanStockBasics(): basics = loadStockBasics() print(basics.head(10)) # Format columns basics['code'] = basics['code'].map(lambda x: str(x).zfill(6)) basics['timeToMarket'] = basics['timeToMarket'].map( u.formatDateYYYYmmddInt64) if gs.is_debug: basics_number = len(basics) for i in range(basics_number): if basics.loc[i, 'timeToMarket'] == c.magic_date: print(i, type(basics.loc[i, 'timeToMarket']), basics.loc[i, 'timeToMarket'], basics.loc[i, 'code']) # Filter out invalid timeToMarket stocks basics_nottm = basics[basics.timeToMarket == c.magic_date] basics = basics[basics.timeToMarket != c.magic_date] basics_nottm.set_index('code', inplace=True) basics.set_index('code', inplace=True) # Save to CSV File u.to_csv(basics, c.path_dict['basics'], c.file_dict['basics']) u.to_csv(basics_nottm, c.path_dict['basics'], c.file_dict['basics_nottm'])