'start with $1000
buy 100 stock1 shares at $10
sell short 100 stock2 shares at $10
stock1 then goes down to $9
stock2 goes to $11'

def test_long_short_positions(self):

    self.create_environment_stuff()
    trades_1 = factory.create_trade_history(self.asset1, [10, 10, 10, 9], [100, 100, 100, 100], oneday, self.sim_params, trading_calendar=self.trading_calendar)
    trades_2 = factory.create_trade_history(self.asset2, [10, 10, 10, 11], [100, 100, 100, 100], oneday, self.sim_params, trading_calendar=self.trading_calendar)
    data_portal = create_data_portal_from_trade_history(self.env.asset_finder, self.trading_calendar, self.instance_tmpdir, self.sim_params, {1: trades_1, 2: trades_2})
    txn1 = create_txn(self.asset1, trades_1[0].dt, 10.0, 100)
    txn2 = create_txn(self.asset2, trades_1[0].dt, 10.0, (-100))
    pt = perf.PositionTracker(self.sim_params.data_frequency)
    pp = perf.PerformancePeriod(1000.0, self.sim_params.data_frequency)
    pp.position_tracker = pt
    pt.execute_transaction(txn1)
    pp.handle_execution(txn1)
    pt.execute_transaction(txn2)
    pp.handle_execution(txn2)
    dt = trades_1[(-2)].dt
    pt.sync_last_sale_prices(dt, False, data_portal)
    pp.calculate_performance()
    check_perf_period(pp, gross_leverage=2.0, net_leverage=0.0, long_exposure=1000.0, longs_count=1, short_exposure=(-1000.0), shorts_count=1)
    account = pp.as_account()
    check_account(account, settled_cash=1000.0, equity_with_loan=1000.0, total_positions_value=0.0, total_positions_exposure=0.0, regt_equity=1000.0, available_funds=1000.0, excess_liquidity=1000.0, cushion=1.0, leverage=2.0, net_leverage=0.0, net_liquidation=1000.0)
    dt = trades_1[(-1)].dt
    pt.sync_last_sale_prices(dt, False, data_portal)
    pp.calculate_performance()
    account = pp.as_account()
    check_perf_period(pp, gross_leverage=2.5, net_leverage=(-0.25), long_exposure=900.0, longs_count=1, short_exposure=(-1100.0), shorts_count=1)
    check_account(account, settled_cash=1000.0, equity_with_loan=800.0, total_positions_value=(-200.0), total_positions_exposure=(-200.0), regt_equity=1000.0, available_funds=1000.0, excess_liquidity=1000.0, cushion=1.25, leverage=2.5, net_leverage=(-0.25), net_liquidation=800.0)
