def test_trigger_sma_200_(self): df = pd.read_csv("resources/2018-12-25-ams-5min.csv") df = preparedata.add_moving_averages(df) e = MockEmitter(data=df) st = IndicatorTrigger("ema_20::>::sma_200") while e.not_finished() and not st.triggered: st.active(e.emit()) self.assertTrue(st.triggered)
def test_trigger_sma_200(self): df = pd.read_csv("resources/aapl::2018-06-01::1min.csv") df = preparedata.add_moving_averages(df) e = MockEmitter(data=df) st = SimpleTrigger("sma_200::>::10.10") while e.not_finished() and not st.triggered: st.active(e.emit()) self.assertTrue(st.triggered)
def test_nested_trigger(self): df = pd.read_csv("resources/2018-12-25-ams-5min.csv") df = preparedata.add_moving_averages(df) e = MockEmitter(data=df) st = NestedTrigger( "ema_20::<::last::type=ti&&sma_200::<::last::type=ti") while e.not_finished() and not st.triggered: st.active(e.emit()) self.assertTrue(st.triggered)
def _test_viz_sma(self): import matplotlib.pyplot as plt df = pd.read_csv("resources/2018-12-25-ams-5min.csv") df_prepared = preparedata.add_moving_averages(df) self.assertIsNotNone(df_prepared) print(df_prepared.columns) plt.plot(df_prepared['last'], c='black', linewidth=.4) plt.plot(df_prepared['sma_200'], c='blue', linewidth=.4) plt.plot(df_prepared['ema_20'], c='green', linewidth=.4) plt.show()
def test_trade_buy_sell_technical_indicator(self): df = pd.read_csv("resources/aapl::2018-06-01::1min.csv") df = preparedata.add_moving_averages(df) e = MockEmitter(data=df) # stop should sell strategy = TradeStrategy( buy_trigger="sma_200::<::ema_20::type=ti", sell_trigger="sma_200::>::sma_50::type=technical_indicator", stop_trigger="last::<::1.0", quantity=10) trade = Trade(symbol="mock", strategy=strategy, mock=True) trader = MockTrader(trade) while e.not_finished() and trader.trade.active: trader.follow_course(data=e.emit()) self.assertFalse(trader.trade.active) self.assertEqual(trader.trade.state, TradeState.FINISHED) print(trader.trade.summary.to_json())
def test_add_moving_averages(self): df = pd.read_csv("resources/aapl::2018-06-01::1min.csv") df_prepared = preparedata.add_moving_averages(df=df) self.assertIsNotNone(df_prepared['sma_200']) self.assertIsNotNone(df_prepared['ema_20']) self.assertIsNotNone(df_prepared)