def strategy_pass(): stock = Stock(TEST_PASS_TRADE_STOCK) stock.refresh(to_date=TEST_REFRESH_DATE_PASS) stock.add_indicator('SMA80') stock.add_indicator('SMA150') test = Strategy('SMA80_SMA150', TEST_BUY_CONDITION, TEST_SELL_CONDITION) test.refresh([stock]) compare(test, STRATEGY_PASS, "Pass strategy")
def init_refreshed_stock_with_indicators(): stock = Stock(TEST_STOCK) stock.refresh(to_date = TEST_REFRESH_DATE_WITH_INDICATORS) Indicator('SMA80', partial(SMA.execute, window = 80)) Indicator('SMA150', partial(SMA.execute, window = 150)) stock.add_indicator('SMA80') stock.add_indicator('SMA150') os.rename(SAVE_FOLDER + stock.path, TEST_FOLDER + 'refreshed_stock_with_indicators.p')
def init_stock_with_indicators(): stock = Stock(TEST_STOCK) stock.refresh(to_date = TEST_REFRESH_DATE_NOT_EMPTY) indicator = Indicator('SMA80', partial(SMA.execute, window = 80)) Indicator('SMA150', partial(SMA.execute, window = 150)) stock.add_indicator('SMA80') stock.add_indicator('SMA150') os.rename(SAVE_FOLDER + stock.path, TEST_FOLDER + 'stock_with_indicators.p') os.rename(SAVE_FOLDER + indicator.path, TEST_FOLDER + 'applied_indicator.p')
def init_strategy_pass(): stock = Stock(TEST_PASS_TRADE_STOCK) stock.refresh(to_date = TEST_REFRESH_DATE_PASS) Indicator('SMA80', partial(SMA.execute, window = 80)) Indicator('SMA150', partial(SMA.execute, window = 150)) stock.add_indicator('SMA80') stock.add_indicator('SMA150') strategy = Strategy('SMA80_SMA150', test_buy_condition, test_sell_condition) strategy.refresh([stock]) os.rename(SAVE_FOLDER + strategy.path, TEST_FOLDER + 'strategy_pass.p')
def init_strategy_awaiting_sell_before(): stock = Stock(TEST_AWAITING_TRADE_STOCK) stock.refresh(to_date = TEST_REFRESH_DATE_AWAITING_SELL_1) Indicator('SMA80', partial(SMA.execute, window = 80)) Indicator('SMA150', partial(SMA.execute, window = 150)) stock.add_indicator('SMA80') stock.add_indicator('SMA150') strategy = Strategy('SMA80_SMA150', test_buy_condition, test_sell_condition) strategy.refresh([stock]) os.rename(SAVE_FOLDER + strategy.path, TEST_FOLDER + 'strategy_awaiting_sell_before.p')
def init_applied_strategy(): stock = Stock(TEST_STOCK) stock.refresh(to_date = TEST_REFRESH_DATE_WITH_INDICATORS) Indicator('SMA80', partial(SMA.execute, window = 80)) Indicator('SMA150', partial(SMA.execute, window = 150)) stock.add_indicator('SMA80') stock.add_indicator('SMA150') strategy = Strategy('SMA80_SMA150', test_buy_condition, test_sell_condition) strategy.refresh([stock]) os.rename(SAVE_FOLDER + strategy.path, TEST_FOLDER + 'applied_strategy.p') os.rename(SAVE_FOLDER + stock.path, TEST_FOLDER + 'stock_with_applied_strategy.p')
def strategy_awaiting_sell(): stock = Stock(TEST_AWAITING_TRADE_STOCK) stock.refresh(to_date=TEST_REFRESH_DATE_AWAITING_SELL_1) stock.add_indicator('SMA80') stock.add_indicator('SMA150') test = File('SMA80_SMA150', class_type='Strategy').load() test.refresh([stock]) compare(test, STRATEGY_AWAITING_SELL_BEFORE, "Awaiting sell before") test.refresh([stock]) print("Reiteration: ok") stock.refresh(to_date=TEST_REFRESH_DATE_AWAITING_SELL_2) test.refresh([stock]) compare(test, STRATEGY_AWAITING_SELL_AFTER, "Awaiting sell after")
def strategy_awaiting_buy(): stock = Stock(TEST_AWAITING_TRADE_STOCK) stock.refresh(to_date=TEST_REFRESH_DATE_AWAITING_BUY_1) stock.add_indicator('SMA80') stock.add_indicator('SMA150') test = Strategy('SMA80_SMA150', TEST_BUY_CONDITION, TEST_SELL_CONDITION) test.refresh([stock]) compare(test, STRATEGY_AWAITING_BUY_BEFORE, "Awaiting buy before") test.refresh([stock]) print("Reiteration: ok") stock.refresh(to_date=TEST_REFRESH_DATE_AWAITING_BUY_2) test.refresh([stock]) compare(test, STRATEGY_AWAITING_BUY_AFTER, "Awaiting buy after")
def init_refreshed_not_empty_stock(): stock = Stock(TEST_STOCK) stock.refresh(to_date = TEST_REFRESH_DATE_NOT_EMPTY) os.rename(SAVE_FOLDER + stock.path, TEST_FOLDER + 'refreshed_not_empty_stock.p')