dededdew
This commit is contained in:
@@ -165,7 +165,7 @@ def simulate_trade(direction, entry_price, entry_time, next_15min_time, tp=8, sl
|
||||
for candle in future_candles:
|
||||
open_p, high, low = map(float, (candle['open'], candle['high'], candle['low']))
|
||||
|
||||
if direction == "long": # long
|
||||
if direction == "long": # long
|
||||
if open_p >= tp_price: # 开盘跳空止盈 涨信号,
|
||||
return open_p, open_p - entry_price, candle['id']
|
||||
if open_p <= sl_price: # 开盘跳空止损
|
||||
@@ -266,34 +266,37 @@ def backtest(dates, tp, sl):
|
||||
# ===============================================================
|
||||
|
||||
if __name__ == '__main__':
|
||||
dates = [f"2025-9-{i}" for i in range(1, 31)]
|
||||
dates = [f"2025-6-{i}" for i in range(1, 31)]
|
||||
|
||||
trades, stats = backtest(dates, tp=10, sl=-2)
|
||||
for i in range(1, 11):
|
||||
for i1 in range(1, 51):
|
||||
|
||||
logger.info("===== 每笔交易详情 =====")
|
||||
for t in trades:
|
||||
logger.info(
|
||||
f"{t['entry_time']} {t['direction']}({t['signal']}) "
|
||||
f"入场={t['entry']:.2f} 出场={t['exit']:.2f} 出场时间={t['exit_time']} "
|
||||
f"差价={t['diff']:.2f}"
|
||||
)
|
||||
trades, stats = backtest(dates, tp=i1, sl=-i)
|
||||
|
||||
total_profit = sum(t['diff'] / t['entry'] * 10000 for t in trades)
|
||||
total_fee = sum(5 + 10000 / t['entry'] * t['exit'] * 0.0005 for t in trades)
|
||||
# logger.info("===== 每笔交易详情 =====")
|
||||
# for t in trades:
|
||||
# logger.info(
|
||||
# f"{t['entry_time']} {t['direction']}({t['signal']}) "
|
||||
# f"入场={t['entry']:.2f} 出场={t['exit']:.2f} 出场时间={t['exit_time']} "
|
||||
# f"差价={t['diff']:.2f}"
|
||||
# )
|
||||
|
||||
print(f"\n一共交易笔数:{len(trades)}")
|
||||
print(f"一共盈利:{total_profit:.2f}")
|
||||
print(f"一共手续费:{total_fee:.2f}")
|
||||
print(f"净利润:{total_profit - total_fee:.2f}")
|
||||
total_profit = sum(t['diff'] / t['entry'] * 10000 for t in trades)
|
||||
total_fee = sum(5 + 10000 / t['entry'] * t['exit'] * 0.0005 for t in trades)
|
||||
|
||||
# if total_profit > total_fee * 0.1:
|
||||
# print(i1, i)
|
||||
# print(f"\n一共交易笔数:{len(trades)}")
|
||||
# print(f"一共盈利:{total_profit:.2f}")
|
||||
# print(f"一共手续费:{total_fee:.2f}")
|
||||
# print(f"净利润:{total_profit - total_fee * 0.1}")
|
||||
#
|
||||
# print("\n===== 信号统计 =====")
|
||||
# print(f"\n一共交易笔数:{len(trades)}")
|
||||
# print(f"一共盈利:{total_profit:.2f}")
|
||||
# print(f"一共手续费:{total_fee:.2f}")
|
||||
# print(f"净利润:{total_profit - total_fee:.2f}")
|
||||
|
||||
if total_profit > total_fee * 0.1:
|
||||
print(f"止盈:{i1}, 止损:{i}")
|
||||
print(f"\n一共交易笔数:{len(trades)}")
|
||||
print(f"一共盈利:{total_profit:.2f}")
|
||||
print(f"一共手续费:{total_fee:.2f}")
|
||||
print(f"净利润:{total_profit - total_fee * 0.1}")
|
||||
|
||||
print("\n===== 信号统计 =====")
|
||||
#
|
||||
# for k, v in stats.items():
|
||||
# win_rate = (v['wins'] / v['count'] * 100) if v['count'] > 0 else 0
|
||||
|
||||
Reference in New Issue
Block a user