dededdew
This commit is contained in:
@@ -228,7 +228,7 @@ def backtest(dates, tp, sl):
|
||||
continue
|
||||
|
||||
# 下一个 15 分钟K线的时间范围
|
||||
next_15min_time = all_data[idx + 5]['id'] if idx + 5 < len(all_data) else all_data[-1]['id']
|
||||
next_15min_time = all_data[idx + 50]['id'] if idx + 50 < len(all_data) else all_data[-1]['id']
|
||||
|
||||
entry_price = float(entry_candle['open']) # 开仓价格
|
||||
exit_price, diff, exit_time = simulate_trade(
|
||||
@@ -268,26 +268,28 @@ def backtest(dates, tp, sl):
|
||||
if __name__ == '__main__':
|
||||
dates = [f"2025-9-{i}" for i in range(1, 31)]
|
||||
|
||||
# for i in range(1, 11):
|
||||
# for i1 in range(1, 51):
|
||||
# for i in range(5, 11):
|
||||
# for i1 in range(25, 51):
|
||||
|
||||
trades, stats = backtest(dates, tp=15, sl=-50)
|
||||
trades, stats = backtest(dates, tp=50, sl=-10)
|
||||
|
||||
# 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}"
|
||||
# )
|
||||
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}"
|
||||
)
|
||||
|
||||
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)
|
||||
# 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:.2f}")
|
||||
print("\n===== 信号统计 =====")
|
||||
|
||||
# if total_profit > total_fee * 0.1:
|
||||
# print(f"止盈:{i1}, 止损:{i}")
|
||||
|
||||
Reference in New Issue
Block a user