question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ArgumentOutOfRangeException for Aggregation with PeriodSize.Month

See original GitHub issue

the problem

Calling public static IEnumerable<Quote> Aggregate<TQuote>(this IEnumerable<TQuote> quotes, PeriodSize newSize) with PeriodSize.Month returns a ArgumentOutOfRangeException. Aggregation by other periods in lower time frame (Daily, Weekly) works as expected.

to reproduce

  1. Create a IEnumerable<Quote> quotes collection with hourly or daily data
  2. Call quotes.Aggregate(PeriodSize.Month)

Error message(s):

System.ArgumentOutOfRangeException
  HResult=0x80131502
  Message=Historical quotes Aggregation must use a new size value that is greater than zero (0). Arg_ParamName_Name
ArgumentOutOfRange_ActualValue
  Source=Skender.Stock.Indicators
  StackTrace:
   at Skender.Stock.Indicators.HistoricalQuotes.Aggregate[TQuote](IEnumerable`1 quotes, TimeSpan timeSpan)
   at Skender.Stock.Indicators.HistoricalQuotes.Aggregate[TQuote](IEnumerable`1 quotes, PeriodSize newSize)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SvenSkrabalcommented, Mar 4, 2022

The PeriodSize enum value is converted to a TimeSpan object with an extension method:

public static IEnumerable<Quote> Aggregate<TQuote>(
        this IEnumerable<TQuote> quotes,
        PeriodSize newSize)
        where TQuote : IQuote
    {
        // parameter conversion
        TimeSpan newTimeSpan = newSize.ToTimeSpan();

        // convert
        return quotes.Aggregate(newTimeSpan);
    }

This extension method is lacking a case for PeriodSize.Month:

// PERIOD-SIZE to TIMESPAN CONVERSION
    internal static TimeSpan ToTimeSpan(this PeriodSize periodSize)
    {
        return periodSize switch
        {
            PeriodSize.OneMinute => TimeSpan.FromMinutes(1),
            PeriodSize.TwoMinutes => TimeSpan.FromMinutes(2),
            PeriodSize.ThreeMinutes => TimeSpan.FromMinutes(3),
            PeriodSize.FiveMinutes => TimeSpan.FromMinutes(5),
            PeriodSize.FifteenMinutes => TimeSpan.FromMinutes(15),
            PeriodSize.ThirtyMinutes => TimeSpan.FromMinutes(30),
            PeriodSize.OneHour => TimeSpan.FromHours(1),
            PeriodSize.TwoHours => TimeSpan.FromHours(2),
            PeriodSize.FourHours => TimeSpan.FromHours(4),
            PeriodSize.Day => TimeSpan.FromDays(1),
            PeriodSize.Week => TimeSpan.FromDays(7),
            _ => TimeSpan.Zero
        };
    }
0reactions
DaveSkendercommented, Mar 6, 2022

This was implemented in version 1.22.0 and is now available.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Year, Month, and Day parameters describe an un- ...
ArgumentOutOfRangeException : Year, Month, and Day parameters describe an un-representable DateTime. DateTime fromDate = new DateTime(DateTime.
Read more >
ArgumentOutOfRangeException Class (System)
The exception that is thrown when the value of an argument is outside the allowable range of values as defined by the invoked...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found