def get_data(self, code, table_name, crawler): values = om.df_from_mongo(table_name, {'code':code}, translate_types=crawler.get_translate_types()) if not base.is_df_validate(values): values = crawler.excute(code) values['code'] = code om.df_to_mongo(table_name, values, crawler.get_keys()) values = om.df_from_mongo(table_name, {'code': code}, translate_types=crawler.get_translate_types()) return values
def do_get_from(self, code, table_name, fun_query, translate_types=None): df_rtn = mongobase.df_from_mongo( table_name, {'code': self.jqDataCrawlerManagerPrivate.format_code_db(code)}, translate_types) if len(df_rtn) is 0: self.jqDataCrawlerManagerPrivate.do_get_from_jq( code, table_name, fun_query) df_rtn = mongobase.df_from_mongo(table_name, { 'code': self.jqDataCrawlerManagerPrivate.format_code_db(code) }, translate_types) return df_rtn
def getLastDf(date): date_str = date.strftime("%Y-%m-%d") resDf = om.df_from_mongo(constant.table_name_k_data, {'date': date_str}, translate_types={'date': datetime.date}) if not base.is_df_validate(resDf) or len(resDf) < 10: date -= datetime.timedelta(days=1) return getLastDf(date) return resDf
def modify_k_data_history(): df_company = om.df_from_mongo(constant.table_name_company) codes = df_company['code'].to_list() for code in codes: start = time.perf_counter() df = om.df_from_mongo(constant.table_name_k_data, {'code': code}) if base.is_df_validate(df): df = df.sort_values(by=['date'], ascending=True) date = df.head(1)['date'].iloc[0] om.update(constant.table_name_k_data_history, {'$set': { 'code': code, 'start_date': date }}, {'code': code}) print((time.perf_counter() - start))
def filter(self, codes): df_task_history = om.df_from_mongo( constant.table_name_task_order_graham_tendency) for code in codes: row = None if base.is_df_validate(df_task_history): row = df_task_history.loc[df_task_history['code'] == code] for key, value in self.grahams.items(): if not self.excute_one(key, value, code, row): break
def regress(date, trade): #sql = 'select * from k_data where code = \'{}\' '.format(code) resDf = om.df_from_mongo(constant.table_name_k_data, {'date': date}, translate_types={'date': datetime.date}) if not base.is_df_validate(resDf): return None df = resDf.sort_values(by=['psTTM'], ascending=False) logging.info('regress :{}'.format(date)) for index, row in df.iterrows(): if _is_support(row['peTTM']): trade.buy(row) else: trade.sell(row)
last_last_year_total_profit = get_value_year(incomes, year - 1, 'report_date', ['total_profit']) if last_year_total_profit is None or last_last_year_total_profit is None: return False last_year_total_profit = last_year_total_profit.get('total_profit') last_last_year_total_profit = last_last_year_total_profit.get( 'total_profit') if last_year_total_profit is None or last_last_year_total_profit is None: return False return (float(last_year_total_profit) - float(last_last_year_total_profit)) \ / float(last_last_year_total_profit) > (-5 / 100) if __name__ == '__main__': base.init_applicaiton() stockTendency = GrahamTendency() df_company = om.df_from_mongo(constant.table_name_company) codes = df_company['code'].to_list() codes = ['sh.600606'] #orderGrahamTendency = OrderGrahamTendency() #orderGrahamTendency.filter(codes) #GrahamBalance().filter(codes) #GrahamBalance().filter(codes) for Tendency in GrahamTendency.__subclasses__(): Tendency().filter(codes)