Fix ROI calculation for Strategy
This commit is contained in:
@@ -182,8 +182,8 @@ public class AgentGrain : Grain, IAgentGrain
|
||||
_state.State.TotalFees = totalFees;
|
||||
|
||||
// Calculate wins/losses from position PnL
|
||||
var totalWins = positions.Count(p => (p.ProfitAndLoss?.Realized ?? 0) > 0);
|
||||
var totalLosses = positions.Count(p => (p.ProfitAndLoss?.Realized ?? 0) <= 0);
|
||||
var totalWins = positions.Count(p => (p.ProfitAndLoss?.Net ?? 0) > 0);
|
||||
var totalLosses = positions.Count(p => (p.ProfitAndLoss?.Net ?? 0) <= 0);
|
||||
|
||||
// Calculate ROI based on PnL minus fees
|
||||
var netPnL = totalPnL - totalFees;
|
||||
|
||||
@@ -791,12 +791,18 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
}
|
||||
}
|
||||
|
||||
var positionForMetrics = _tradingBot.Positions.Where(p => p.Value.IsValidForMetrics())
|
||||
.Select(p => p.Value).ToList();
|
||||
var positionForMetrics = await ServiceScopeHelpers.WithScopedService<ITradingService, List<Position>>(
|
||||
_scopeFactory,
|
||||
async tradingService =>
|
||||
{
|
||||
return (await tradingService.GetPositionsByInitiatorIdentifierAsync(this.GetPrimaryKey()))
|
||||
.Where(p => p.IsValidForMetrics()).ToList();
|
||||
});
|
||||
|
||||
// Calculate statistics using TradingBox helpers
|
||||
var (tradeWins, tradeLosses) = TradingBox.GetWinLossCount(positionForMetrics);
|
||||
var pnl = _tradingBot.GetProfitAndLoss();
|
||||
var fees = _tradingBot.GetTotalFees();
|
||||
var pnl = positionForMetrics.Sum(p => p.ProfitAndLoss.Realized);
|
||||
var fees = positionForMetrics.Sum(p => p.CalculateTotalFees());
|
||||
var netPnl = pnl - fees; // Net PnL after fees
|
||||
var volume = TradingBox.GetTotalVolumeTraded(positionForMetrics);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user