Rename strategy to indicators
This commit is contained in:
@@ -30,7 +30,7 @@ namespace Managing.Application.Backtesting
|
||||
IExchangeService exchangeService,
|
||||
IBotFactory botFactory,
|
||||
IBacktestRepository backtestRepository,
|
||||
ILogger<Backtester> logger,
|
||||
ILogger<Backtester> logger,
|
||||
IScenarioService scenarioService,
|
||||
IAccountService accountService)
|
||||
{
|
||||
@@ -74,9 +74,9 @@ namespace Managing.Application.Backtesting
|
||||
{
|
||||
var account = await GetAccountFromConfig(config);
|
||||
var candles = GetCandles(account, config.Ticker, config.Timeframe, startDate, endDate);
|
||||
|
||||
|
||||
var result = await RunBacktestWithCandles(config, candles, user);
|
||||
|
||||
|
||||
// Set start and end dates
|
||||
result.StartDate = startDate;
|
||||
result.EndDate = endDate;
|
||||
@@ -115,9 +115,9 @@ namespace Managing.Application.Backtesting
|
||||
{
|
||||
// Set FlipPosition based on BotType
|
||||
config.FlipPosition = config.BotType == BotType.FlippingBot;
|
||||
|
||||
|
||||
var tradingBot = _botFactory.CreateBacktestTradingBot(config);
|
||||
|
||||
|
||||
// Load scenario - prefer Scenario object over ScenarioName
|
||||
if (config.Scenario != null)
|
||||
{
|
||||
@@ -129,9 +129,10 @@ namespace Managing.Application.Backtesting
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Either Scenario object or ScenarioName must be provided in TradingBotConfig");
|
||||
throw new ArgumentException(
|
||||
"Either Scenario object or ScenarioName must be provided in TradingBotConfig");
|
||||
}
|
||||
|
||||
|
||||
tradingBot.User = user;
|
||||
await tradingBot.LoadAccount();
|
||||
|
||||
@@ -153,9 +154,9 @@ namespace Managing.Application.Backtesting
|
||||
return account;
|
||||
}
|
||||
|
||||
return new Account
|
||||
{
|
||||
Name = config.AccountName,
|
||||
return new Account
|
||||
{
|
||||
Name = config.AccountName,
|
||||
Exchange = TradingExchanges.GmxV2
|
||||
};
|
||||
}
|
||||
@@ -191,7 +192,7 @@ namespace Managing.Application.Backtesting
|
||||
}
|
||||
|
||||
bot.Candles = new HashSet<Candle>(candles);
|
||||
bot.UpdateStrategiesValues();
|
||||
bot.UpdateIndicatorsValues();
|
||||
|
||||
var strategies = _scenarioService.GetStrategies();
|
||||
var strategiesValues = GetStrategiesValues(strategies, candles);
|
||||
@@ -228,21 +229,21 @@ namespace Managing.Application.Backtesting
|
||||
WalletBalances = bot.WalletBalances.ToList(),
|
||||
Statistics = stats,
|
||||
OptimizedMoneyManagement = optimizedMoneyManagement,
|
||||
StrategiesValues = AggregateValues(strategiesValues, bot.StrategiesValues),
|
||||
StrategiesValues = AggregateValues(strategiesValues, bot.IndicatorsValues),
|
||||
Score = score
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Dictionary<StrategyType, StrategiesResultBase> AggregateValues(
|
||||
Dictionary<StrategyType, StrategiesResultBase> strategiesValues,
|
||||
Dictionary<StrategyType, StrategiesResultBase> botStrategiesValues)
|
||||
private Dictionary<IndicatorType, IndicatorsResultBase> AggregateValues(
|
||||
Dictionary<IndicatorType, IndicatorsResultBase> strategiesValues,
|
||||
Dictionary<IndicatorType, IndicatorsResultBase> botStrategiesValues)
|
||||
{
|
||||
// Foreach strategy type, only retrieve the values where the strategy is not present already in the bot
|
||||
// Then, add the values to the bot values
|
||||
|
||||
var result = new Dictionary<StrategyType, StrategiesResultBase>();
|
||||
var result = new Dictionary<IndicatorType, IndicatorsResultBase>();
|
||||
foreach (var strategy in strategiesValues)
|
||||
{
|
||||
// if (!botStrategiesValues.ContainsKey(strategy.Key))
|
||||
@@ -259,10 +260,10 @@ namespace Managing.Application.Backtesting
|
||||
return result;
|
||||
}
|
||||
|
||||
private Dictionary<StrategyType, StrategiesResultBase> GetStrategiesValues(IEnumerable<Strategy> strategies,
|
||||
private Dictionary<IndicatorType, IndicatorsResultBase> GetStrategiesValues(IEnumerable<Indicator> strategies,
|
||||
List<Candle> candles)
|
||||
{
|
||||
var strategiesValues = new Dictionary<StrategyType, StrategiesResultBase>();
|
||||
var strategiesValues = new Dictionary<IndicatorType, IndicatorsResultBase>();
|
||||
var fixedCandles = new FixedSizeQueue<Candle>(10000);
|
||||
foreach (var candle in candles)
|
||||
{
|
||||
@@ -273,7 +274,7 @@ namespace Managing.Application.Backtesting
|
||||
{
|
||||
try
|
||||
{
|
||||
var s = ScenarioHelpers.BuildStrategy(strategy, 10000);
|
||||
var s = ScenarioHelpers.BuildIndicator(strategy, 10000);
|
||||
s.Candles = fixedCandles;
|
||||
strategiesValues[strategy.Type] = s.GetStrategyValues();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user