'verify that the performance period calculates properly for a
single buy transaction'

def test_long_position(self):

    self.create_environment_stuff()
    trades = factory.create_trade_history(self.asset1, [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})
    txn = create_txn(self.asset1, trades[1].dt, 10.0, 100)
    pt = perf.PositionTracker(self.sim_params.data_frequency)
    pp = perf.PerformancePeriod(1000.0, self.sim_params.data_frequency, period_open=self.sim_params.start_session, period_close=self.sim_params.end_session)
    pp.position_tracker = pt
    pt.execute_transaction(txn)
    pp.handle_execution(txn)
    self.assertEqual(pp.positions[1].last_sale_price, 10.0)
    pt.sync_last_sale_prices(trades[(-1)].dt, False, data_portal)
    pp.calculate_performance()
    self.assertEqual(pp.cash_flow, (((-1) * txn.price) * txn.amount), 'capital    used    should    be    equal    to    the    opposite    of    the    transaction                                                    cost    of    sole    txn    in    test')
    self.assertEqual(len(pp.positions), 1, 'should    be    just    one    position')
    self.assertEqual(pp.positions[1].asset, txn.asset, 'position    should    be    in    security    with    id    1')
    self.assertEqual(pp.positions[1].amount, txn.amount, 'should    have    a    position    of    {sharecount}    shares'.format(sharecount=txn.amount))
    self.assertEqual(pp.positions[1].cost_basis, txn.price, 'should    have    a    cost    basis    of    10')
    self.assertEqual(pp.positions[1].last_sale_price, trades[(-1)].price, 'last    sale    should    be    same    as    last    trade.                                                    expected    {exp}    actual    {act}'.format(exp=trades[(-1)].price, act=pp.positions[1].last_sale_price))
    self.assertEqual(pp.ending_value, 1100, 'ending    value    should    be    price    of    last    trade    times    number    of                                                    shares    in    position')
    self.assertEqual(pp.pnl, 100, 'gain    of    1    on    100    shares    should    be    100')
    check_perf_period(pp, gross_leverage=1.0, net_leverage=1.0, long_exposure=1100.0, longs_count=1, short_exposure=0.0, shorts_count=0)
    account = pp.as_account()
    check_account(account, settled_cash=0.0, equity_with_loan=1100.0, total_positions_value=1100.0, total_positions_exposure=1100.0, regt_equity=0.0, available_funds=0.0, excess_liquidity=0.0, cushion=0.0, leverage=1.0, net_leverage=1.0, net_liquidation=1100.0)
