public static CsvDownloadParameters Create(string ticker, FiscalQuarterPeriod from, FiscalQuarterPeriod to, CsvDownloadOutputSettings outputSettings)
        {
            JpTickerValidator.Validate(ticker);
            var range = PeriodRange <FiscalQuarterPeriod> .Create(from, to);

            return(new CsvDownloadParameters(ticker, range, outputSettings));
        }
        public void FindEndOfOndemandPeriodTest()
        {
            var tierResolver = CreatTierResolver();
            var helper       = new ApiTaskHelper(tierResolver);

            // for fixed tier range, return null
            // quarter
            var tierRange = PeriodRange <IComparablePeriod> .Create(fixedOldestQuarter, fixedLatestQuarter);

            Assert.IsNull(helper.FindEndOfOndemandPeriod(DataTypeConfig.Quarter, ticker, tierRange, true, true, true) as FiscalQuarterPeriod);
            Assert.IsNull(helper.FindEndOfOndemandPeriod(DataTypeConfig.Quarter, ticker, tierRange, false, true, true) as FiscalQuarterPeriod);
            // daily
            tierRange = PeriodRange <IComparablePeriod> .Create(fixedTierOldestDay, fixedTierLatestDay);

            Assert.IsNull(helper.FindEndOfOndemandPeriod(DataTypeConfig.Daily, ticker, tierRange, true, true, true) as DayPeriod);
            Assert.IsNull(helper.FindEndOfOndemandPeriod(DataTypeConfig.Daily, ticker, tierRange, false, true, true) as DayPeriod);

            // for ondemand range
            // quarter
            tierRange
                = PeriodRange <IComparablePeriod> .Create(ondemandOldestQuarter, ondemandLatestQuarter);

            Assert.AreEqual(ondemandLatestQuarter, helper.FindEndOfOndemandPeriod(DataTypeConfig.Quarter, ticker, tierRange, true, true, true) as FiscalQuarterPeriod);
            Assert.ThrowsException <NotSupportedTierException>(() => helper.FindEndOfOndemandPeriod(DataTypeConfig.Quarter, ticker, tierRange, false, true, true));

            tierRange
                = PeriodRange <IComparablePeriod> .Create(ondemandOldestDay, ondemandLatestDay);

            Assert.AreEqual(ondemandLatestDay, helper.FindEndOfOndemandPeriod(DataTypeConfig.Daily, ticker, tierRange, true, true, true) as DayPeriod);
            Assert.ThrowsException <NotSupportedTierException>(() => helper.FindEndOfOndemandPeriod(DataTypeConfig.Daily, ticker, tierRange, false, true, true));
        }
Example #3
0
        public void CreateForDayPeriodTest()
        {
            var from    = DayPeriod.Create(2020, 1, 1);
            var to      = DayPeriod.Create(2020, 1, 2);
            var fqRange = PeriodRange <DayPeriod> .Create(from, to);

            Assert.AreEqual(from, fqRange.From);
            Assert.AreEqual(to, fqRange.To);
            Assert.ThrowsException <ValidationError>(() => PeriodRange <DayPeriod> .Create(to, from));
        }
Example #4
0
        public void FixedTierRengeLengthTest()
        {
            var from  = FiscalQuarterPeriod.Create(2020, 1);
            var to    = FiscalQuarterPeriod.Create(2021, 2);
            var range = PeriodRange <FiscalQuarterPeriod> .Create(from, to);

            var supportedTierRange = new SupportedTierRange <FiscalQuarterPeriod>(range, null);

            Assert.AreEqual((uint)5, supportedTierRange.FixedTierRengeLength());
        }
Example #5
0
        public void IncludesTest()
        {
            var from  = FiscalQuarterPeriod.Create(2020, 1);
            var to    = FiscalQuarterPeriod.Create(2020, 3);
            var range = PeriodRange <FiscalQuarterPeriod> .Create(from, to);

            Assert.IsTrue(range.Includes(from));
            Assert.IsTrue(range.Includes(FiscalQuarterPeriod.Create(2020, 2)));
            Assert.IsTrue(range.Includes(to));
            Assert.IsFalse(range.Includes(FiscalQuarterPeriod.Create(2020, 4)));
            Assert.IsFalse(range.Includes(FiscalQuarterPeriod.Create(2019, 4)));
        }
Example #6
0
        public void TotalGapTest()
        {
            // quarter
            var fromFqp = FiscalQuarterPeriod.Create(2020, 1);
            var toFqp   = FiscalQuarterPeriod.Create(2021, 2);

            Assert.AreEqual((uint)5, PeriodRange <FiscalQuarterPeriod> .Create(fromFqp, toFqp).TotalGap());


            // day
            var fromDay = DayPeriod.Create(2016, 1, 1);
            var toDay   = DayPeriod.Create(2016, 2, 1);

            Assert.AreEqual((uint)31, PeriodRange <DayPeriod> .Create(fromDay, toDay).TotalGap());
        }
Example #7
0
        public void SliceDayTest()
        {
            var from     = DayPeriod.Create(2016, 1, 1);
            var to       = DayPeriod.Create(2016, 2, 1);
            var dayRange = PeriodRange <DayPeriod> .Create(from, to);

            // size = 1
            var chunks = PeriodRange <DayPeriod> .Slice(dayRange, 1).ToArray();

            Assert.AreEqual(32, chunks.Length);
            Assert.AreEqual(from, chunks[0].From);
            Assert.AreEqual(from, chunks[0].To);
            Assert.AreEqual(from.Next(), chunks[1].From);
            Assert.AreEqual(to, chunks[31].From);
            Assert.AreEqual(to, chunks[31].To);
            for (uint i = 0; i < chunks.Length; i++)
            {
                Assert.AreEqual(0, ComparablePeriodUtil.GetGap(chunks[i].From, chunks[i].To));
            }

            // size = 2
            chunks = PeriodRange <DayPeriod> .Slice(dayRange, 2).ToArray();

            Assert.AreEqual(16, chunks.Length);
            Assert.AreEqual(from, chunks[0].From);
            Assert.AreEqual(from.Next(), chunks[0].To);
            Assert.AreEqual(from.Next().Next(), chunks[1].From);
            Assert.AreEqual(to, chunks[15].To);
            for (uint i = 0; i < chunks.Length; i++)
            {
                Assert.AreEqual(1, ComparablePeriodUtil.GetGap(chunks[i].From, chunks[i].To));
            }


            // size = 3
            chunks = PeriodRange <DayPeriod> .Slice(dayRange, 3).ToArray();

            Assert.AreEqual(11, chunks.Length);
            Assert.AreEqual(from, chunks[0].From);
            Assert.AreEqual(from.Next().Next(), chunks[0].To);
            Assert.AreEqual(from.Next().Next().Next(), chunks[1].From);
            Assert.AreEqual(to, chunks[10].To);
            for (uint i = 0; i < chunks.Length - 1; i++)
            {
                Assert.AreEqual(2, ComparablePeriodUtil.GetGap(chunks[i].From, chunks[i].To));
            }
            Assert.AreEqual(1, ComparablePeriodUtil.GetGap(chunks.Last().From, chunks.Last().To));
        }
Example #8
0
        public void SliceFiscalQuarterTest()
        {
            var from         = FiscalQuarterPeriod.Create(2016, 1);
            var to           = FiscalQuarterPeriod.Create(2020, 4);
            var quarterRange = PeriodRange <FiscalQuarterPeriod> .Create(from, to);

            // size = 1
            var chunks = PeriodRange <FiscalQuarterPeriod> .Slice(quarterRange, 1).ToArray();

            Assert.AreEqual(20, chunks.Length);
            Assert.AreEqual(from, chunks[0].From);
            Assert.AreEqual(from, chunks[0].To);
            Assert.AreEqual(from.Next(), chunks[1].From);
            Assert.AreEqual(to, chunks[19].From);
            Assert.AreEqual(to, chunks[19].To);
            for (uint i = 0; i < chunks.Length; i++)
            {
                Assert.AreEqual(0, ComparablePeriodUtil.GetGap(chunks[i].From, chunks[i].To));
            }

            // size = 2
            chunks = PeriodRange <FiscalQuarterPeriod> .Slice(quarterRange, 2).ToArray();

            Assert.AreEqual(10, chunks.Length);
            Assert.AreEqual(from, chunks[0].From);
            Assert.AreEqual(from.Next(), chunks[0].To);
            Assert.AreEqual(from.Next().Next(), chunks[1].From);
            Assert.AreEqual(to, chunks[9].To);
            for (uint i = 0; i < chunks.Length; i++)
            {
                Assert.AreEqual(1, ComparablePeriodUtil.GetGap(chunks[i].From, chunks[i].To));
            }

            // size = 3
            chunks = PeriodRange <FiscalQuarterPeriod> .Slice(quarterRange, 3).ToArray();

            Assert.AreEqual(7, chunks.Length);
            Assert.AreEqual(from, chunks[0].From);
            Assert.AreEqual(from.Next().Next(), chunks[0].To);
            Assert.AreEqual(from.Next().Next().Next(), chunks[1].From);
            Assert.AreEqual(to, chunks[6].To);
            for (uint i = 0; i < chunks.Length - 1; i++)
            {
                Assert.AreEqual(2, ComparablePeriodUtil.GetGap(chunks[i].From, chunks[i].To));
            }
            Assert.AreEqual(1, ComparablePeriodUtil.GetGap(chunks.Last().From, chunks.Last().To));
        }
        private static Company ParseCompany(
            PropertyDictionary properties,
            PropertyDescriptionDictionary descriptions)
        {
            var fixedTierRangeJson = JObject.Parse(properties.Get(PropertyNames.FixedTierRange));
            var fixedTierRange     = FixedTierRangeParser.Parse(fixedTierRangeJson.Properties());

            var oldestFy = uint.Parse(properties.Get(PropertyNames.OldestFiscalYear));
            var oldestFq = uint.Parse(properties.Get(PropertyNames.OldestFiscalQuarter));

            var latestFy   = uint.Parse(properties.Get(PropertyNames.LatestFiscalYear));
            var latestFq   = uint.Parse(properties.Get(PropertyNames.LatestFiscalQuarter));
            var oldestDate = DayPeriod.Parse(properties.Get(PropertyNames.OldestDate));
            // use today as latest date
            var latestDate = DayPeriod.Create(DateTime.Today);

            var fixedTierQuarterRange = PeriodRange <FiscalQuarterPeriod> .Create(fixedTierRange.OldestQuarter, fixedTierRange.LatestQuarter);

            var fixedTierDayRange = PeriodRange <DayPeriod> .Create(fixedTierRange.OldestDate, fixedTierRange.LatestDate);

            var ondemandPeriodRange = PeriodRange <FiscalQuarterPeriod> .Create(
                FiscalQuarterPeriod.Create(oldestFy, oldestFq),
                FiscalQuarterPeriod.Create(latestFy, latestFq)
                );

            var ondemandTierDayRange = PeriodRange <DayPeriod> .Create(oldestDate, latestDate);

            return(Company.Create(
                       properties.Get(PropertyNames.Ticker),
                       fixedTierQuarterRange,
                       ondemandPeriodRange,
                       fixedTierDayRange,
                       ondemandTierDayRange,
                       properties,
                       descriptions
                       ));
        }
Example #10
0
 public static TickerPeriodRangeParameter Create(string ticker, IComparablePeriod from, IComparablePeriod to)
 {
     JpTickerValidator.Validate(ticker);
     return(new TickerPeriodRangeParameter(ticker, PeriodRange <IComparablePeriod> .Create(from, to)));
 }
Example #11
0
        public IList <IApiResource> GetApiResources(DataTypeConfig dataType, string ticker, IComparablePeriod from, IComparablePeriod to, bool isConfigureAwait = true, bool useCache = true)
        {
            UpdateApiKeyIfNeeded();
            if (from.CompareTo(to) > 0)
            {
                throw new ArgumentException($"from={from} is more than to={to}");
            }
            var endOfOndemandPeriod = taskHelper.FindEndOfOndemandPeriod(dataType, ticker, PeriodRange <IComparablePeriod> .Create(from, to), config.IsOndemandEndpointEnabled, isConfigureAwait, useCache);

            // use fixed tier from all range
            if (endOfOndemandPeriod is null)
            {
                var parameter = TickerPeriodRangeParameter.Create(ticker, from, to);
                var json      = client.GetRange(dataType, parameter, false, isConfigureAwait, useCache);
                return(parser.ParseRange(dataType, json));
            }
            else
            {
                var ondemandParameter = TickerPeriodRangeParameter.Create(ticker, from, endOfOndemandPeriod);
                var fixedParameter    = TickerPeriodRangeParameter.Create(ticker, endOfOndemandPeriod.Next(), to);

                var ondemandTierJson = client.GetRange(dataType, ondemandParameter, true, isConfigureAwait, useCache);
                var fixedTierJson    = client.GetRange(dataType, fixedParameter, false, isConfigureAwait, useCache);

                var ondemandResources = parser.ParseRange(dataType, ondemandTierJson);
                var fixedTierResource = parser.ParseRange(dataType, fixedTierJson);

                return(ondemandResources.Concat(fixedTierResource).ToList());
            }
        }