Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error generating statistics: cast a floating-point as decimal #7888

Open
4 tasks done
Martin-Molinero opened this issue Apr 1, 2024 · 0 comments · May be fixed by #8022
Open
4 tasks done

Error generating statistics: cast a floating-point as decimal #7888

Martin-Molinero opened this issue Apr 1, 2024 · 0 comments · May be fixed by #8022
Assignees
Labels

Comments

@Martin-Molinero
Copy link
Member

Expected Behavior

No ArgumentException exception generating stats

Actual Behavior

2024-04-01T20:52:04.1948498Z ERROR:: BaseResultsHandler.GenerateStatisticsResults(): BaseResultsHandler.GenerateStatisticsResults(): Error generating statistics packet System.ArgumentException: It is not possible to cast a non-finite floating-point value (Infinity) as decimal. Please review math operations and verify the result is valid. (Parameter 'input')
 ---> System.NotFiniteNumberException: Overflow or underflow in the arithmetic operation.
   --- End of inner exception stack trace ---
   at QuantConnect.Statistics.PortfolioStatistics..ctor(SortedDictionary`2 profitLoss, SortedDictionary`2 equity, SortedDictionary`2 portfolioTurnover, List`1 listPerformance, List`1 listBenchmark, Decimal startingCapital, IRiskFreeInterestRateModel riskFreeInterestRateModel, Int32 tradingDaysPerYear, Nullable`1 winCount, Nullable`1 lossCount) in Lean/Common/Statistics/PortfolioStatistics.cs:line 287
   at QuantConnect.Statistics.AlgorithmPerformance..ctor(List`1 trades, SortedDictionary`2 profitLoss, SortedDictionary`2 equity, SortedDictionary`2 portfolioTurnover, List`1 listPerformance, List`1 listBenchmark, Decimal startingCapital, Int32 winningTransactions, Int32 losingTransactions, IRiskFreeInterestRateModel riskFreeInterestRateModel, Int32 tradingDaysPerYear) in Lean/Common/Statistics/AlgorithmPerformance.cs:line 71
   at QuantConnect.Statistics.StatisticsBuilder.GetAlgorithmPerformance(DateTime fromDate, DateTime toDate, List`1 trades, SortedDictionary`2 profitLoss, SortedDictionary`2 equity, List`1 pointsPerformance, List`1 pointsBenchmark, List`1 pointsPortfolioTurnover, Decimal startingCapital, SecurityTransactionManager transactions, IRiskFreeInterestRateModel riskFreeInterestRateModel, Int32 tradingDaysPerYear) in Lean/Common/Statistics/StatisticsBuilder.cs:line 147
   at QuantConnect.Statistics.StatisticsBuilder.GetRollingPerformances(DateTime firstDate, DateTime lastDate, List`1 trades, SortedDictionary`2 profitLoss, SortedDictionary`2 equity, List`1 pointsPerformance, List`1 pointsBenchmark, List`1 pointsPortfolioTurnover, Decimal startingCapital, SecurityTransactionManager transactions, IRiskFreeInterestRateModel riskFreeInterestRateModel, Int32 tradingDaysPerYear) inLean/Common/Statistics/StatisticsBuilder.cs:line 192
   at QuantConnect.Statistics.StatisticsBuilder.Generate(List`1 trades, SortedDictionary`2 profitLoss, List`1 pointsEquity, List`1 pointsPerformance, List`1 pointsBenchmark, List`1 pointsPortfolioTurnover, Decimal startingCapital, Decimal totalFees, Int32 totalOrders, CapacityEstimate estimatedStrategyCapacity, String accountCurrencySymbol, SecurityTransactionManager transactions, IRiskFreeInterestRateModel riskFreeInterestRateModel, Int32 tradingDaysPerYear) in Lean/Common/Statistics/StatisticsBuilder.cs:line 74
   at QuantConnect.Lean.Engine.Results.BaseResultsHandler.GenerateStatisticsResults(Dictionary`2 charts, SortedDictionary`2 profitLoss, CapacityEstimate estimatedStrategyCapacity) in Lean/Engine/Results/BaseResultsHandler.cs:line 874

Potential Solution

  • Review code to find bug casting float to decimal, understand reason and handle correctly

Reproducing the Problem

Backtesting

# region imports
from AlgorithmImports import *
# endregion

class LogicalRedPig(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2024, 1, 1)
        self.SetCash(100000)
        self.AddEquity("SPY", Resolution.Minute)
        self.AddEquity("BND", Resolution.Minute)
        self.AddEquity("AAPL", Resolution.Minute)
        self.AddCrypto("BTCUSD", Resolution.Minute)

    def OnData(self, data: Slice):
        if not self.Portfolio.Invested:
            self.SetHoldings("BTCUSD", 0.1)
        else:
            self.SetHoldings("BTCUSD", 0)

System Information

N/A

Checklist

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants