def testTutorial3(self): with common.CopyFiles( [os.path.join("testcases", "data", "orcl-2000.csv")], "."): lines = common.run_sample_script("tutorial-3.py").split("\n") self.assertTrue( common.compare_head("tutorial-3.output", lines[:30])) self.assertTrue( common.compare_tail("tutorial-3.output", lines[-4:-1]))
def testCSVFeed(self): with common.CopyFiles([os.path.join("samples", "data", "quandl_gold_2.csv")], "."): code = """import sys sys.path.append('samples') import csvfeed_1 """ lines = common.run_python_code(code).split("\n") self.assertTrue(common.compare_head("csvfeed_1.output", lines[0:10])) self.assertTrue(common.compare_tail("csvfeed_1.output", lines[-10:-1]))
def testTutorial1MtGox(self): with common.CopyFiles([os.path.join("samples", "data", "trades-mtgox-usd-2013-03.csv")], "."): code = """import sys sys.path.append('samples') import tutorial_mtgox_1 tutorial_mtgox_1.main(False) """ lines = common.run_python_code(code).split("\n") self.assertTrue(common.compare_head("tutorial_mtgox_1.output", lines[0:10])) self.assertTrue(common.compare_tail("tutorial_mtgox_1.output", lines[-10:-1]))
def testExample2(self): with common.CopyFiles([os.path.join("testcases", "data", "30min-bitstampUSD-2.csv")], "30min-bitstampUSD.csv"): code = """import sys sys.path.append('samples') import bccharts_example_2 bccharts_example_2.main(False) """ lines = common.run_python_code(code).split("\n") self.assertTrue(common.compare_head("bccharts_example_2.output", lines[0:10], "testcases/data")) self.assertTrue(common.compare_tail("bccharts_example_2.output", lines[-10:-1], "testcases/data"))
def testTutorial3(self): with common.CopyFiles( [os.path.join("testcases", "data", "orcl-2000.csv")], "."): res = common.run_sample_script("tutorial-3.py") self.assertTrue( common.compare_head("tutorial-3.output", res.get_output_lines(True)[:30])) self.assertTrue( common.compare_tail("tutorial-3.output", res.get_output_lines(True)[-3:])) self.assertTrue(res.exit_ok())
def testExample1(self): with common.CopyFiles([os.path.join("testcases", "data", "bitstampUSD-2.csv")], "bitstampUSD.csv"): code = """import sys sys.path.append('samples') import bccharts_example_1 bccharts_example_1.main() """ common.run_python_code(code) lines = common.get_file_lines("30min-bitstampUSD.csv") self.assertTrue(common.compare_head("30min-bitstampUSD-2.csv", lines[0:10], "testcases/data")) self.assertTrue(common.compare_tail("30min-bitstampUSD-2.csv", lines[-10:], "testcases/data")) os.remove("30min-bitstampUSD.csv")
def testTutorial1MtGox(self): with common.CopyFiles( [os.path.join("samples", "data", "trades-mtgox-usd-2013-03.csv")], "."): code = """import sys sys.path.append('samples') import tutorial_mtgox_1 tutorial_mtgox_1.main(False) """ lines = common.run_python_code(code).split("\n") self.assertTrue( common.compare_head("tutorial_mtgox_1.output", lines[0:10])) self.assertTrue( common.compare_tail("tutorial_mtgox_1.output", lines[-10:-1]))
def testEventStudy(self): files = [] for year in range(2008, 2010): for symbol in ["AA", "AES", "AIG"]: fileName = "%s-%d-yahoofinance.csv" % (symbol, year) files.append(os.path.join("samples", "data", fileName)) with common.CopyFiles(files, "."): code = """import sys sys.path.append('samples') import eventstudy eventstudy.main(False) """ lines = common.run_python_code(code).split("\n") self.assertTrue(common.compare_tail("eventstudy.output", lines[-2:-1]))
def testBBands(self): files = [] for year in range(2011, 2013): for symbol in ["yhoo"]: fileName = "%s-%d-yahoofinance.csv" % (symbol, year) files.append(os.path.join("samples", "data", fileName)) with common.CopyFiles(files, "."): code = """import sys sys.path.append('samples') import bbands bbands.main(False) """ lines = common.run_python_code(code).split("\n") self.assertTrue(common.compare_tail("bbands.output", lines[-2:-1]))
def testErnieChanGldVsGdx(self): files = [] for year in range(2006, 2013): for symbol in ["gld", "gdx"]: fileName = "%s-%d-yahoofinance.csv" % (symbol, year) files.append(os.path.join("samples", "data", fileName)) with common.CopyFiles(files, "."): code = """import sys sys.path.append('samples') import statarb_erniechan statarb_erniechan.main(False) """ lines = common.run_python_code(code).split("\n") self.assertTrue(common.compare_tail("statarb_erniechan.output", lines[-2:-1]))
def testRSI2(self): files = [] for year in range(2009, 2013): for symbol in ["DIA"]: fileName = "%s-%d-yahoofinance.csv" % (symbol, year) files.append(os.path.join("samples", "data", fileName)) with common.CopyFiles(files, "."): code = """import sys sys.path.append('samples') import rsi2_sample rsi2_sample.main(False) """ res = common.run_python_code(code) self.assertTrue(common.compare_tail("rsi2_sample.output", res.get_output_lines()[-2:-1])) self.assertTrue(res.exit_ok())
def testMarketTiming(self): common.init_temp_path() files = [] instruments = ["MSFT", "ORCL", "IBM", "HPQ", "WMT", "UPS", "TGT", "CCL", "XOM", "CVX", "COP", "OXY", "BAC", "JPM", "WFC", "GS", "PG", "PEP", "CL", "KO"] for year in range(2005, 2013+1): for symbol in instruments: fileName = "%s-%d-yahoofinance.csv" % (symbol, year) files.append(os.path.join("samples", "data", fileName)) with common.CopyFiles(files, "data"): code = """import sys sys.path.append('samples') import market_timing market_timing.main(False) """ lines = common.run_python_code(code).split("\n") self.assertTrue(common.compare_tail("market_timing.output", lines[-10:-1]))
def testQuandl(self): files = [] for year in range(2006, 2013): for symbol in ["GORO"]: fileName = "WIKI-%s-%d-quandl.csv" % (symbol, year) files.append(os.path.join("samples", "data", fileName)) files.append(os.path.join("samples", "data", "quandl_gold_2.csv")) with common.CopyFiles(files, "."): code = """import sys sys.path.append('samples') import quandl_sample quandl_sample.main(False) """ lines = common.run_python_code(code).split("\n") self.assertTrue(common.compare_head("quandl_sample.output", lines[0:10])) self.assertTrue(common.compare_tail("quandl_sample.output", lines[-10:-1]))
def testMarketTiming(self): common.init_temp_path() files = [] instruments = ["VTI", "VEU", "IEF", "VNQ", "DBC", "SPY"] for year in range(2007, 2013+1): for symbol in instruments: fileName = "%s-%d-yahoofinance.csv" % (symbol, year) files.append(os.path.join("samples", "data", fileName)) with common.CopyFiles(files, "data"): code = """import sys sys.path.append('samples') import market_timing market_timing.main(False) """ lines = common.run_python_code(code).split("\n") self.assertTrue(common.compare_tail("market_timing.output", lines[-10:-1]))
def testRSI2(self): files = [] for year in range(2009, 2013): for symbol in ["DIA"]: fileName = "%s-%d-yahoofinance.csv" % (symbol, year) files.append(os.path.join("samples", "data", fileName)) with common.CopyFiles(files, "."): code = """import sys sys.path.append('samples') import rsi2_sample rsi2_sample.main(False) """ res = common.run_python_code(code) self.assertTrue( common.compare_tail("rsi2_sample.output", res.get_output_lines()[-2:-1])) self.assertTrue(res.exit_ok())
def testTutorial3(self): with common.CopyFiles([os.path.join("testcases", "data", "orcl-2000.csv")], "."): res = common.run_sample_script("tutorial-3.py") self.assertTrue(common.compare_head("tutorial-3.output", res.get_output_lines(True)[:30])) self.assertTrue(common.compare_tail("tutorial-3.output", res.get_output_lines(True)[-3:])) self.assertTrue(res.exit_ok())
def testTutorial2(self): with common.CopyFiles([os.path.join("testcases", "data", "orcl-2000.csv")], "."): lines = common.run_sample_script("tutorial-2.py") self.assertTrue(common.compare_head("tutorial-2.output", lines[:15])) self.assertTrue(common.compare_tail("tutorial-2.output", lines[-3:]))