'verify performance where short is bought and covered, and shares trade after cover'

def test_covering_short(self):

    self.create_environment_stuff(num_days=10)
    trades = factory.create_trade_history(self.asset1, [10, 10, 10, 11, 9, 8, 7, 8, 9, 10], [100, 100, 100, 100, 100, 100, 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})
    short_txn = create_txn(self.asset1, trades[1].dt, 10.0, (-100))
    cover_txn = create_txn(self.asset1, trades[6].dt, 7.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(short_txn)
    pp.handle_execution(short_txn)
    pt.execute_transaction(cover_txn)
    pp.handle_execution(cover_txn)
    pt.sync_last_sale_prices(trades[(-1)].dt, False, data_portal)
    pp.calculate_performance()
    short_txn_cost = (short_txn.price * short_txn.amount)
    cover_txn_cost = (cover_txn.price * cover_txn.amount)
    self.assertEqual(pp.cash_flow, (((-1) * short_txn_cost) - cover_txn_cost), 'capital    used    should    be    equal    to    the    net    transaction    costs')
    self.assertEqual(len(pp.positions), 0, 'should    be    zero    positions')
    self.assertEqual(pp.ending_value, 0, 'ending    value    should    be    price    of    last    trade    times    number    of    shares    in    position')
    self.assertEqual(pp.pnl, 300, 'gain    of    1    on    100    shares    should    be    300')
    check_perf_period(pp, gross_leverage=0.0, net_leverage=0.0, long_exposure=0.0, longs_count=0, short_exposure=0.0, shorts_count=0)
    account = pp.as_account()
    check_account(account, settled_cash=1300.0, equity_with_loan=1300.0, total_positions_value=0.0, total_positions_exposure=0.0, regt_equity=1300.0, available_funds=1300.0, excess_liquidity=1300.0, cushion=1.0, leverage=0.0, net_leverage=0.0, net_liquidation=1300.0)
