def test_get_trades_from_positions(self): positions = pd.DataFrame([np.nan, 2, 3, np.nan, 2, 3, 3.1, 4, 3, 5, 7], pd.date_range(start=pd.datetime(2015, 1, 1), periods=11)) price = pd.DataFrame([100, 103, np.nan, 106, 110, 105, np.nan, 106, 120, np.nan, 142], pd.date_range(start=pd.datetime(2015, 1, 1), periods=11)) #trades=get_trades_from_positions(price, positions, delayfill, roundpositions, None, None, None, None) trades = get_trades_from_positions( price, positions, True, True, None, None, None, None) self.assertEqual(list(trades.trades), [ 2.0, 1.0, -1.0, 1.0, 1.0, -1.0, 2.0, 2.0]) self.assertEqual(list(trades.fill_price)[ :-1], [106.0, 106.0, 105.0, 106.0, 120.0, 142.0, 142.0]) trades = get_trades_from_positions( price, positions, False, True, None, None, None, None) self.assertEqual(list(trades.trades), [ 2.0, 1.0, -1.0, 1.0, 1.0, -1.0, 2.0, 2.0]) self.assertEqual(list(trades.fill_price), [ 103.0, 106.0, 110.0, 105.0, 106.0, 120.0, 142.0, 142.0]) trades = get_trades_from_positions( price, positions, True, False, None, None, None, None) self.assertEqual(list(trades.trades), [ 2.0, 1.0, -1.0, 1.0, 0.1, 0.9, -1.0, 2.0, 2.0]) self.assertEqual(list(trades.fill_price)[ :-1], [106.0, 106.0, 105.0, 106.0, 106.0, 120.0, 120.0, 142.0, 142.0])
def test_get_trades_from_positions(self): positions = pd.DataFrame([np.nan, 2, 3, np.nan, 2, 3, 3.1, 4, 3, 5, 7], dt_range2) price = pd.DataFrame( [100, 103, np.nan, 106, 110, 105, np.nan, 106, 120, np.nan, 142], dt_range2) # test delayed fill delayfill = True roundpositions = True get_daily_returns_volatility = None forecast = None fx = None value_of_price_point = None trades = get_trades_from_positions(price, positions, delayfill, roundpositions, get_daily_returns_volatility, forecast, fx, value_of_price_point) np.testing.assert_almost_equal( trades.trades, [2.0, 1.0, -1.0, 1.0, 1.0, -1.0, 2.0, 2.0]) np.testing.assert_almost_equal( trades.fill_price[:-1], [106.0, 106.0, 105.0, 106.0, 120.0, 142.0, 142.0]) # test none delayed fill delayfill = False trades = get_trades_from_positions(price, positions, delayfill, roundpositions, get_daily_returns_volatility, forecast, fx, value_of_price_point) np.testing.assert_almost_equal( trades.trades, [2.0, 1.0, -1.0, 1.0, 1.0, -1.0, 2.0, 2.0]) np.testing.assert_almost_equal( trades.fill_price, [103.0, 106.0, 110.0, 105.0, 106.0, 120.0, 142.0, 142.0]) # test roundpositions delayfill = True roundpositions = False trades = get_trades_from_positions(price, positions, delayfill, roundpositions, get_daily_returns_volatility, forecast, fx, value_of_price_point) np.testing.assert_almost_equal( trades.trades, [2.0, 1.0, -1.0, 1.0, 0.1, 0.9, -1.0, 2.0, 2.0]) np.testing.assert_almost_equal( trades.fill_price[:-1], [106.0, 106.0, 105.0, 106.0, 106.0, 120.0, 142.0, 142.0])
def test_get_trades_from_positions(self): positions = pd.DataFrame([np.nan, 2, 3, np.nan, 2, 3, 3.1, 4, 3, 5, 7], dt_range2) price = pd.DataFrame( [100, 103, np.nan, 106, 110, 105, np.nan, 106, 120, np.nan, 142], dt_range2) # test delayed fill delayfill = True roundpositions = True get_daily_returns_volatility = None forecast = None fx = None value_of_price_point = None trades = get_trades_from_positions( price, positions, delayfill, roundpositions, get_daily_returns_volatility, forecast, fx, value_of_price_point) np.testing.assert_almost_equal( trades.trades, [2.0, 1.0, -1.0, 1.0, 1.0, -1.0, 2.0, 2.0]) np.testing.assert_almost_equal(trades.fill_price[:-1], [ 106.0, 106.0, 105.0, 106.0, 120.0, 142.0, 142.0 ]) # test none delayed fill delayfill = False trades = get_trades_from_positions( price, positions, delayfill, roundpositions, get_daily_returns_volatility, forecast, fx, value_of_price_point) np.testing.assert_almost_equal( trades.trades, [2.0, 1.0, -1.0, 1.0, 1.0, -1.0, 2.0, 2.0]) np.testing.assert_almost_equal(trades.fill_price, [ 103.0, 106.0, 110.0, 105.0, 106.0, 120.0, 142.0, 142.0 ]) # test roundpositions delayfill = True roundpositions = False trades = get_trades_from_positions( price, positions, delayfill, roundpositions, get_daily_returns_volatility, forecast, fx, value_of_price_point) np.testing.assert_almost_equal( trades.trades, [2.0, 1.0, -1.0, 1.0, 0.1, 0.9, -1.0, 2.0, 2.0]) np.testing.assert_almost_equal(trades.fill_price[:-1], [ 106.0, 106.0, 105.0, 106.0, 106.0, 120.0, 142.0, 142.0 ])