hyperopt_org 使用静态币对列表

This commit is contained in:
Ubuntu 2025-09-11 08:22:19 +08:00
parent 707b860cdc
commit f17a02b03a
3 changed files with 173 additions and 1 deletions

Binary file not shown.

View File

@ -243,7 +243,7 @@ docker-compose run --rm freqtrade hyperopt $PAIRS_FLAG \
--enable-protections \
--strategy-path /freqtrade/templates \
--timerange ${START_DATE}-${END_DATE} \
-e 400 \
-e 500 \
-j 4 \
--hyperopt-loss SharpeHyperOptLossDaily \
--spaces buy sell \

172
tools/hyperopt_org.sh Executable file
View File

@ -0,0 +1,172 @@
#!/bin/bash
# 检查 .env 文件
if [ ! -f ".env" ]; then
echo "⚠️ 本地缺少 .env 文件,请创建并配置。示例内容如下:"
echo ""
echo "STRATEGY_NAME=TheForceV7"
echo "CONFIG_FILE=basic.json"
echo "TEST_BRANCH=theforce-noai-test"
echo "DRYRUN_BRANCH=theforce-noai-dryrun"
echo ""
exit 1
fi
# 加载 .env 文件中的变量
export $(grep -v '^#' .env | xargs)
# 设置默认值
STRATEGY_NAME=${STRATEGY_NAME:-TheForceV7}
CONFIG_FILE=${CONFIG_FILE:-basic.json}
echo "Using strategy: $STRATEGY_NAME"
echo "Using config: $CONFIG_FILE"
echo "Using testBranch: $TEST_BRANCH"
# Function to extract the value of a parameter
get_param_value() {
local param="$1"
shift
local args=("$@")
local i=0
while [ $i -lt ${#args[@]} ]; do
case "${args[$i]}" in
$param=*)
echo "${args[$i]#*=}"
return 0
;;
$param)
# Check if the next argument exists and does not start with a dash
if [ $((i + 1)) -lt ${#args[@]} ] && [[ "${args[$((i + 1))]}" != -* ]]; then
echo "${args[$((i + 1))]}"
return 0
else
echo "Error: Missing value for parameter $param" >&2
exit 1
fi
;;
esac
i=$((i + 1))
done
return 0
}
# Check if we have named parameters
HAS_NAMED_PARAMS=false
for arg in "$@"; do
if [[ "$arg" == --* ]]; then
HAS_NAMED_PARAMS=true
break
fi
done
# Initialize variables
START_DATE_RAW=""
END_DATE_RAW=""
PAIRS_ARG=""
PAIR_REMOTE_LIST_URL=""
# Parse parameters based on whether we have named parameters
if [ "$HAS_NAMED_PARAMS" = true ]; then
# Use named parameter parsing
START_DATE_RAW=$(get_param_value "--start-date" "$@")
END_DATE_RAW=$(get_param_value "--end-date" "$@")
PAIRS_ARG=$(get_param_value "--pairs" "$@")
PAIR_REMOTE_LIST_URL=$(get_param_value "--pairRemoteList" "$@")
else
# Use positional parameter parsing
if [ $# -gt 0 ]; then
START_DATE_RAW="$1"
fi
if [ $# -gt 1 ]; then
END_DATE_RAW="$2"
fi
if [ $# -gt 2 ]; then
THIRD_PARAM="$3"
# Check if it's a URL
if [[ "$THIRD_PARAM" == http://* ]] || [[ "$THIRD_PARAM" == https://* ]]; then
PAIR_REMOTE_LIST_URL="$THIRD_PARAM"
echo "Detected URL parameter: $PAIR_REMOTE_LIST_URL"
# Check if it's a pair like "*/USDT"
elif [[ "$THIRD_PARAM" == */USDT ]] || [[ "$THIRD_PARAM" == */BUSD ]] || [[ "$THIRD_PARAM" == */USDC ]]; then
PAIRS_ARG="$THIRD_PARAM"
echo "Detected pair parameter: $PAIRS_ARG"
else
echo "Warning: Third parameter '$THIRD_PARAM' is neither a URL nor a pair"
fi
fi
fi
# Set default values if parameters not provided
if [ -z "$START_DATE_RAW" ]; then
START_DATE_RAW=$(date -d "2 days ago" +"%Y-%m-%d %H:%M:%S")
fi
if [ -z "$END_DATE_RAW" ]; then
END_DATE_RAW=$(date -d "tomorrow" +"%Y-%m-%d %H:%M:%S")
fi
# Parse dates
if [[ "$START_DATE_RAW" == *" "* ]]; then
START_DATE=$(date -d "$START_DATE_RAW" +"%s")
else
# 兼容旧格式20250616 -> 转换为 2025-06-16 00:00:00 再转为时间戳
START_DATE=$(date -d "${START_DATE_RAW:0:4}-${START_DATE_RAW:4:2}-${START_DATE_RAW:6:2} 00:00:00" +"%s")
fi
if [[ "$END_DATE_RAW" == *" "* ]]; then
END_DATE=$(date -d "$END_DATE_RAW" +"%s")
else
END_DATE=$(date -d "${END_DATE_RAW:0:4}-${END_DATE_RAW:4:2}-${END_DATE_RAW:6:2} 00:00:00" +"%s")
fi
# Format end_date for URL parameter (YYYY-MM-DD format)
END_DATE_FORMATTED=$(date -d "@$END_DATE" "+%Y-%m-%d")
# 处理交易对参数:优先级为 --pairRemoteList > --pairs > 默认值
# 使用 --pairs 参数提供的交易对
PAIRS_FLAG="--pairs $PAIRS_ARG"
echo "Using pairs from --pairs parameter: $PAIRS_ARG"
echo "Number of pairs: $(echo "$PAIRS_ARG" | wc -w)"
# 使用默认的交易对列表
DEFAULT_PAIRS="BTC/USDT TON/USDT DOT/USDT XRP/USDT OKB/USDT SOL/USDT DOGE/USDT WCT/USDT TRUMP/USDT SUI/USDT PEPE/USDT TRB/USDT MASK/USDT UNI/USDT KAITO/USDT"
PAIRS_FLAG="--pairs $DEFAULT_PAIRS"
echo "Using default pairs: $DEFAULT_PAIRS"
cd ../
source .venv/bin/activate
rm -rf user_data/models/*
rm -rf ./freqtrade/user_data/data/backtest_results/*
rm -fr ./user_data/dryrun_results/*
rm result/*
PARAMS_NAME=freqaiprimer
hyperopt_config="${STRATEGY_NAME%.py}.json"
echo "docker-compose run --rm freqtrade hyperopt $PAIRS_FLAG \
--logfile /freqtrade/user_data/logs/freqtrade.log \
--freqaimodel LightGBMRegressorMultiTarget \
--strategy $STRATEGY_NAME \
--config /freqtrade/config_examples/$CONFIG_FILE \
--config /freqtrade/templates/${PARAMS_NAME}.json \
--enable-protections \
--strategy-path /freqtrade/templates \
--timerange ${START_DATE}-${END_DATE} \
-e 100 \
-j 4 \
--hyperopt-loss ShortTradeDurHyperOptLoss \
--spaces buy sell trailing \
--fee 0.0016"
docker-compose run --rm freqtrade hyperopt $PAIRS_FLAG \
--logfile /freqtrade/user_data/logs/freqtrade.log \
--freqaimodel LightGBMRegressorMultiTarget \
--strategy $STRATEGY_NAME \
--config /freqtrade/config_examples/$CONFIG_FILE \
--config /freqtrade/templates/${PARAMS_NAME}.json \
--enable-protections \
--strategy-path /freqtrade/templates \
--timerange ${START_DATE}-${END_DATE} \
-e 500 \
-j 4 \
--hyperopt-loss SharpeHyperOptLossDaily \
--spaces buy sell \
--fee 0.0016