def testMakeOptionException(self): # valid arguments fn_cal = self.test_mktcal refs = [dt.date(2015, 1, 3)] tests = [dt.date(2015, 1, 10)] days = 10 inc = 2 future = 10 fn_sym = self.test_symbol_file cv_factor = 2 max_stocks = 10 fn_opt = self.fn_opt # make sure no exception is raised with valid arguments target.make_option_data(fn_cal, refs, tests, days, inc, future, fn_sym, cv_factor, max_stocks, fn_opt) # empty reference self.assertRaises(ValueError, target.make_option_data, fn_cal, [], tests, days, inc, future, fn_sym, cv_factor, max_stocks, fn_opt) self.assertRaises(ValueError, target.make_option_data, fn_cal, None, tests, days, inc, future, fn_sym, cv_factor, max_stocks, fn_opt) # empty test self.assertRaises(ValueError, target.make_option_data, fn_cal, refs, [], days, inc, future, fn_sym, cv_factor, max_stocks, fn_opt) self.assertRaises(ValueError, target.make_option_data, fn_cal, refs, None, days, inc, future, fn_sym, cv_factor, max_stocks, fn_opt) # train_inc too large self.assertRaises(ValueError, target.make_option_data, fn_cal, refs, tests, days, days, future, fn_sym, cv_factor, max_stocks, fn_opt) # future_day before the last day of date range self.assertRaises(ValueError, target.make_option_data, fn_cal, refs, tests, days, inc, days-1, fn_sym, cv_factor, max_stocks, fn_opt) # cv_factor >= 2 self.assertRaises(ValueError, target.make_option_data, fn_cal, refs, tests, days, inc, future, fn_sym, 1, max_stocks, fn_opt) # max_stocks >= cv_factor self.assertRaises(ValueError, target.make_option_data, fn_cal, refs, tests, days, inc, future, fn_sym, cv_factor, cv_factor-1, fn_opt)
def testMakeOption(self): fn_cal = self.test_mktcal refs = [dt.date(2015, 1, 3), dt.date(2015, 1, 6)] tests = [dt.date(2015, 1, 9), dt.date(2015, 1, 11)] days = 8 inc = 1 future = 10 fn_sym = self.test_symbol_file cv_factor = 3 max_stocks = None # take everything fn_opt = self.fn_opt target.make_option_data(fn_cal, refs, tests, days, inc, future, fn_sym, cv_factor, max_stocks, fn_opt) self.assertTrue(filecmp.cmp(self.expected_option, fn_opt))
def testMakeOption(self): fn_cal = self.test_mktcal refs = [dt.date(2015, 1, 3), dt.date(2015, 1, 6)] tests = [dt.date(2015, 1, 9), dt.date(2015, 1,11)] days = 8 inc = 1 future = 10 fn_sym = self.test_symbol_file cv_factor = 3 max_stocks = None # take everything fn_opt = self.fn_opt target.make_option_data( fn_cal, refs, tests, days, inc, future, fn_sym, cv_factor, max_stocks, fn_opt) self.assertTrue(filecmp.cmp(self.expected_option, fn_opt))
def testMakeOptionException(self): # valid arguments fn_cal = self.test_mktcal refs = [dt.date(2015, 1, 3)] tests = [dt.date(2015, 1, 10)] days = 10 inc = 2 future = 10 fn_sym = self.test_symbol_file cv_factor = 2 max_stocks = 10 fn_opt = self.fn_opt # make sure no exception is raised with valid arguments target.make_option_data(fn_cal, refs, tests, days, inc, future, fn_sym, cv_factor, max_stocks, fn_opt) # empty reference self.assertRaises( ValueError, target.make_option_data, fn_cal, [], tests, days, inc, future, fn_sym, cv_factor, max_stocks, fn_opt, ) self.assertRaises( ValueError, target.make_option_data, fn_cal, None, tests, days, inc, future, fn_sym, cv_factor, max_stocks, fn_opt, ) # empty test self.assertRaises( ValueError, target.make_option_data, fn_cal, refs, [], days, inc, future, fn_sym, cv_factor, max_stocks, fn_opt, ) self.assertRaises( ValueError, target.make_option_data, fn_cal, refs, None, days, inc, future, fn_sym, cv_factor, max_stocks, fn_opt, ) # train_inc too large self.assertRaises( ValueError, target.make_option_data, fn_cal, refs, tests, days, days, future, fn_sym, cv_factor, max_stocks, fn_opt, ) # future_day before the last day of date range self.assertRaises( ValueError, target.make_option_data, fn_cal, refs, tests, days, inc, days - 1, fn_sym, cv_factor, max_stocks, fn_opt, ) # cv_factor >= 2 self.assertRaises( ValueError, target.make_option_data, fn_cal, refs, tests, days, inc, future, fn_sym, 1, max_stocks, fn_opt ) # max_stocks >= cv_factor self.assertRaises( ValueError, target.make_option_data, fn_cal, refs, tests, days, inc, future, fn_sym, cv_factor, cv_factor - 1, fn_opt, )