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

Unhandled Decimal Overflow Exception in PortfolioStatistics #8211

Closed
4 tasks done
AlexCatarino opened this issue Jul 18, 2024 · 1 comment · Fixed by #8256
Closed
4 tasks done

Unhandled Decimal Overflow Exception in PortfolioStatistics #8211

AlexCatarino opened this issue Jul 18, 2024 · 1 comment · Fixed by #8256
Assignees
Labels

Comments

@AlexCatarino
Copy link
Member

AlexCatarino commented Jul 18, 2024

Expected Behavior

PortfolioStatistics doesn't throw exceptions due to extreme returns.

Actual Behavior

If a daily return is too high, the annual performance equals decimal.MaxValue, which we cannot use to calculate the information ratio.

Potential Solution

  • reproduce issue
  • review failure location (& other potential similar failures)
  • explore reusing extension methods for double to decimal conversions, if applicable

Reproducing the Problem

    public class BasicTemplateAlgorithm : QCAlgorithm
    {
        public override void Initialize()
        {
            SetStartDate(2021, 01, 25);
            SetEndDate(2021, 01, 30);
            var symbol = AddEquity("GME").Symbol;

            @"
2021-01-25T15:00:00Z,GME,22.375,8044,Market,Filled,179984.5, 
2021-01-25T17:00:00Z,GME,24.995,-3043,Market,Filled,-76059.785, 
2021-01-25T18:00:00Z,GME,17.355,-2409,Market,Filled,-41808.195, 
2021-01-25T19:00:00Z,GME,18.915,-1535,Market,Filled,-29034.525, 
2021-01-25T20:00:00Z,GME,19.275,1277,Market,Filled,24614.175, 
2021-01-26T16:00:00Z,GME,21.9025,-1421,Market,Filled,-31123.4525, 
2021-01-26T17:00:00Z,GME,21.92125,1139,Market,Filled,24968.30375, 
2021-01-26T18:00:00Z,GME,26.3525,2691,Market,Filled,70914.5775, 
2021-01-26T20:00:00Z,GME,32.875,732,Market,Filled,24064.5, 
2021-01-27T18:00:00Z,GME,85.625,-4016,Market,Filled,-343870, 
2021-01-28T15:00:00Z,GME,117.125,77,Market,Filled,9018.625, 
2021-01-28T16:00:00Z,GME,66.0025,357,Market,Filled,23562.8925, 
2021-01-28T17:00:00Z,GME,63.7475,-1188,Market,Filled,-75732.03, 
2021-01-28T18:00:00Z,GME,60.0525,1376,Market,Filled,82632.24, 
2021-01-28T19:00:00Z,GME,60.7,-764,Market,Filled,-46374.8, 
2021-01-29T16:00:00Z,GME,83.655,583,Market,Filled,48770.865, 
2021-01-29T18:00:00Z,GME,82.0025,-519,Market,Filled,-42559.2975, 
2021-01-29T20:00:00Z,GME,70.75,-339,Market,Filled,-23984.25, 
2021-01-28T21:00:00Z,GME,95,-406,Market On Open,Filled,-38570, ".Split("\n")
                .Where(x => !string.IsNullOrWhiteSpace(x))
                .DoForEach(x =>
                {
                    var csv = x.Split(',');
                    var date = DateTime.Parse(csv[0]);
                    var quantity = Parse.Decimal(csv[3]);
                    Schedule.On(DateRules.On(date), TimeRules.At(date.TimeOfDay, TimeZones.Utc), () => MarketOrder(symbol, quantity));
                });
        }

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
@Martin-Molinero
Copy link
Member

BaseResultsHandler.GenerateStatisticsResults(): Error generating statistics packet System.OverflowException: Value was either too large or too small for a Decimal.
   at System.Number.ThrowOverflowException(TypeCode type)
   at System.Decimal.DecCalc.ScaleResult(Buf24* bufRes, UInt32 hiRes, Int32 scale)
   at System.Decimal.DecCalc.DecAddSub(DecCalc& d1, DecCalc& d2, Boolean sign)
   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 /Common/Statistics/PortfolioStatistics.cs:line 204

Stack trace,

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.

3 participants