Exemplo n.º 1
0
    def test_covariance_different_sets(self):
        test_quotes1 = DataLoader(os.path.join("tests", "test_data"),
                                  date(2018, 11, 1), date(2018, 11, 30),
                                  "close", "").get_quotes()
        test_quotes2 = DataLoader(os.path.join("tests", "test_data3"),
                                  date(2018, 11, 1), date(2018, 11, 30),
                                  "close", "").get_quotes()

        covariance = VarianceCovarianceAnalyser(test_quotes1,
                                                test_quotes2).covariance()

        self.assertEqual(round(covariance, 11), -0.30202140309)
Exemplo n.º 2
0
    def test_covariance_equal_sets(self):
        test_quotes1 = DataLoader(os.path.join("tests", "test_data"),
                                  date(2018, 11, 1), date(2018, 11, 30),
                                  "close", "").get_quotes()
        test_quotes2 = DataLoader(os.path.join("tests", "test_data2"),
                                  date(2018, 11, 1), date(2018, 11, 30),
                                  "close", "").get_quotes()

        covariance = VarianceCovarianceAnalyser(test_quotes1,
                                                test_quotes2).covariance()

        self.assertEqual(round(covariance, 11), 0.02666666667)
Exemplo n.º 3
0
    def test_average(self):
        test_quotes = DataLoader(os.path.join("tests", "test_data"),
                                 date(2018, 11, 1), date(2018, 11, 30),
                                 "close", "").get_quotes()
        average_closing_price = DescriptiveStatistics(test_quotes).average()

        self.assertEqual(average_closing_price, 15.9)
Exemplo n.º 4
0
    def test_std_dev(self):
        test_quotes = DataLoader(os.path.join("tests", "test_data"),
                                 date(2018, 11, 1), date(2018, 11, 30),
                                 "close", "").get_quotes()
        std_dev = DescriptiveStatistics(test_quotes).standard_deviation()

        self.assertEqual(round(std_dev, 5), 3.12357)
Exemplo n.º 5
0
    def test_covariance_same_data(self):
        test_quotes1 = DataLoader(os.path.join("tests", "test_data"),
                                  date(2018, 11, 1), date(2018, 11, 30),
                                  "close", "").get_quotes()

        covariance = VarianceCovarianceAnalyser(test_quotes1,
                                                test_quotes1).covariance()
        variance = DescriptiveStatistics(test_quotes1).variance()

        self.assertEqual(covariance, variance)
    def test_high_quotes(self):
        test_quotes = DataLoader(os.path.join("tests", "test_data"),
                                 date(2018, 11, 1), date(2018, 11, 30), "high",
                                 "")

        high_quotes = {
            '20181101': 16.0,
            '20181102': 15.0,
            '20181103': 17.0,
            '20181104': 19.0,
            '20181105': 14.0,
            '20181106': 12.0,
            '20181107': 20.0,
            '20181108': 19.0,
            '20181109': 16.0,
            '20181110': 19.0,
            '20181111': 10.0,
            '20181112': 11.0,
            '20181113': 12.0,
            '20181114': 14.0,
            '20181115': 15.0,
            '20181116': 10.0,
            '20181117': 15.0,
            '20181118': 17.0,
            '20181119': 20.0,
            '20181120': 13.0,
            '20181121': 13.0,
            '20181122': 13.0,
            '20181123': 17.0,
            '20181124': 12.0,
            '20181125': 10.0,
            '20181126': 11.0,
            '20181127': 16.0,
            '20181128': 11.0,
            '20181129': 16.0,
            '20181130': 18.0
        }

        self.assertEqual(test_quotes.get_quotes(), high_quotes)
    def test_volumes(self):
        test_volumes = DataLoader(os.path.join("tests", "test_data"),
                                  date(2018, 11, 1), date(2018, 11, 30),
                                  "volume", "")

        volumes = {
            '20181101': 7911.0,
            '20181102': 6831.0,
            '20181103': 1892.0,
            '20181104': 1824.0,
            '20181105': 1169.0,
            '20181106': 1090.0,
            '20181107': 5869.0,
            '20181108': 7072.0,
            '20181109': 4181.0,
            '20181110': 3971.0,
            '20181111': 4776.0,
            '20181112': 5232.0,
            '20181113': 3122.0,
            '20181114': 6601.0,
            '20181115': 1276.0,
            '20181116': 1483.0,
            '20181117': 6479.0,
            '20181118': 2294.0,
            '20181119': 5622.0,
            '20181120': 6252.0,
            '20181121': 5422.0,
            '20181122': 6811.0,
            '20181123': 5853.0,
            '20181124': 6692.0,
            '20181125': 7188.0,
            '20181126': 4200.0,
            '20181127': 5709.0,
            '20181128': 3278.0,
            '20181129': 4914.0,
            '20181130': 1508.0
        }

        self.assertEqual(test_volumes.get_quotes(), volumes)
Exemplo n.º 8
0
    def test_data_flow(self):
        test_path = os.path.dirname(__file__)
        test_path = os.path.join(os.path.split(test_path)[0], "data")

        try:
            os.remove(os.path.join(test_path, "11BIT.json"))
        except FileNotFoundError:
            pass

        test_data_retriever = QuoteRetriever(last_day_close=False,
                                             headers=True)

        test_data_retriever.save_quotes()

        test_data = DataLoader("11BIT", date(2018, 11, 1),
                               date(2018, 11, 30)).get_quotes()

        average = DescriptiveStatistics(test_data).average()
        self.assertEqual(round(average, 2), 273.35)
Exemplo n.º 9
0
    pprint("START LOCATION:")
    startLocation = locationInput("000000")
    pprint("END LOCATION:")
    endLocation = locationInput("999999")
    pprint("START DAY:")
    startDay = dayInput("Monday")
    pprint("END DAY:")
    endDay = dayInput("Sunday")
    pprint("START TIME:")
    startTime = timeInput("0")
    pprint("END TIME:")
    endTime = timeInput("500340")
    data.refineData(startLocation, endLocation, startDay, endDay, startTime,
                    endTime)


def showStats():
    stats = data.calculateStats()
    clear()
    pprint("Statistics for currently refined data are as follows:")
    pprint("Average Temperature - {:.2f}".format(stats["temperatureAverage"]))
    pprint("Temperature Range - {:.2f}".format(stats["temperatureRange"]))
    pprint("Average Wind Speed - {:.2f}".format(stats["windSpeedAverage"]))
    pprint("Wind Speed Range - {:.2f}".format(stats["windSpeedRange"]))
    print("\n\n\n")


if __name__ == "__main__":
    global data
    data = DataLoader()
    mainloop()
 def test_ticker_type(self):
     ticker = 20
     with self.assertRaises(TypeError):
         DataLoader(ticker=ticker)
 def test_quote_type(self):
     quote_type = 20
     with self.assertRaises(TypeError):
         DataLoader(quote_type=quote_type, ticker="11BIT")
 def test_end_date(self):
     end_date = "wrong date"
     with self.assertRaises(TypeError):
         DataLoader(end_date=end_date, ticker="11BIT")
 def test_start_date_type(self):
     start_date = "wrong date"
     with self.assertRaises(TypeError):
         DataLoader(start_date=start_date, ticker="11BIT")
Exemplo n.º 14
0
 def test_variance(self):
     test_quotes = DataLoader(os.path.join("tests", "test_data"),
                              date(2018, 11, 1), date(2018, 11, 30),
                              "close", "").get_quotes()
     variance = DescriptiveStatistics(test_quotes).variance()
     self.assertEqual(round(variance, 14), 9.75666666666667)