This commit is contained in:
薇薇安 2026-02-05 19:55:50 +08:00
parent a38f5ff05d
commit 79fb20bf41
4 changed files with 1382 additions and 2 deletions

70
analyze_json.py Normal file
View File

@ -0,0 +1,70 @@
import json
from datetime import datetime
import sys
file_path = '/Users/vivian/work/python/auto_trade_sys/交易记录_2026-02-05T11-39-32.json'
def parse_time(time_str):
if not time_str:
return None
try:
# Adjust format based on actual JSON content if needed
# Assuming ISO format or similar based on filename
return datetime.fromisoformat(time_str.replace('Z', '+00:00'))
except ValueError:
return None
try:
with open(file_path, 'r', encoding='utf-8') as f:
data = json.load(f)
closed_trades = [t for t in data if t.get('状态') == '已平仓']
total_trades = len(data)
closed_count = len(closed_trades)
print(f"Total Trades in File: {total_trades}")
print(f"Closed Trades: {closed_count}")
if closed_count == 0:
print("No closed trades to analyze.")
sys.exit(0)
wins = [t for t in closed_trades if float(t.get('盈亏', 0)) > 0]
losses = [t for t in closed_trades if float(t.get('盈亏', 0)) <= 0]
total_pnl = sum(float(t.get('盈亏', 0)) for t in closed_trades)
total_win_pnl = sum(float(t.get('盈亏', 0)) for t in wins)
total_loss_pnl = sum(float(t.get('盈亏', 0)) for t in losses)
avg_win = total_win_pnl / len(wins) if wins else 0
avg_loss = total_loss_pnl / len(losses) if losses else 0
print(f"\n--- Performance Analysis ---")
print(f"Win Count: {len(wins)}")
print(f"Loss Count: {len(losses)}")
win_rate = (len(wins) / closed_count * 100) if closed_count > 0 else 0
print(f"Win Rate: {win_rate:.2f}%")
print(f"Total PnL: {total_pnl:.4f} USDT")
print(f"Avg Win: {avg_win:.4f} USDT")
print(f"Avg Loss: {avg_loss:.4f} USDT")
if avg_loss != 0:
rr_ratio = abs(avg_win / avg_loss)
print(f"Avg Win / Avg Loss Ratio (R:R): {rr_ratio:.2f}")
else:
print("Avg Win / Avg Loss Ratio (R:R): Infinite (No Losses)")
# Duration Analysis (if fields exist)
# Assuming fields like '开仓时间' and '平仓时间' exist based on typical trade records
# If not, this part will be skipped or adjusted
# Let's inspect one record keys to be sure for future reference
if closed_trades:
print(f"\nSample Record Keys: {list(closed_trades[0].keys())}")
except Exception as e:
print(f"Error: {e}")
import traceback
traceback.print_exc()

View File

@ -205,11 +205,11 @@ def _get_trading_config():
'EXCLUDE_MAJOR_COINS': True, # 排除主流币BTC、ETH、BNB等专注于山寨币
'STOP_LOSS_PERCENT': 0.12, # 止损12%(保证金百分比)
'TAKE_PROFIT_PERCENT': 0.10, # 第二目标/单目标止盈10%
'TAKE_PROFIT_1_PERCENT': 0.15, # 分步止盈第一目标15%,提高整体盈亏比
'TAKE_PROFIT_1_PERCENT': 0.25, # 分步止盈第一目标25%2026-02-05优化提高盈亏比
'MIN_STOP_LOSS_PRICE_PCT': 0.025, # 最小止损价格变动2.5%2026-01-29优化从2%提高到2.5%,给波动更多空间)
'MIN_TAKE_PROFIT_PRICE_PCT': 0.02, # 最小止盈价格变动2%
'USE_ATR_STOP_LOSS': True, # 使用ATR动态止损
'ATR_STOP_LOSS_MULTIPLIER': 2.0, # ATR止损倍数2.02026-01-29优化从1.5提高到2.0,减少被正常波动扫出
'ATR_STOP_LOSS_MULTIPLIER': 1.5, # ATR止损倍数1.52026-02-05优化收紧止损改善盈亏比
'ATR_TAKE_PROFIT_MULTIPLIER': 2.0, # ATR止盈倍数2.02026-01-27优化降低止盈目标更容易触发
'RISK_REWARD_RATIO': 3.0, # 盈亏比3:12026-01-27优化降低更容易触发保证胜率
'ATR_PERIOD': 14, # ATR计算周期14

30
update_strategy_config.py Normal file
View File

@ -0,0 +1,30 @@
import sys
import os
from pathlib import Path
# Add project root to sys.path
project_root = Path(__file__).resolve().parent
sys.path.insert(0, str(project_root))
sys.path.insert(0, str(project_root / 'backend'))
try:
from backend.database.models import GlobalStrategyConfig
updates = [
('ATR_STOP_LOSS_MULTIPLIER', 1.5, 'float', 'risk', 'ATR止损倍数优化后1.5'),
('TAKE_PROFIT_1_PERCENT', 0.25, 'float', 'strategy', '第一目标止盈25%(优化后)'),
('ATR_TAKE_PROFIT_MULTIPLIER', 2.0, 'float', 'risk', 'ATR止盈倍数'),
# Also ensure USE_ATR_STOP_LOSS is True
('USE_ATR_STOP_LOSS', True, 'bool', 'risk', '开启ATR止损'),
]
print("Updating Global Strategy Config...")
for key, value, type_, category, desc in updates:
print(f"Setting {key} = {value}")
GlobalStrategyConfig.set(key, value, type_, category, description=desc, updated_by='system_optimizer')
print("Done.")
except Exception as e:
print(f"Error: {e}")
import traceback
traceback.print_exc()

File diff suppressed because it is too large Load Diff