| | |
| | | è·å交æåæ° |
| | | @return: |
| | | """ |
| | | result = strategy_params_settings.settings.to_json_str() |
| | | return {"code": 0, "data": result} |
| | | result = strategy_params_settings.StrategyParamsSettingsManager().get_settings().to_json_str() |
| | | return {"code": 0, "data": json.loads(result)} |
| | | |
| | | def __on_set_settings(self, data): |
| | | """ |
| | | 设置交æåæ° |
| | | @return: |
| | | """ |
| | | settings = strategy_params_settings.StrategyParamsSettingsManager().get_settings() |
| | | for k in data: |
| | | settings.__setattr__(k, data[k]) |
| | | strategy_params_settings.StrategyParamsSettingsManager().set_settings(settings) |
| | | # åæ¥åæ°è®¾ç½® |
| | | return {"code": 0, "data": {}} |
| | | |
| | | def __on_get_env(self, need_hsitory_data): |
| | | """ |
| | |
| | | else: |
| | | # 妿å¨16:00ä¹åéç¨ä¸ä¸ä¸ªäº¤ææ¥ |
| | | day = TradeDateManager().get_next_trade_day(tool.get_now_date_str()) |
| | | fdata["history_data"]["leading_limit_up_block_codes_count"] = env_info.get_leading_limit_up_block_codes_count( |
| | | fdata["history_data"][ |
| | | "leading_limit_up_block_codes_count"] = env_info.get_leading_limit_up_block_codes_count( |
| | | day) |
| | | |
| | | if tool.get_now_time_str() < '16:00:00': |
| | |
| | | result_json = {} |
| | | if ctype == "get_settings": |
| | | result_json = self.__on_get_settings() |
| | | elif ctype == 'set_settings': |
| | | del data["ctype"] |
| | | result_json = self.__on_set_settings(data) |
| | | elif ctype == 'get_env': |
| | | result_json = self.__on_get_env(data.get("history")) |
| | | elif ctype == 'update_leading_limit_up_datas': |
| | |
| | | # ä¿åTick线 |
| | | with open(tick_path, encoding='utf-8', mode='w') as f: |
| | | f.write(f"{results}") |
| | | print("å©ä½æ°éï¼", len(set(batch_codes) - excute_codes)) |
| | | finally: |
| | | excute_codes.add(code) |
| | | if show_log: |
| | |
| | | """ |
| | | import json |
| | | |
| | | from db.mysql_data_delegate import Mysqldb |
| | | from utils import tool |
| | | |
| | | |
| | | class StrategyParamsSettings: |
| | | # ç¦æ¢ä¹°å
¥ |
| | | STATE_FORBIDDEN_BUY = 0 |
| | |
| | | self.trade_state = 1 |
| | | # ä¹°å
¥éé¢ |
| | | self.buy_money = 2000 |
| | | # æå¤§ä¹°å
¥ç¥¨çæ°é |
| | | self.max_buy_codes_count = 10 |
| | | # ä»·æ ¼åºé´ |
| | | self.price_range = (3, 60) |
| | | # èé¢ææ¶¨åæ° |
| | |
| | | # æ¯å¦å¯ä¹°ä»æ¥æ¶¨åè¿ç票 |
| | | self.can_buy_limited_up = False |
| | | # æä½å¼ç涨å¹
|
| | | self.min_open_rate = -0.03 |
| | | self.min_open_rate = 0.00001 |
| | | # å¯ä¹°ç涨å¹
æ¯ä¾ |
| | | self.avaiable_rates = (-0.03, 0.07) |
| | | # 仿¥æ¶¨åä»·éçªç ´XXæ¥æé«ä»·,Noneè¡¨ç¤ºæ¤æ¡æ°æ®ä¸çæ |
| | |
| | | return obj |
| | | |
| | | |
| | | settings: StrategyParamsSettings = StrategyParamsSettings() |
| | | @tool.singleton |
| | | class StrategyParamsSettingsManager: |
| | | def __init__(self): |
| | | self.musql = Mysqldb() |
| | | self.__settings = StrategyParamsSettings() |
| | | self.__load_data() |
| | | |
| | | def __load_data(self): |
| | | sql = f"select `value` from config where `key` = 'low_suction_settings'" |
| | | setting_str_list = self.musql.select_one(sql) |
| | | if setting_str_list and setting_str_list[0]: |
| | | self.__settings = StrategyParamsSettings.to_obj(setting_str_list[0]) |
| | | |
| | | def set_settings(self, settings: StrategyParamsSettings): |
| | | sql = f"update config set `value` = '{settings.to_json_str()}' where `key` = 'low_suction_settings'" |
| | | self.musql.execute(sql) |
| | | self.__settings = settings |
| | | |
| | | def get_settings(self): |
| | | return self.__settings |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | settings = StrategyParamsSettingsManager().get_settings() |
| | | StrategyParamsSettingsManager().set_settings(settings) |
| | |
| | | def load_target_plate_and_codes(self): |
| | | """ |
| | | å è½½ç®æ æ¿åä¸å¯¹åºç代ç ï¼ |
| | | 仿è¿120ä¸ªäº¤ææ¥ççæ£æ¶¨åæ°æ®ä¸ |
| | | 仿è¿60ä¸ªäº¤ææ¥ççæ£æ¶¨åæ°æ®ä¸ |
| | | @return: {"æ¿å":[代ç ]} |
| | | """ |
| | | end_date = self.trade_days[:60][-1] |
| | |
| | | if results: |
| | | results = [x for x in results if |
| | | (tool.is_can_buy_code(x[0]) and x[0] in valid_codes and x[0] not in exclude_codes)] |
| | | max_count = len(results) // 3 if len(results) % 3 == 0 else len(results) // 3 + 1 |
| | | results = results[:max_count] |
| | | # åå10 |
| | | results = results[:10] |
| | | # åå1/3䏿¶¨åæ°æ¯å10 |
| | | # max_count = len(results) // 3 if len(results) % 3 == 0 else len(results) // 3 + 1 |
| | | # results = results[:max_count] |
| | | # # åå10 |
| | | # results = results[:10] |
| | | codes = [x[0] for x in results] |
| | | fresults[kpl_util.filter_block(b)] = codes |
| | | return fresults |
| | |
| | | from strategy.data_analyzer import KPLLimitUpDataAnalyzer |
| | | from strategy.data_downloader import DataDownloader |
| | | from strategy.low_suction_strategy import LowSuctionOriginDataExportManager |
| | | from strategy.strategy_params_settings import StrategyParamsSettings |
| | | from strategy.strategy_params_settings import StrategyParamsSettings, StrategyParamsSettingsManager |
| | | from strategy.strategy_variable import StockVariables |
| | | from strategy.strategy_variable_factory import DataLoader, StrategyVariableFactory |
| | | from third_data import kpl_util |
| | |
| | | |
| | | class BackTest: |
| | | |
| | | def __init__(self, day, script_name="ä½å¸èæ¬_辨è¯åº¦_v3.py", settings=StrategyParamsSettings()): |
| | | def __init__(self, day, script_name="ä½å¸èæ¬_辨è¯åº¦_v3.py", settings=StrategyParamsSettingsManager().get_settings()): |
| | | self.day = day |
| | | scripts = "" |
| | | with open(script_name, mode='r', encoding='utf-8') as f: |
| | |
| | | # "2025-05-15", "2025-05-16", "2025-05-19", "2025-05-20", "2025-05-21", "2025-05-22"] |
| | | days = ["2025-05-12", "2025-05-13", "2025-05-14", "2025-05-15", "2025-05-16", "2025-05-19", "2025-05-20", |
| | | "2025-05-21", "2025-05-22", "2025-05-23", "2025-05-26", "2025-05-27", "2025-05-28", "2025-05-29", |
| | | "2025-05-30", "2025-06-03", "2025-06-04", "2025-06-05", "2025-06-06", "2025-06-09"] |
| | | "2025-05-30", "2025-06-03", "2025-06-04", "2025-06-05", "2025-06-06", "2025-06-09", "2025-06-10"] |
| | | days.reverse() |
| | | for day in days: |
| | | if day not in back_test_dict: |
| | |
| | | if target_code.find("60") != 0 and target_code.find("00") != 0 and target_code.find("30") != 0: |
| | | return False, "ç§åæ¿ç票ä¸ä¹°" |
| | | |
| | | if sv.æ¿åæäº¤ä»£ç : |
| | | deal_codes = set() |
| | | for p in sv.æ¿åæäº¤ä»£ç : |
| | | deal_codes |= set(sv.æ¿åæäº¤ä»£ç [p]) |
| | | if len(deal_codes) >= settings.max_buy_codes_count: |
| | | return False, f"ä¹°å
¥ä»£ç æ°è¶
é({len(deal_codes)}/{settings.max_buy_codes_count})" |
| | | |
| | | # ç®æ 票æ¿å涨å个æ°>=2 |
| | | can_buy_plates = set() |
| | | for plate in sv.ä»£ç æ¿å: |
| | |
| | | |
| | | limit_up_codes_count = max([(p, len(sv.å¼çå¦ææ£æ¿å涨å.get(p, []))) for p in can_buy_plates], key=lambda x: x[1])[1] |
| | | |
| | | threshold_money *= max(min(10 - limit_up_codes_count + 3, 10), 5)/10 |
| | | threshold_money *= max(min(10 - limit_up_codes_count + 1, 10), 5) / 10 |
| | | |
| | | # print(target_code, sv.èªç±æµéå¸å¼, threshold_money, limit_up_codes_count) |
| | | |
| | | |
| | | # threshold_money = 200e4 # int(sv.æ¨æ¥æäº¤é * 0.2 * sv.仿¥æ¶¨åä»· * 0.05) |
| | | if big_order_money < threshold_money: |