public void CreateFromStringTest()
        {
            var fyFqStr = "2018Q1";
            var period  = FiscalQuarterPeriod.Parse(fyFqStr);

            Assert.AreEqual((uint)2018, period.Year);
            Assert.AreEqual((uint)1, period.Quarter);
            Assert.AreEqual(fyFqStr, period.ToString());
        }
        private CsvDownloadParameters CreateParametersFromFormValues()
        {
            var ticker      = textTicker.Text;
            var from        = FiscalQuarterPeriod.Parse(textFrom.Text);
            var to          = FiscalQuarterPeriod.Parse(textTo.Text);
            var encoding    = radioUTF8.Checked ? TabularOutputEncoding.UTF8 : TabularOutputEncoding.SJIS;
            var destination = radioCSV.Checked ? TabularOutputDestination.NewCsvFile
                : TabularOutputDestination.NewWorksheet;

            return(CsvDownloadParameters.Create(ticker, from, to, CsvDownloadOutputSettings.Create(encoding, destination)));
        }
        public static CsvDownloadParameters Load()
        {
            var ticker = Properties.Settings.Default.CSVTicker;

            JpTickerValidator.Validate(ticker);
            var from           = FiscalQuarterPeriod.Parse(Properties.Settings.Default.CSVFrom);
            var to             = FiscalQuarterPeriod.Parse(Properties.Settings.Default.CSVTo);
            var outputSettings = LoadOutputSettings();

            return(CsvDownloadParameters.Create(ticker, from, to, outputSettings));
        }
Example #4
0
 public static ITickerPeriodParameter Create(string ticker, string periodParam, FiscalQuarterPeriod latestFiscalQuarterPeriod)
 {
     if (periodParam.Equals("latest"))
     {
         return(TickerDayParameter.Create(ticker, LatestDayPeriod.GetInstance()));
     }
     else if (PeriodRegularExpressionConfig.DayRegex.IsMatch(periodParam))
     {
         return(TickerDayParameter.Create(ticker, DayPeriod.Parse(periodParam)));
     }
     else if (PeriodRegularExpressionConfig.FiscalQuarterRegex.IsMatch(periodParam))
     {
         var period = FiscalQuarterPeriod.Parse(periodParam);
         return(TickerQuarterParameter.Create(ticker, period));
     }
     else if (PeriodRegularExpressionConfig.RelativeFiscalQuarterRegex.IsMatch(periodParam))
     {
         var period = RelativeFiscalQuarterPeriod.Parse(periodParam);
         return(TickerQuarterParameter.Create(ticker, period));
     }
     else if (PeriodRegularExpressionConfig.BCodeUdfFiscalQuarterInputRegex.IsMatch(periodParam))
     {
         var match = PeriodRegularExpressionConfig.BCodeUdfFiscalQuarterInputRegex
                     .Match(periodParam);
         var fy = match.Groups["fiscalYear"].Value.Trim();
         var fq = match.Groups["fiscalQuarter"].Value.Trim();
         if (fy.Contains("LY"))
         {
             var prevYears = RelativeFiscalQuarterPeriod.ParseRelativeValue("years", match);
             if (prevYears > latestFiscalQuarterPeriod.Year)
             {
                 throw new ValidationError($"{prevYears} is bigger than {latestFiscalQuarterPeriod.Year}");
             }
             var fiscalQuarter = fq.Replace("Q", "");
             var period        = FiscalQuarterPeriod.Create(latestFiscalQuarterPeriod.Year - prevYears, uint.Parse(fiscalQuarter));
             return(TickerQuarterParameter.Create(ticker, fy, fiscalQuarter, period));
         }
         else if (fq.Contains("LQ"))
         {
             var prevQuarters = RelativeFiscalQuarterPeriod.ParseRelativeValue("quarters", match);
             var period       = FiscalQuarterPeriod.Create(uint.Parse(fy), latestFiscalQuarterPeriod.Quarter).Before(0, prevQuarters);
             return(TickerQuarterParameter.Create(ticker, fy, fq, period));
         }
         else
         {
             throw new ValidationError($"{periodParam} is not supported input format");
         }
     }
     else
     {
         throw new ValidationError($"{periodParam} is not supported input format");
     }
 }
        public void CreateGetQuarterRangeRequestTest()
        {
            // ok case
            var ticker  = "6501";
            var fromStr = "2020Q1";
            var toStr   = "2022Q4";

            var from      = FiscalQuarterPeriod.Parse(fromStr);
            var to        = FiscalQuarterPeriod.Parse(toStr);
            var parameter = TickerPeriodRangeParameter.Create(ticker, from, to);

            var request = BuffettCodeApiV3RequestCreator.CreateGetQuarterRangeRequest(parameter);

            Assert.AreEqual(request.EndPoint, BuffettCodeApiV3Config.ENDPOINT_BULK_QUARTER);
            Assert.AreEqual(ticker, request.Parameters["ticker"]);
            Assert.AreEqual(fromStr, request.Parameters["from"]);
            Assert.AreEqual(toStr, request.Parameters["to"]);
        }
        public void EqualsTest()
        {
            var a = TickerQuarterParameter.Create("1234", FiscalQuarterPeriod.Create(2020, 1));
            var b = TickerQuarterParameter.Create("1234", FiscalQuarterPeriod.Parse("2020Q1"));
            var c = TickerQuarterParameter.Create("2345", FiscalQuarterPeriod.Create(2020, 1));
            var d = TickerQuarterParameter.Create("1234", FiscalQuarterPeriod.Create(2020, 2));
            var e = TickerQuarterParameter.Create("1234", RelativeFiscalQuarterPeriod.Create(1, 2));
            var f = TickerQuarterParameter.Create("1234", RelativeFiscalQuarterPeriod.Create(1, 2));
            var g = TickerQuarterParameter.Create("1234", RelativeFiscalQuarterPeriod.Create(1, 3));
            var i = TickerQuarterParameter.Create("2345", RelativeFiscalQuarterPeriod.Create(1, 2));
            var j = TickerQuarterParameter.Create("2345", "2019", "LQ-2", RelativeFiscalQuarterPeriod.Create(1, 2));

            Assert.AreEqual(a, b);
            Assert.AreNotEqual(a, c);
            Assert.AreNotEqual(a, d);
            Assert.AreNotEqual(a, e);
            Assert.AreEqual(e, f);
            Assert.AreNotEqual(e, g);
            Assert.AreNotEqual(e, i);
            Assert.AreNotEqual(e, g);
            Assert.AreNotEqual(e, j);
        }