-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
926 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
""" | ||
Author: Charmve [email protected] | ||
Date: 2023-05-14 18:18:42 | ||
LastEditors: Charmve [email protected] | ||
LastEditTime: 2024-03-29 13:44:26 | ||
FilePath: /qbot_pro/qbot/engine/config.py | ||
Version: 1.0.1 | ||
Blogs: charmve.blog.csdn.net | ||
GitHub: https://github.com/Charmve | ||
Description: | ||
Copyright (c) 2023 by Charmve, All Rights Reserved. | ||
Licensed under the MIT License. | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
QBOT_TOP_DIR = Path(__file__).parent.parent.parent | ||
|
||
DATA_DIR = Path(__file__).parent.parent.parent.joinpath("data") | ||
RESULT_DIR = Path(__file__).parent.parent.parent.joinpath("results") | ||
ASSERTS_DIR = Path(__file__).parent.parent.joinpath("asserts") | ||
DOCS_DIR = Path(__file__).parent.parent.parent.joinpath("docs") | ||
ENGINE_DIR = Path(__file__).parent.parent.parent.joinpath("qbot/engine") | ||
|
||
DATA_DIR_HDF5 = DATA_DIR.joinpath("hdf5") | ||
DATA_DIR_CSV = DATA_DIR.joinpath("stocks") | ||
FUTURES_DATA_DIR = DATA_DIR.joinpath("futures") | ||
FUNDS_DATA_DIR = DATA_DIR.joinpath("funds") | ||
BTC_DATA_DIR = DATA_DIR.joinpath("btc") | ||
OPTIONS_DATA_DIR = DATA_DIR.joinpath("options") | ||
|
||
MULTI_FACTS_DIR = DATA_DIR.joinpath("multi-facts") | ||
QLIB_MLRUNS_DIR = DATA_DIR.joinpath("qlib_mlruns") | ||
QLIB_DATA_DIR = DATA_DIR.joinpath("qlib_data") | ||
DATA_DIR_HDF5_ALL = DATA_DIR_HDF5.joinpath("all.h5") | ||
DATA_DIR_HDF5_CACHE = DATA_DIR_HDF5.joinpath("cache.h5") | ||
|
||
DATA_DIR_HDF5_BKT_RESULTS = RESULT_DIR.joinpath("hdf5") | ||
BKT_RESULT_DIR = RESULT_DIR.joinpath("bkt_result") | ||
INDICAT_RESULT_DIR = RESULT_DIR.joinpath("indicators") | ||
BACKTEST_RESULT_DIR = RESULT_DIR.joinpath("bk_result") | ||
|
||
RESEARCH_REPORTS = DOCS_DIR.joinpath("research_reports") | ||
NOTEBOOK_DIR = DOCS_DIR.joinpath("notebook") | ||
|
||
STOCK_LIST_CSV = DATA_DIR.joinpath("stock_code.csv") | ||
FUTURES_LIST_CSV = DATA_DIR.joinpath("futures_code.csv") | ||
OPTIONS_LIST_CSV = DATA_DIR.joinpath("options_code.csv") | ||
|
||
TOKENS_FILE = ENGINE_DIR.joinpath("tokens.json") | ||
|
||
STOCK_REAL_ACCOUNT = ENGINE_DIR.joinpath("trade/engine_apis/stocks/account.json") | ||
FUTURES_REAL_ACCOUNT = ENGINE_DIR.joinpath("trade/engine_apis/futures/account.json") | ||
OPTIONS_REAL_ACCOUNT = ENGINE_DIR.joinpath("trade/engine_apis/options/account.json") | ||
BTC_REAL_ACCOUNT = ENGINE_DIR.joinpath("trade/engine_apis/btc/account.json") | ||
FUNDS_REAL_ACCOUNT = ENGINE_DIR.joinpath("trade/engine_apis/funds/account.json") | ||
|
||
STOCK_SIM_ACCOUNT = ENGINE_DIR.joinpath("trade/engine_apis/stocks/sim_account.json") | ||
FUTURES_SIM_ACCOUNT = ENGINE_DIR.joinpath("trade/engine_apis/futures/sim_account.json") | ||
OPTIONS_SIM_ACCOUNT = ENGINE_DIR.joinpath("trade/engine_apis/options/sim_account.json") | ||
BTC_SIM_ACCOUNT = ENGINE_DIR.joinpath("trade/engine_apis/btc/sim_account.json") | ||
FUNDS_SIM_ACCOUNT = ENGINE_DIR.joinpath("trade/engine_apis/funds/sim_account.json") | ||
|
||
dirs = [ | ||
DATA_DIR, | ||
RESULT_DIR, | ||
DATA_DIR_CSV, | ||
BKT_RESULT_DIR, | ||
INDICAT_RESULT_DIR, | ||
MULTI_FACTS_DIR, | ||
QLIB_MLRUNS_DIR, | ||
QLIB_DATA_DIR, | ||
DATA_DIR_HDF5_BKT_RESULTS, | ||
RESEARCH_REPORTS, | ||
NOTEBOOK_DIR, | ||
] | ||
for dir in dirs: | ||
dir.mkdir(exist_ok=True, parents=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import json | ||
import re | ||
|
||
|
||
def extract_content(text): | ||
pattern = r"\((.*?)\)" # 匹配()之间的内容 | ||
result = re.findall(pattern, text) | ||
return result | ||
|
||
|
||
def save_strings_as_json(str_data, file_path): | ||
data = json.loads(str_data) | ||
json_str = json.dumps(data) | ||
|
||
with open(file_path, "w") as file: | ||
file.write(json_str) | ||
|
||
def file2dict(path): | ||
with open(path, encoding="utf-8") as f: | ||
return json.load(f) | ||
|
||
def list_files_in_directory(path, file_suffix=[".csv"]): | ||
files_list = [] | ||
for root, dirs, files in os.walk(path): | ||
for file_suf in file_suffix: | ||
for file in files: | ||
files_list.append(file.strip(file_suf)) | ||
return files_list | ||
|
||
# data_str=""" | ||
# { | ||
# 'universe': ['000300.SH', '000905.SH', '399006.SZ', 'SPX'], | ||
# 'benchmarks': ['000300.SH'], | ||
# 'factors': [ | ||
# ('rate', '$close/Ref($close,1) -1'), | ||
# ('mom_20', '$close/Ref($close,20) -1'), | ||
# ('buy_1', '$mom_20>0.08'), | ||
# ('sell_1', '$mom_20<0') | ||
# ], | ||
# 'factors_date': [('rank', '$mom_20')], | ||
# 'buy': (['buy_1'], 1), | ||
# 'sell': (['sell_1'], 1), | ||
# 'order_by': ('rank', 2) # 从大到小, 取前2 | ||
# } | ||
# """ | ||
# save_strings_as_json(data_str, "data.txt") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import logging | ||
|
||
# 1.创建一个logger实例,并且logger实例的名称命名为“single info”,设定的严重级别为DEBUG | ||
LOGGER = logging.getLogger("qbot") | ||
LOGGER.setLevel(logging.DEBUG) | ||
|
||
LOGGER_TXT = logging.getLogger("qbot") | ||
LOGGER_TXT.setLevel(logging.DEBUG) | ||
|
||
# 2.创建一个handler,这个主要用于控制台输出日志,并且设定严重级别 | ||
ch = logging.StreamHandler() | ||
ch.setLevel(logging.DEBUG) | ||
|
||
# 2、创建一个handler,用于写入日志文件 | ||
fh = logging.FileHandler("qbot_pro.log", encoding="utf-8", mode="a") | ||
fh.setLevel(logging.WARNING) | ||
|
||
# 3.创建handler的输出格式(formatter) | ||
formatter = logging.Formatter( | ||
"%(asctime)s - %(levelname)s - %(filename)s:%(lineno)d %(funcName)s: %(message)s" | ||
) | ||
|
||
# 4.将formatter添加到handler中 | ||
ch.setFormatter(formatter) | ||
fh.setFormatter(formatter) | ||
|
||
# 5.将handler添加到logger中 | ||
LOGGER.addHandler(ch) | ||
LOGGER_TXT.addHandler(fh) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logging | ||
|
||
|
||
class logger: | ||
def __init__(self, path, clevel=logging.INFO, Flevel=logging.INFO): | ||
self.logger = logging.getLogger(path) | ||
self.logger.setLevel(logging.DEBUG) | ||
fmt = logging.Formatter( | ||
"[%(asctime)s] [%(levelname)s] %(message)s", "%Y-%m-%d %H:%M:%S" | ||
) | ||
# 设置CMD日志 | ||
sh = logging.StreamHandler() | ||
sh.setFormatter(fmt) | ||
sh.setLevel(clevel) | ||
# 设置文件日志 | ||
fh = logging.FileHandler(path, encoding="utf-8") | ||
fh.setFormatter(fmt) | ||
fh.setLevel(Flevel) | ||
self.logger.addHandler(sh) | ||
self.logger.addHandler(fh) | ||
|
||
def debug(self, message): | ||
self.logger.debug(message) | ||
|
||
def info(self, message): | ||
self.logger.info(message) | ||
|
||
def war(self, message): | ||
self.logger.warn(message) | ||
|
||
def error(self, message): | ||
self.logger.error(message) | ||
|
||
def cri(self, message): | ||
self.logger.critical(message) | ||
|
||
|
||
log = logger("log.txt") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
strategy_choices = ( | ||
[ | ||
"单因子-相对强弱指数RSI", | ||
"单因子-随机相对强弱指数StochRSI(预留A)", | ||
"单因子-RSRS择时(预留B)", | ||
"单因子-移动均线+KDJ(预留C)", | ||
"单因子-MACD和ADX指标(预留D)", | ||
"单因子-布林线均值回归(预留E)", | ||
"单因子-阿隆指标(趋势交易)(预留F)", | ||
"单因子-简单移动均线(预留G)", | ||
"单因子-情绪指标ARBR(预留H)", | ||
"单因子-市场低估值策略(预留I)", | ||
"机器学习-麻雀优化算法SSA(预留J)", | ||
"机器学习-支持向量机SVM", | ||
"机器学习-LSTM时序预测(预留K)", | ||
"机器学习-LGBM模型价格预测", | ||
"机器学习-随机森林模型价格预测(预留L)", | ||
"机器学习-线性回归价格预测(预留M)", | ||
"强化学习-RL模型价格预测(预留N)", | ||
"强化学习-Q-Leaning预测(预留O)", | ||
"传统策略-海龟策略(预留P)", | ||
"传统策略-网格策略(预留Q)", | ||
"组合优化-配对交易(预留R)", | ||
"组合优化-Kurtosis Portfolio组合策略(预留S)", | ||
"多因子-ROC(20)动量信号周频Top1", | ||
"多因子-小市值(预留T)", | ||
"多因子-alphalens多因子交易(预留U)", | ||
], | ||
) | ||
|
||
trade_platforms = ( | ||
[ | ||
"同花顺", | ||
"东方财富", | ||
"华泰证券", | ||
"银河证券", | ||
"雪球", | ||
"海通证券" | ||
"国金证券", | ||
"通达信", | ||
"银河证券", | ||
"国泰君安", | ||
"中汇亿达", | ||
"恒生UFT", | ||
"掘金", | ||
"中泰XTP", | ||
"顶点飞创", | ||
"华鑫奇点", | ||
], | ||
) | ||
|
||
btc_trade_platforms = ( | ||
[ | ||
"欧易OKEX", | ||
"火币Huobi", | ||
"币安Binance", | ||
"Bitget", | ||
"coinex", | ||
"kucoin", | ||
"bingx", | ||
"coinbase", | ||
"Bybit", | ||
"bitmart", | ||
"bitmex", | ||
], | ||
) | ||
|
||
futures_trade_platforms = (["CTP", "易达", "艾克朗科", "CTPMini", "飞马Femas"],) |
Oops, something went wrong.