示例#1
0
 def setUp(self):
     """ Setup work before each test
     """
     self.all_stocks = stocks.StockCollection()
     sa.LoadCSV(TEST_FILES["march1.csv"], self.all_stocks)
     sa.LoadCSV(TEST_FILES["march2.csv"], self.all_stocks)
     sa.LoadCSV(TEST_FILES["march3.csv"], self.all_stocks)
     sa.LoadCSV(TEST_FILES["march4.csv"], self.all_stocks)
     sa.LoadCSV(TEST_FILES["march5.csv"], self.all_stocks)
     sa.LoadTriplet(TEST_FILES["feb1.trp"], self.all_stocks)
     sa.LoadTriplet(TEST_FILES["feb2.trp"], self.all_stocks)
     sa.LoadTriplet(TEST_FILES["feb3.trp"], self.all_stocks)
     sa.LoadTriplet(TEST_FILES["feb4.trp"], self.all_stocks)
示例#2
0
    def test_simple_case(self):
        """ Large file test of LoadCSV to ensure the correct number of 
            stocks are loaded
        """
        loadCsv = sa.LoadCSV(TEST_FILES['march1.csv'], self.all_stocks)

        stocks_loaded = self.all_stocks._all_stocks.keys()
        self.assertEqual(len(stocks_loaded), 1910,
                         'LoadCSV should load correct number of stocks')
示例#3
0
    def testSimpleResult(self):
        """ Large file test of the HighLow analyser
        """
        # Load a simple training set
        sa.LoadCSV(TEST_FILES['march1.csv'], self.all_stocks)
        hl = sa.HighLow()

        stock = self.all_stocks.get_stock("ADV")
        stock.analyse(hl)

        res = hl.result()
        self.assertEqual(
            res, (0.025, 0.023),
            'Did not get correct value for the Highest and Lowest price')
示例#4
0
    def testSimpleResult(self):
        """ Large file test of the MovingAverage analyser
        """
        num_days = 4

        # Load a simple training set
        sa.LoadCSV(TEST_FILES['march1.csv'], self.all_stocks)
        ma = sa.MovingAverage(num_days)

        stock = self.all_stocks.get_stock("ADV")
        stock.analyse(ma)

        res = ma.result()
        self.assertEqual(
            res, 0.02375,
            'MovingAverage not correct for stock "ADV" in "march1.csv"')
示例#5
0
    def testSimpleResult(self):
        """ A large file test of the GapUp analysers
        """
        delta = 0.0009

        # Load a simple training set
        sa.LoadCSV(TEST_FILES['march1.csv'], self.all_stocks)
        gu = sa.GapUp(delta)

        stock = self.all_stocks.get_stock("ADV")
        stock.analyse(gu)

        res = gu.result()
        self.assertIsNotNone(
            res,
            'GapUp should return a valid TradingData for stock "ADV" in "march1.csv"'
        )
        self.assertEqual(
            res.get_date(), '20170228',
            'GapUp should return correct result for stock "ADV" in "march1.csv"'
        )
示例#6
0
 def setUp(self):
     """ Setup work before each test
     """
     self.all_stocks = stocks.StockCollection()
     sa.LoadCSV(TEST_FILES["march1_small.csv"], self.all_stocks)
示例#7
0
 def test_invalid_file(self):
     """ Test program raises appropriate exceptions
     """
     with self.assertRaises(RuntimeError):
         # This is an invalid Triplet file and should not work
         sa.LoadCSV('stocks.py', self.all_stocks)
示例#8
0
 def test_process_overriden(self):
     """ [OOC 4] Demonstrated correct understanding of overriding methods
     """
     loadCsv = sa.LoadCSV(TEST_FILES['march1.csv'], self.all_stocks)
     with open(TEST_FILES['march1.csv'], 'r') as f:
         loadCsv._process(f)
示例#9
0
 def test_inheritance(self):
     """ [OOC 3] Demonstrated correct understanding of inheritance
     """
     loadCsv = sa.LoadCSV(TEST_FILES['march1.csv'], self.all_stocks)
     self.assertEqual(loadCsv.__class__.__bases__[0].__name__, 'Loader',
                      'LoadCSV should correctly inherit from Loader')