Add new parameters
This commit is contained in:
@@ -58,9 +58,90 @@ public class Backtest
|
||||
[Required] public Dictionary<StrategyType, StrategiesResultBase> StrategiesValues { get; set; }
|
||||
[Required] public double Score { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new TradingBotConfig based on this backtest's configuration for starting a live bot.
|
||||
/// This method ensures all properties are properly copied, including nullable values.
|
||||
/// </summary>
|
||||
/// <param name="accountName">The account name to use for the new bot (can override backtest account)</param>
|
||||
/// <param name="botName">The name for the new bot</param>
|
||||
/// <param name="initialTradingBalance">The initial trading balance for the new bot</param>
|
||||
/// <param name="moneyManagement">Optional money management override (uses backtest's if not provided)</param>
|
||||
/// <returns>A new TradingBotConfig ready for bot creation</returns>
|
||||
public TradingBotConfig CreateLiveBotConfig(
|
||||
string accountName,
|
||||
string botName,
|
||||
decimal initialTradingBalance,
|
||||
MoneyManagement moneyManagement = null)
|
||||
{
|
||||
return new TradingBotConfig
|
||||
{
|
||||
AccountName = accountName,
|
||||
MoneyManagement = moneyManagement ?? Config.MoneyManagement,
|
||||
Ticker = Config.Ticker,
|
||||
ScenarioName = Config.ScenarioName,
|
||||
Timeframe = Config.Timeframe,
|
||||
IsForWatchingOnly = false, // Always start as active bot
|
||||
BotTradingBalance = initialTradingBalance,
|
||||
BotType = Config.BotType,
|
||||
IsForBacktest = false, // Always false for live bots
|
||||
CooldownPeriod = Config.CooldownPeriod,
|
||||
MaxLossStreak = Config.MaxLossStreak,
|
||||
MaxPositionTimeHours = Config.MaxPositionTimeHours, // Properly copy nullable value
|
||||
FlipOnlyWhenInProfit = Config.FlipOnlyWhenInProfit,
|
||||
FlipPosition = Config.FlipPosition,
|
||||
Name = botName
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a copy of the backtest's configuration for a new backtest.
|
||||
/// Useful for running similar backtests with modified parameters.
|
||||
/// </summary>
|
||||
/// <param name="startDate">New start date for the backtest</param>
|
||||
/// <param name="endDate">New end date for the backtest</param>
|
||||
/// <param name="balance">New initial balance for the backtest</param>
|
||||
/// <param name="moneyManagement">Optional money management override</param>
|
||||
/// <returns>A new TradingBotConfig for backtesting</returns>
|
||||
public TradingBotConfig CreateBacktestConfig(
|
||||
DateTime startDate,
|
||||
DateTime endDate,
|
||||
decimal balance,
|
||||
MoneyManagement moneyManagement = null)
|
||||
{
|
||||
return new TradingBotConfig
|
||||
{
|
||||
AccountName = Config.AccountName,
|
||||
MoneyManagement = moneyManagement ?? Config.MoneyManagement,
|
||||
Ticker = Config.Ticker,
|
||||
ScenarioName = Config.ScenarioName,
|
||||
Timeframe = Config.Timeframe,
|
||||
IsForWatchingOnly = Config.IsForWatchingOnly,
|
||||
BotTradingBalance = balance,
|
||||
BotType = Config.BotType,
|
||||
IsForBacktest = true,
|
||||
CooldownPeriod = Config.CooldownPeriod,
|
||||
MaxLossStreak = Config.MaxLossStreak,
|
||||
MaxPositionTimeHours = Config.MaxPositionTimeHours, // Properly copy nullable value
|
||||
FlipOnlyWhenInProfit = Config.FlipOnlyWhenInProfit,
|
||||
FlipPosition = Config.FlipPosition,
|
||||
Name = $"Backtest-{Config.ScenarioName}-{DateTime.UtcNow:yyyyMMdd-HHmmss}"
|
||||
};
|
||||
}
|
||||
|
||||
public string GetStringReport()
|
||||
{
|
||||
var timeBasedInfo = Config.MaxPositionTimeHours.HasValue
|
||||
? $" | MaxTime: {Config.MaxPositionTimeHours}h"
|
||||
: " | MaxTime: Disabled";
|
||||
|
||||
var flipInfo = Config.FlipPosition
|
||||
? $" | Flip: {(Config.FlipOnlyWhenInProfit ? "Profit-Only" : "Always")}"
|
||||
: "";
|
||||
|
||||
return
|
||||
$"{Config.Ticker} | {Config.Timeframe} | Positions: {Positions.Count} | Winrate: {WinRate}% | Pnl: {FinalPnl:#.##}$ | %Pnl: {GrowthPercentage:#.##}% | %Hodl: {HodlPercentage:#.##}%";
|
||||
$"{Config.Ticker} | {Config.Timeframe} | Positions: {Positions.Count} | Winrate: {WinRate}% | " +
|
||||
$"Pnl: {FinalPnl:#.##}$ | %Pnl: {GrowthPercentage:#.##}% | %Hodl: {HodlPercentage:#.##}%" +
|
||||
$" | Cooldown: {Config.CooldownPeriod} | MaxLoss: {Config.MaxLossStreak}" +
|
||||
timeBasedInfo + flipInfo;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user