Add penality for bad risk reward
This commit is contained in:
@@ -688,7 +688,8 @@ namespace Managing.Application.Tests
|
|||||||
tradingBalance: config.BotTradingBalance,
|
tradingBalance: config.BotTradingBalance,
|
||||||
startDate: backtestResult.StartDate,
|
startDate: backtestResult.StartDate,
|
||||||
endDate: backtestResult.EndDate,
|
endDate: backtestResult.EndDate,
|
||||||
timeframe: config.Timeframe
|
timeframe: config.Timeframe,
|
||||||
|
moneyManagement: config.MoneyManagement
|
||||||
);
|
);
|
||||||
|
|
||||||
var scenarioResult = new ScenarioBacktestResult
|
var scenarioResult = new ScenarioBacktestResult
|
||||||
|
|||||||
@@ -325,7 +325,8 @@ namespace Managing.Application.Backtesting
|
|||||||
tradingBalance: config.BotTradingBalance,
|
tradingBalance: config.BotTradingBalance,
|
||||||
startDate: candles[0].Date,
|
startDate: candles[0].Date,
|
||||||
endDate: candles.Last().Date,
|
endDate: candles.Last().Date,
|
||||||
timeframe: config.Timeframe
|
timeframe: config.Timeframe,
|
||||||
|
moneyManagement: config.MoneyManagement
|
||||||
);
|
);
|
||||||
|
|
||||||
var scoringResult = BacktestScorer.CalculateDetailedScore(scoringParams);
|
var scoringResult = BacktestScorer.CalculateDetailedScore(scoringParams);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Managing.Domain.MoneyManagements;
|
||||||
using static Managing.Common.Enums;
|
using static Managing.Common.Enums;
|
||||||
|
|
||||||
namespace Managing.Domain.Backtests;
|
namespace Managing.Domain.Backtests;
|
||||||
@@ -20,6 +21,7 @@ public class BacktestScoringParams
|
|||||||
public DateTime StartDate { get; }
|
public DateTime StartDate { get; }
|
||||||
public DateTime EndDate { get; }
|
public DateTime EndDate { get; }
|
||||||
public Timeframe Timeframe { get; }
|
public Timeframe Timeframe { get; }
|
||||||
|
public MoneyManagement MoneyManagement { get; }
|
||||||
|
|
||||||
public BacktestScoringParams(
|
public BacktestScoringParams(
|
||||||
double sharpeRatio,
|
double sharpeRatio,
|
||||||
@@ -35,7 +37,8 @@ public class BacktestScoringParams
|
|||||||
decimal tradingBalance = 0,
|
decimal tradingBalance = 0,
|
||||||
DateTime startDate = default,
|
DateTime startDate = default,
|
||||||
DateTime endDate = default,
|
DateTime endDate = default,
|
||||||
Timeframe timeframe = Timeframe.OneHour)
|
Timeframe timeframe = Timeframe.OneHour,
|
||||||
|
MoneyManagement moneyManagement = null)
|
||||||
{
|
{
|
||||||
SharpeRatio = sharpeRatio;
|
SharpeRatio = sharpeRatio;
|
||||||
GrowthPercentage = growthPercentage;
|
GrowthPercentage = growthPercentage;
|
||||||
@@ -51,5 +54,6 @@ public class BacktestScoringParams
|
|||||||
StartDate = startDate;
|
StartDate = startDate;
|
||||||
EndDate = endDate;
|
EndDate = endDate;
|
||||||
Timeframe = timeframe;
|
Timeframe = timeframe;
|
||||||
|
MoneyManagement = moneyManagement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,6 +189,19 @@ public class BacktestScorer
|
|||||||
result.AddPenaltyCheck("HODL Underperformance", newMultiplier, $"Underperforming HODL by {hodlUnderperformance:F2}% applied {hodlPenalty:F1}% penalty");
|
result.AddPenaltyCheck("HODL Underperformance", newMultiplier, $"Underperforming HODL by {hodlUnderperformance:F2}% applied {hodlPenalty:F1}% penalty");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 9. Money Management Risk/Reward Penalty (Dynamic)
|
||||||
|
if (p.MoneyManagement != null && p.MoneyManagement.StopLoss > 0 && p.MoneyManagement.TakeProfit > 0)
|
||||||
|
{
|
||||||
|
var riskRewardRatio = (double)(p.MoneyManagement.TakeProfit / p.MoneyManagement.StopLoss);
|
||||||
|
if (riskRewardRatio <= 1.0) // If Risk/Reward ratio is not above 1:1
|
||||||
|
{
|
||||||
|
var riskRewardPenalty = (1.0 - riskRewardRatio) * 0.5; // 50% penalty per 0.1 ratio below 1.0
|
||||||
|
var newMultiplier = Math.Max(0.2, 1 - riskRewardPenalty);
|
||||||
|
penaltyMultiplier *= newMultiplier;
|
||||||
|
result.AddPenaltyCheck("Poor Risk/Reward Ratio", newMultiplier, $"Risk/Reward ratio of {riskRewardRatio:F2}:1 below 1:1 threshold applied {riskRewardPenalty:F1}% penalty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return baseScore * penaltyMultiplier;
|
return baseScore * penaltyMultiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user