def study_one_good_deep(self, start_collection_name = None): collectionName = start_collection_name endValue = "2016-11-17" duration = ("2016-06-05", endValue) monitorCount = 5 study_count = 20 dbHelper = DBHelper() study_good_ratio = 0.03 chooseParam = self.adjust_params["normal"] bollIndex = IndexBoll(collectionName, duration = duration, monitor_count = 2 , study_count = study_count, study_good_ratio = study_good_ratio) goodTables = bollIndex.study_good() realGoodTables = [] #dbHelper.print_values(goodTables, 20,[G_CONST_DATE_FIELD_NAME, G_CONST_STUDY_DEAL_DAYS, G_CONST_STUDY_GOOD_VALUE, G_CONST_STUDY_REAL_RATE, G_CONST_STUDY_CORRECT],False) if(len(goodTables) > 0): for goodPoint in goodTables: dateValue = goodPoint[G_CONST_DATE_FIELD_NAME] kdjIndex = IndexKDJ(collectionName, verify_date = dateValue, monitor_count = 3, study_count = study_count, study_good_ratio = study_good_ratio) #macdIndex = IndexMACD(collectionName, verify_date = dateValue, monitor_count = monitorCount, study_count = study_count) #rsiIndex = IndexRSI(collectionName, verify_date = dateValue, monitor_count = monitorCount, study_count = study_count) #self.logger.logInfo("kdj good is {}".format(dateValue)) #if(macdIndex.is_good_by()): #self.logger.logInfo("kdj good is {}".format(dateValue)) if(True or kdjIndex.is_good_by()): #self.logger.logInfo("---macd good is {}".format(dateValue)) #if(rsiIndex.is_good_by()): #self.logger.logInfo("------macd good is {}".format(dateValue)) #self.logger.logInfo("-------------[{}] good collection_name is {}".format(dateValue, collectionName) ) realGoodTables.append(goodPoint) if(len(realGoodTables) > 0): self.logger.logInfo("-------------[] good collection_name is {}".format(collectionName) ) dbHelper.print_values(realGoodTables, 20,[G_CONST_DATE_FIELD_NAME, G_CONST_STUDY_DEAL_DATE, G_CONST_STUDY_DEAL_DAYS, G_CONST_STUDY_REAL_RATE, G_CONST_STUDY_CORRECT,G_CONST_STUDY_DEAL_START_VALUE,G_CONST_STUDY_DEAL_END_VALUE],False) return realGoodTables
def study_good_deep(self, start_collection_name = None): dbSetHandler = MogoDBSetHandler(db_server = G_CONST_DB_SERVER, db_port= G_CONST_DB_PORT, db_instance= G_CONST_DB_INSTANCE_NAME) collectionNames = dbSetHandler.get_all_collections() collectionNames.sort() index = 0 needSkip = (start_collection_name != None) goodIndexes = [] endValue = "2016-10-11" duration = ("2015-11-05", endValue) monitorCount = 5 study_count = 20 study_good_ratio = 0.03 dbHelper = DBHelper() chooseParam = self.adjust_params["normal"] for collectionName in collectionNames: #hList = self.reader.getAllValues(tag) if(needSkip and collectionName == start_collection_name): needSkip = False if(needSkip): continue index += 1 self.logger.logInfo("[" + str(index) + "]collection_name " + collectionName) #if(index > 100): #break realGoodTables = self.study_one_good_deep(collectionName) if(len(realGoodTables) > 0): goodIndexes.append([collectionName, realGoodTables]) return goodIndexes
def __init__(self, collection_name, monitor_count=10, duration=None, study_count=200, verify_date=None, verify_count=300, study_good_ratio=0.05, study_good_count=10): self.logger = Logger() self.collection_name = collection_name self.latest_date = "now" self.start_time_field_name = "start_time" self.end_time_field_name = "end_time" self.duration = duration self.monitor_count = monitor_count self.study_count = study_count self.verify_date = verify_date self.verify_count = verify_count self.raw_data = None self.index_calculator = CommonIndex() self.db_helper = DBHelper() self.unit_helper = UnitHelper() self.latest_date = None self.data = None self.study_good_ratio = study_good_ratio self.study_good_count = study_good_count
def print_data(self, data, line_count = 100, fields = []): db_helper = DBHelper() db_helper.print_values(data, line_count, fields)
#if(macdIndex.is_good_by()): #self.logger.logInfo("kdj good is {}".format(dateValue)) if(True or kdjIndex.is_good_by()): #self.logger.logInfo("---macd good is {}".format(dateValue)) #if(rsiIndex.is_good_by()): #self.logger.logInfo("------macd good is {}".format(dateValue)) #self.logger.logInfo("-------------[{}] good collection_name is {}".format(dateValue, collectionName) ) realGoodTables.append(goodPoint) if(len(realGoodTables) > 0): self.logger.logInfo("-------------[] good collection_name is {}".format(collectionName) ) dbHelper.print_values(realGoodTables, 20,[G_CONST_DATE_FIELD_NAME, G_CONST_STUDY_DEAL_DATE, G_CONST_STUDY_DEAL_DAYS, G_CONST_STUDY_REAL_RATE, G_CONST_STUDY_CORRECT,G_CONST_STUDY_DEAL_START_VALUE,G_CONST_STUDY_DEAL_END_VALUE],False) return realGoodTables if __name__ == '__main__': logger = Logger() dbHelper = DBHelper() indexManager = IndexManager(logger) #indexManager.update_all_index() indexes = indexManager.find_good_index(seek_number = 20) print(indexes) #goodIndex = indexManager.study_good_deep("history_table_002608_sz") ''' for hIndex in goodIndex: indexName = hIndex[0] values = hIndex[1] logger.logInfo("good collection is ".format(indexName)) dbHelper.print_values(values, 20,[G_CONST_DATE_FIELD_NAME, G_CONST_STUDY_DEAL_DATE, G_CONST_STUDY_DEAL_DAYS, G_CONST_STUDY_REAL_RATE, G_CONST_STUDY_CORRECT,G_CONST_STUDY_DEAL_START_VALUE,G_CONST_STUDY_DEAL_END_VALUE],False) #590 '''
indexData = index_data if (len(indexData) == 0): return False dateInfo = indexData[0] is_good = 3 monitorCount = self.monitor_count firstRsiValue = dateInfo[G_CONST_CALCULATION_RSI_12_NAME] endDateInfo = indexData[monitorCount - 1] endRsiValue = endDateInfo[G_CONST_CALCULATION_RSI_12_NAME] if (firstRsiValue < 0 and firstRsiValue < endRsiValue): is_good = 0 return is_good if __name__ == '__main__': dbHelper = DBHelper() stock_number = "000004" stock_tag = "sz" collection_name = G_CONST_DB_DETAIL_TABLE + "_" + stock_number + "_" + stock_tag duration = ("2015-05-05", "2016-09-08") indx_handler = IndexRSI(collection_name, duration=duration, study_count=500) #indx_handler.update_data() #raw_data = indx_handler.get_raw_data() #raw_data.reverse() #dbHelper.print_values(raw_data, 20) #raw_data.reverse() data_rsi = indx_handler.get_refined_data() #print("count is " + str(len(raw_data))) dbHelper.print_values(data_rsi, 40, [
def is_below_mid(self, index_data, index, monitor_count=3): monitorCount = monitor_count if (len(index_data) <= index + monitorCount): return False isGood = True for i in range(0, monitorCount): nextDateInfo = index_data[index + i] n_macdDea = nextDateInfo[G_CONST_CALCULATION_MACD_DEA_NAME] if (0 < n_macdDea): isGood = False break return isGood if __name__ == '__main__': dbHelper = DBHelper() stock_number = "000966" stock_tag = "sz" collection_name = G_CONST_DB_DETAIL_TABLE + "_" + stock_number + "_" + stock_tag #macd_days = [5, 10, 2] #indx_handler = IndexMACD(collection_name, macd_days) #raw_data = indx_handler.get_raw_data() #raw_data.reverse() #dbHelper.print_values(raw_data, 40, [G_CONST_DATE_FIELD_NAME, G_CONST_ClOSE_FIELD_NAME], False) ''' data_macd = indx_handler.get_index_data(raw_data) EMA26FIELD = "INDEX_MACD_" + "EMA_26" EMA12FIELD = "INDEX_MACD_" + "EMA_12" DIFFFIELD = "INDEX_MACD_" + "MACDDIFF_9" DEAFIELD = "INDEX_MACD_" + "MACDDEA_9" BARFIELD = "INDEX_MACD_" + "MACDBAR_9"