Start and End Dates of the Longest Rising Period
Problem Description The stock table records the daily closing prices of many stocks, with the fields CODE (stock code), DT (trading date) and CL (closing price). For a given target stock, find the period during which it rose for the largest number of consecutive days, and give the start date and end date of that period. Source Data stock table (only the records of the target stock CODE = 100046…
The task at hand is to identify the period when the specified stock (CODE 100046) consistently rose for the most consecutive trading days. To accomplish this, the data must be filtered to include only the records for this stock, sorted chronologically by trading date, and then segmented into intervals where the closing price does not fall.
The interval starts anew whenever the closing price declines from the previous day's level. As each interval is identified, the algorithm assigns it a unique group number, which remains constant for all days within that uninterrupted ascent. At the conclusion of each interval, the count of days included in that particular rising sequence is recorded.
The longest sequence is then pinpointed by comparing these day counts, and the start and end dates corresponding to this longest uninterrupted rise are extracted.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.