def test_strategy(strategy_name, strategy_func, hdf_filename, min_profit_prct=0.0003, signal_window_time=100, min_window_signals=1, trade_size_usd=1000000, max_position=5000000, fill_function=None): if hdf_filename is None: raise RuntimeError('HDF File must be specified') if not os.path.exists(hdf_filename): raise RuntimeError('Cannot find path specifed') (d, currency_pair, ts, bids, offers, bid_vols, offer_vols) = simulate2.load_dataset(hdf_filename) (signals, mean_spread, mean_range) = strategy_func(d) (usd_pnl, pos_deltas, pos_run, closing_position, closing_pnl, usd_last_pos, ignored_signals) = \ simulate2.execute_aggressive(ts, \ bids, \ offers, \ bid_vols, \ offer_vols, \ signals, \ currency_pair, \ trade_size_usd, \ signal_window_time, \ min_window_signals, \ min_profit_prct, \ carry_position = False, \ max_position = max_position, \ fill_function=None, \ cut_long = -(mean_spread+mean_range), \ cut_short= -(mean_spread+mean_range)) print "Min_profit_prct: ", min_profit_prct print "Signal_window_time: ", signal_window_time print "Min_window_signals: ", min_window_signals print "Trade_size_usd: ", trade_size_usd simulate2.trade_stats(d, \ strategy_name,\ ts,\ signals,\ min_profit_prct,\ signal_window_time,\ min_window_signals,\ trade_size_usd,\ max_position,\ usd_pnl,\ pos_deltas,\ closing_position,\ closing_pnl,\ mean_spread,\ mean_range,\ ignored_signals,\ tick_file = hdf_filename, \ out_path='/tmp/')
def mix_test1(): signals = [1, 1, 1, 0, -1, 0, -1, 0, 1, -1] mean_spread = 1 mean_range = 1 # Reset the market bids = np.arange(1, 2, .10) offers = np.arange(1.1, 2.1, .10) bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) # TEST 7 # No take profit - trade only on signals # No cuts - set spread and range high # DO carry position - elimintates averaging problem of closing trde - pnl more transparent # No min profit - trade on all signals - not just profitable ones # This should trade on ALL signals regardless of profitability and never cut (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive( ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=None, carry_position=True, default_trade_size=1, max_position=5, fill_function=None, cut_long=-(mean_spread + mean_range) * 2, cut_short=-(mean_spread + mean_range) * 2, usd_transaction_cost=0, trade_file='/tmp/testoutshit', take_profit_pct=None) assert (round(sum(pnl), 2) == .15) pos_deltas_test = [1., 1., 1., 0., -3., 0., -1., 0., 1., -1.] pos_deltas_out = np.equal(position_deltas, pos_deltas_test) assert (pos_deltas_out.all() == True) # End with position since carry_position is True here pos_run_test = [1., 2., 3., 3., 0., 0., -1., -1., 0., -1.] pos_run_out = np.equal(position_running, pos_run_test) assert (pos_run_out.all() == True) assert (closing_position == -1.) assert (closing_pnl == 0)
def mix_test4(): signals = [1, 1, 1, 0, -1, 0, -1, 0, 1, -1] # Reset the market bids = np.arange(1, 2, .10) offers = np.arange(1.1, 2.1, .10) bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) mean_spread = 0 mean_range = 0.0001 # TEST 10 # Allow take profit - fully exit profitable position # Allow cuts mean_spread = 0 mean_range = 0.0001 # DO NOT carry position - close avg price of long/short against avg of past market # No min profit - trade on all signals - not just profitable ones (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive( ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=None, carry_position=True, default_trade_size=1, max_position=5, fill_function=None, cut_long=-(mean_spread + mean_range) * 2, cut_short=-(mean_spread + mean_range) * 2, usd_transaction_cost=0, trade_file='/tmp/testoutshit', take_profit_pct=0.0001) assert (round(sum(pnl), 2) == 0.02) pos_deltas_test = [1., 1., 1., -3., -1., 1., -1., 1., 1., -1.] pos_deltas_out = np.equal(position_deltas, pos_deltas_test) assert (pos_deltas_out.all() == True) pos_run_test = [1., 2., 3., 0., -1., 0., -1., 0., 1., 0.] pos_run_out = np.equal(position_running, pos_run_test) assert (pos_run_out.all() == True) assert (closing_position == 0.) assert (closing_pnl == 0.)
def short_test3(): # Set up the market # Cut level is offer[6] offers = [2.1, 2., 1.9, 1.8, 1.7, 1.6, 2.5, 1.4, 1.3, 1.2] bids = [2., 1.9, 1.8, 1.7, 1.6, 1.5, 1.4, 1.3, 1.2, 1.1] bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) mean_spread = 0.1 mean_range = 0.0 # Start with short and end with long signals = [-1, 0, 0, 0, 0, 0, 0, 0, 0, 1] # TEST 6 # Test short trade with cutoff # NB - NO CARRY will average closing prices which again distorts pnl in monotonic markets like the test sets so closing pnl will be exaggerated here mean_spread = 0.0 mean_range = 0.0001 (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive( ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=0.0001, carry_position=False, default_trade_size=1, max_position=5, fill_function=None, cut_long=-(mean_spread + mean_range) * 2, cut_short=-(mean_spread + mean_range) * 2, usd_transaction_cost=0, trade_file='/tmp/testoutshit', take_profit_pct=None) assert (round(sum(pnl), 2) == -0.55) pos_deltas_test = [-1., 0., 0., 0., 0., 0., 1., 0., 0., -1.] pos_deltas_out = np.equal(position_deltas, pos_deltas_test) assert (pos_deltas_out.all() == True) pos_run_test = [-1., -1., -1., -1., -1., -1., 0., 0., 0., 0.] pos_run_out = np.equal(position_running, pos_run_test) assert (pos_run_out.all() == True) assert (round(closing_pnl, 2) == -0.05) assert (closing_position == 1.)
def long_test_2(): # Set up the market bids = np.arange(1, 2, .10) offers = np.arange(1.1, 2.1, .10) bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) mean_spread = 0.1 mean_range = 0.0 # Set up signals for single long trade signals = [1, 0, 0, 0, 0, 0, 0, 0, 0, -1] # TEST 2 # Test enter and exit with one buy and sell - no position carry, trade only on signal = False # Test for opportunistic profit # NB - NO CARRY will average closing prices which again distorts pnl in monotonic markets like the test sets so closing pnl will be exaggerated here (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive( ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=0.0001, carry_position=False, default_trade_size=1, max_position=5, fill_function=None, cut_long=-(mean_spread + mean_range) * 2, cut_short=-(mean_spread + mean_range) * 2, usd_transaction_cost=0, trade_file='/tmp/testoutshit', take_profit_pct=0.0001) # Profit here is convoluted since the price array is artificial and changes very quickly so when averaging the price to close the position the true price is distorted - i.e. first 4 offers average to 1.30 assert (round(sum(pnl), 2) == 0.35) pos_deltas_test = [1., 0., -1., 0., 0., 0., 0., 0., 0., 1.] pos_deltas_out = np.equal(position_deltas, pos_deltas_test) assert (pos_deltas_out.all() == True) assert (sum(position_deltas) + closing_position == 0) pos_run_test = [1., 1., 0., 0., 0., 0., 0., 0., 0., 0.] pos_run_out = np.equal(position_running, pos_run_test) assert (pos_run_out.all() == True) assert (round(closing_pnl, 2) == 0.25) assert (closing_position == -1.)
def short_test2(): # Set up the market bids = np.arange(2, 1, -.10) offers = np.arange(2.1, 1.1, -.10) bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) mean_spread = 0.1 mean_range = 0.0 # Start with short and end with long signals = [-1, 0, 0, 0, 0, 0, 0, 0, 0, 1] # TEST 5 # Test short trade first - no carry position, trade only on signal = False # Short and take profit - then trade last frame long and close position with short (no carry) # NB - NO CARRY will average closing prices which again distorts pnl in monotonic markets like the test sets so closing pnl will be exaggerated here (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive( ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=0.0001, carry_position=False, default_trade_size=1, max_position=5, fill_function=None, cut_long=-(mean_spread + mean_range) * 2, cut_short=-(mean_spread + mean_range) * 2, usd_transaction_cost=0, trade_file='/tmp/testoutshit', take_profit_pct=0.0001) assert (round(sum(pnl), 2) == 0.35) pos_deltas_test = [-1., 0., 1., 0., 0., 0., 0., 0., 0., -1.] pos_deltas_out = np.equal(position_deltas, pos_deltas_test) assert (pos_deltas_out.all() == True) pos_run_test = [-1., -1., 0., 0., 0., 0., 0., 0., 0., 0.] pos_run_out = np.equal(position_running, pos_run_test) assert (pos_run_out.all() == True) assert (round(closing_pnl, 2) == 0.25) assert (closing_position == 1.)
def short_test1(): # Set up the market bids = np.arange(2, 1, -.10) offers = np.arange(2.1, 1.1, -.10) bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) mean_spread = 0.1 mean_range = 0.0 # Start with short and end with long signals = [-1, 0, 0, 0, 0, 0, 0, 0, 0, 1] # TEST 4 # Test short trade first - no carry position, trade only on signal = True (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive( ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=0.0001, carry_position=False, default_trade_size=1, max_position=5, fill_function=None, cut_long=-(mean_spread + mean_range) * 2, cut_short=-(mean_spread + mean_range) * 2, usd_transaction_cost=0, trade_file='/tmp/testoutshit', take_profit_pct=None) assert (round(sum(pnl), 2) == 0.8) pos_deltas_test = [-1., 0., 0., 0., 0., 0., 0., 0., 0., 1.] pos_deltas_out = np.equal(position_deltas, pos_deltas_test) assert (pos_deltas_out.all() == True) pos_run_test = [-1., -1., -1., -1., -1., -1., -1., -1., -1., 0.] pos_run_out = np.equal(position_running, pos_run_test) assert (pos_run_out.all() == True) assert (round(closing_pnl, 2) == 0.0) assert (round(closing_position, 2) == 0.0)
def long_test3(): # Set up the market bids = np.arange(1, 2, .10) offers = np.arange(1.1, 2.1, .10) bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) mean_spread = 0.1 mean_range = 0.0 # Set up signals for single long trade signals = [1, 0, 0, 0, 0, 0, 0, 0, 0, -1] # TEST 3 # Test for evaluating profit prct - this shoudl never trigger take profit (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive( ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=100, carry_position=False, default_trade_size=1, max_position=5, fill_function=None, cut_long=-(mean_spread + mean_range) * 2, cut_short=-(mean_spread + mean_range) * 2, usd_transaction_cost=0, trade_file='/tmp/testoutshit', take_profit_pct=0.0001) # Profit here is convoluted since the price array is artificial and changes very quickly so when averaging the price to close the position the true price is distorted - i.e. first 4 offers average to 1.30 assert (round(sum(pnl), 2) == 0.35) pos_deltas_test = [1., 0., -1., 0., 0., 0., 0., 0., 0., 1.] pos_deltas_out = np.equal(position_deltas, pos_deltas_test) assert (pos_deltas_out.all() == True) pos_run_test = [1., 1., 0., 0., 0., 0., 0., 0., 0., 0.] pos_run_out = np.equal(position_running, pos_run_test) assert (pos_run_out.all() == True)
def test_long1(): # Set up the market bids = np.arange(1, 2, .10) offers = np.arange(1.1, 2.1, .10) bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) mean_spread = 0.1 mean_range = 0.0 # Set up signals for single long trade signals = [1, 0, 0, 0, 0, 0, 0, 0, 0, -1] # TEST 1 # Test enter and exit wiht one buy and sell - no position carry, trade only on signal = True # Start with long and end with short (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive( ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=0.0001, carry_position=False, default_trade_size=1, max_position=5, fill_function=None, cut_long=-(mean_spread + mean_range) * 2, cut_short=-(mean_spread + mean_range) * 2, usd_transaction_cost=0, trade_file='/tmp/testoutshit', take_profit_pct=None) assert (round(sum(pnl), 2) == 0.80) assert (sum(position_deltas) == 0.0) assert (sum(position_running) == 9.) assert (closing_position == 0)
def long_test_2(): # Set up the market bids = np.arange(1, 2, .10) offers = np.arange(1.1, 2.1, .10) bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) mean_spread = 0.1 mean_range = 0.0 # Set up signals for single long trade signals = [1,0,0,0,0,0,0,0,0,-1] # TEST 2 # Test enter and exit with one buy and sell - no position carry, trade only on signal = False # Test for opportunistic profit # NB - NO CARRY will average closing prices which again distorts pnl in monotonic markets like the test sets so closing pnl will be exaggerated here (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive(ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=0.0001, carry_position = False, default_trade_size = 1, max_position=5, fill_function=None, cut_long = -(mean_spread+mean_range)*2, cut_short= -(mean_spread+mean_range)*2, usd_transaction_cost= 0, trade_file='/tmp/testoutshit', take_profit_pct=0.0001) # Profit here is convoluted since the price array is artificial and changes very quickly so when averaging the price to close the position the true price is distorted - i.e. first 4 offers average to 1.30 assert(round(sum(pnl),2) == 0.35) pos_deltas_test = [ 1., 0., -1., 0., 0., 0., 0., 0., 0., 1.] pos_deltas_out = np.equal(position_deltas, pos_deltas_test) assert(pos_deltas_out.all() == True) assert(sum(position_deltas) + closing_position == 0) pos_run_test = [ 1., 1., 0., 0., 0., 0., 0., 0., 0., 0.] pos_run_out = np.equal(position_running, pos_run_test) assert(pos_run_out.all() == True) assert(round(closing_pnl,2) == 0.25) assert(closing_position == -1.)
def mix_test4(): signals = [1,1,1,0,-1,0,-1,0,1,-1] # Reset the market bids = np.arange(1, 2, .10) offers = np.arange(1.1, 2.1, .10) bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) mean_spread = 0 mean_range = 0.0001 # TEST 10 # Allow take profit - fully exit profitable position # Allow cuts mean_spread = 0 mean_range = 0.0001 # DO NOT carry position - close avg price of long/short against avg of past market # No min profit - trade on all signals - not just profitable ones (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive(ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=None, carry_position = True, default_trade_size = 1, max_position=5, fill_function=None, cut_long = -(mean_spread+mean_range)*2, cut_short= -(mean_spread+mean_range)*2, usd_transaction_cost= 0, trade_file='/tmp/testoutshit', take_profit_pct=0.0001) assert(round(sum(pnl), 2) == 0.02) pos_deltas_test = [ 1., 1., 1., -3., -1., 1., -1., 1., 1., -1.] pos_deltas_out = np.equal(position_deltas, pos_deltas_test) assert(pos_deltas_out.all() == True) pos_run_test = [ 1., 2., 3., 0., -1., 0., -1., 0., 1., 0.] pos_run_out = np.equal(position_running, pos_run_test) assert(pos_run_out.all() == True) assert(closing_position == 0.) assert(closing_pnl == 0.)
def test_long1(): # Set up the market bids = np.arange(1, 2, .10) offers = np.arange(1.1, 2.1, .10) bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) mean_spread = 0.1 mean_range = 0.0 # Set up signals for single long trade signals = [1,0,0,0,0,0,0,0,0,-1] # TEST 1 # Test enter and exit wiht one buy and sell - no position carry, trade only on signal = True # Start with long and end with short (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive(ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=0.0001, carry_position = False, default_trade_size = 1, max_position=5, fill_function=None, cut_long = -(mean_spread+mean_range)*2, cut_short= -(mean_spread+mean_range)*2, usd_transaction_cost= 0, trade_file='/tmp/testoutshit', take_profit_pct=None) assert(round(sum(pnl),2) == 0.80) assert(sum(position_deltas) == 0.0) assert(sum(position_running) == 9.) assert(closing_position == 0)
def mix_test1(): signals = [1,1,1,0,-1,0,-1,0,1,-1] mean_spread = 1 mean_range = 1 # Reset the market bids = np.arange(1, 2, .10) offers = np.arange(1.1, 2.1, .10) bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) # TEST 7 # No take profit - trade only on signals # No cuts - set spread and range high # DO carry position - elimintates averaging problem of closing trde - pnl more transparent # No min profit - trade on all signals - not just profitable ones # This should trade on ALL signals regardless of profitability and never cut (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive(ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=None, carry_position = True, default_trade_size = 1, max_position=5, fill_function=None, cut_long = -(mean_spread+mean_range)*2, cut_short= -(mean_spread+mean_range)*2, usd_transaction_cost= 0, trade_file='/tmp/testoutshit', take_profit_pct=None) assert(round(sum(pnl), 2) == .15) pos_deltas_test = [ 1., 1., 1., 0., -3., 0., -1., 0., 1., -1.] pos_deltas_out = np.equal(position_deltas, pos_deltas_test) assert(pos_deltas_out.all() == True) # End with position since carry_position is True here pos_run_test = [ 1., 2., 3., 3., 0., 0., -1., -1., 0., -1.] pos_run_out = np.equal(position_running, pos_run_test) assert(pos_run_out.all() == True) assert(closing_position == -1.) assert(closing_pnl == 0)
def short_test3(): # Set up the market # Cut level is offer[6] offers = [ 2.1, 2. , 1.9, 1.8, 1.7, 1.6, 2.5 , 1.4, 1.3, 1.2] bids = [ 2. , 1.9, 1.8, 1.7, 1.6, 1.5, 1.4, 1.3, 1.2, 1.1] bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) mean_spread = 0.1 mean_range = 0.0 # Start with short and end with long signals = [-1,0,0,0,0,0,0,0,0,1] # TEST 6 # Test short trade with cutoff # NB - NO CARRY will average closing prices which again distorts pnl in monotonic markets like the test sets so closing pnl will be exaggerated here mean_spread = 0.0 mean_range = 0.0001 (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive(ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=0.0001, carry_position = False, default_trade_size = 1, max_position=5, fill_function=None, cut_long = -(mean_spread+mean_range)*2, cut_short= -(mean_spread+mean_range)*2, usd_transaction_cost= 0, trade_file='/tmp/testoutshit', take_profit_pct=None) assert(round(sum(pnl), 2) == -0.55) pos_deltas_test = [-1., 0., 0., 0., 0., 0., 1., 0., 0., -1.] pos_deltas_out = np.equal(position_deltas, pos_deltas_test) assert(pos_deltas_out.all() == True) pos_run_test = [ -1., -1., -1., -1., -1., -1., 0., 0., 0., 0.] pos_run_out = np.equal(position_running, pos_run_test) assert(pos_run_out.all() == True) assert(round(closing_pnl,2) == -0.05) assert(closing_position == 1.)
def short_test2(): # Set up the market bids = np.arange(2, 1, -.10) offers = np.arange(2.1, 1.1, -.10) bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) mean_spread = 0.1 mean_range = 0.0 # Start with short and end with long signals = [-1,0,0,0,0,0,0,0,0,1] # TEST 5 # Test short trade first - no carry position, trade only on signal = False # Short and take profit - then trade last frame long and close position with short (no carry) # NB - NO CARRY will average closing prices which again distorts pnl in monotonic markets like the test sets so closing pnl will be exaggerated here (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive(ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=0.0001, carry_position = False, default_trade_size = 1, max_position=5, fill_function=None, cut_long = -(mean_spread+mean_range)*2, cut_short= -(mean_spread+mean_range)*2, usd_transaction_cost= 0, trade_file='/tmp/testoutshit', take_profit_pct=0.0001) assert(round(sum(pnl), 2) == 0.35) pos_deltas_test = [ -1., 0., 1., 0., 0., 0., 0., 0., 0., -1.] pos_deltas_out = np.equal(position_deltas, pos_deltas_test) assert(pos_deltas_out.all() == True) pos_run_test = [ -1., -1., 0., 0., 0., 0., 0., 0., 0., 0.] pos_run_out = np.equal(position_running, pos_run_test) assert(pos_run_out.all() == True) assert(round(closing_pnl,2) == 0.25) assert(closing_position == 1.)
def short_test1(): # Set up the market bids = np.arange(2, 1, -.10) offers = np.arange(2.1, 1.1, -.10) bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) mean_spread = 0.1 mean_range = 0.0 # Start with short and end with long signals = [-1,0,0,0,0,0,0,0,0,1] # TEST 4 # Test short trade first - no carry position, trade only on signal = True (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive(ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=0.0001, carry_position = False, default_trade_size = 1, max_position=5, fill_function=None, cut_long = -(mean_spread+mean_range)*2, cut_short= -(mean_spread+mean_range)*2, usd_transaction_cost= 0, trade_file='/tmp/testoutshit', take_profit_pct=None) assert(round(sum(pnl), 2) == 0.8) pos_deltas_test = [ -1., 0., 0., 0., 0., 0., 0., 0., 0., 1.] pos_deltas_out = np.equal(position_deltas, pos_deltas_test) assert(pos_deltas_out.all() == True) pos_run_test = [ -1., -1., -1., -1., -1., -1., -1., -1., -1., 0.] pos_run_out = np.equal(position_running, pos_run_test) assert(pos_run_out.all() == True) assert(round(closing_pnl,2) == 0.0) assert(round(closing_position,2) == 0.0)
def long_test3(): # Set up the market bids = np.arange(1, 2, .10) offers = np.arange(1.1, 2.1, .10) bid_vols = 2000000 * np.ones(10) offer_vols = 1000000 * np.ones(10) mean_spread = 0.1 mean_range = 0.0 # Set up signals for single long trade signals = [1,0,0,0,0,0,0,0,0,-1] # TEST 3 # Test for evaluating profit prct - this shoudl never trigger take profit (pnl, position_deltas, position_running, closing_position, closing_pnl, ignored_signals, m2m_pnl) = simulate2.execute_aggressive(ts, bids, offers, bid_vols, offer_vols, signals, currency_pair, signal_window_time=1, min_window_signals=1, min_profit_prct=100, carry_position = False, default_trade_size = 1, max_position=5, fill_function=None, cut_long = -(mean_spread+mean_range)*2, cut_short= -(mean_spread+mean_range)*2, usd_transaction_cost= 0, trade_file='/tmp/testoutshit', take_profit_pct=0.0001) # Profit here is convoluted since the price array is artificial and changes very quickly so when averaging the price to close the position the true price is distorted - i.e. first 4 offers average to 1.30 assert(round(sum(pnl),2) == 0.35) pos_deltas_test = [ 1., 0., -1., 0., 0., 0., 0., 0., 0., 1.] pos_deltas_out = np.equal(position_deltas, pos_deltas_test) assert(pos_deltas_out.all() == True) pos_run_test = [ 1., 1., 0., 0., 0., 0., 0., 0., 0., 0.] pos_run_out = np.equal(position_running, pos_run_test) assert(pos_run_out.all() == True)