'Purchase/sell multiple lots of AMZN, GOOG
at various prices/commissions to ensure
the arithmetic in calculating equity, drawdowns
and sharpe ratio is correct.'

def test_calculating_statistics(self):

    price_handler = PriceHandlerMock()
    self.portfolio = Portfolio(price_handler, PriceParser.parse(500000.0))
    portfolio_handler = PortfolioHandlerMock(self.portfolio)
    statistics = SimpleStatistics(self.config, portfolio_handler)
    self.assertEqual(PriceParser.display(statistics.equity[0]), 500000.0)
    self.assertEqual(PriceParser.display(statistics.drawdowns[0]), 0)
    self.assertEqual(statistics.equity_returns[0], 0.0)
    self.portfolio.transact_position('BOT', 'AMZN', 100, PriceParser.parse(566.56), PriceParser.parse(1.0))
    t = '2000-01-01    00:00:00'
    statistics.update(t, portfolio_handler)
    self.assertEqual(PriceParser.display(statistics.equity[1]), 499807.0)
    self.assertEqual(PriceParser.display(statistics.drawdowns[1]), 193.0)
    self.assertEqual(statistics.equity_returns[1], (-0.0386))
    self.portfolio.transact_position('BOT', 'AMZN', 200, PriceParser.parse(566.395), PriceParser.parse(1.0))
    t = '2000-01-02    00:00:00'
    statistics.update(t, portfolio_handler)
    self.assertEqual(PriceParser.display(statistics.equity[2]), 499455.0)
    self.assertEqual(PriceParser.display(statistics.drawdowns[2]), 545.0)
    self.assertEqual(statistics.equity_returns[2], (-0.0705))
    self.portfolio.transact_position('BOT', 'GOOG', 200, PriceParser.parse(707.5), PriceParser.parse(1.0))
    t = '2000-01-03    00:00:00'
    statistics.update(t, portfolio_handler)
    self.assertEqual(PriceParser.display(statistics.equity[3]), 499046.0)
    self.assertEqual(PriceParser.display(statistics.drawdowns[3]), 954.0)
    self.assertEqual(statistics.equity_returns[3], (-0.082))
    self.portfolio.transact_position('SLD', 'AMZN', 100, PriceParser.parse(565.83), PriceParser.parse(1.0))
    t = '2000-01-04    00:00:00'
    statistics.update(t, portfolio_handler)
    self.assertEqual(PriceParser.display(statistics.equity[4]), 499164.0)
    self.assertEqual(PriceParser.display(statistics.drawdowns[4]), 836.0)
    self.assertEqual(statistics.equity_returns[4], 0.0236)
    self.portfolio.transact_position('BOT', 'GOOG', 200, PriceParser.parse(705.545), PriceParser.parse(1.0))
    t = '2000-01-05    00:00:00'
    statistics.update(t, portfolio_handler)
    self.assertEqual(PriceParser.display(statistics.equity[5]), 499146.0)
    self.assertEqual(PriceParser.display(statistics.drawdowns[5]), 854.0)
    self.assertEqual(statistics.equity_returns[5], (-0.0036))
    self.portfolio.transact_position('SLD', 'AMZN', 200, PriceParser.parse(565.59), PriceParser.parse(1.0))
    t = '2000-01-06    00:00:00'
    statistics.update(t, portfolio_handler)
    self.assertEqual(PriceParser.display(statistics.equity[6]), 499335.0)
    self.assertEqual(PriceParser.display(statistics.drawdowns[6]), 665.0)
    self.assertEqual(statistics.equity_returns[6], 0.0379)
    self.portfolio.transact_position('SLD', 'GOOG', 100, PriceParser.parse(707.92), PriceParser.parse(1.0))
    t = '2000-01-07    00:00:00'
    statistics.update(t, portfolio_handler)
    self.assertEqual(PriceParser.display(statistics.equity[7]), 499580.0)
    self.assertEqual(PriceParser.display(statistics.drawdowns[7]), 420.0)
    self.assertEqual(statistics.equity_returns[7], 0.049)
    self.portfolio.transact_position('SLD', 'GOOG', 100, PriceParser.parse(707.9), PriceParser.parse(0.0))
    t = '2000-01-08    00:00:00'
    statistics.update(t, portfolio_handler)
    self.assertEqual(PriceParser.display(statistics.equity[8]), 499824.0)
    self.assertEqual(PriceParser.display(statistics.drawdowns[8]), 176.0)
    self.assertEqual(statistics.equity_returns[8], 0.0488)
    self.portfolio.transact_position('SLD', 'GOOG', 100, PriceParser.parse(707.92), PriceParser.parse(0.5))
    t = '2000-01-09    00:00:00'
    statistics.update(t, portfolio_handler)
    self.assertEqual(PriceParser.display(statistics.equity[9]), 500069.5)
    self.assertEqual(PriceParser.display(statistics.drawdowns[9]), 0.0)
    self.assertEqual(statistics.equity_returns[9], 0.0491)
    self.portfolio.transact_position('SLD', 'GOOG', 100, PriceParser.parse(707.78), PriceParser.parse(1.0))
    t = '2000-01-10    00:00:00'
    statistics.update(t, portfolio_handler)
    self.assertEqual(PriceParser.display(statistics.equity[10]), 500300.5)
    self.assertEqual(PriceParser.display(statistics.drawdowns[10]), 0.0)
    self.assertEqual(statistics.equity_returns[10], 0.0462)
    results = statistics.get_results()
    self.assertEqual(results['max_drawdown'], 954.0)
    self.assertEqual(results['max_drawdown_pct'], 0.1908)
    self.assertAlmostEqual(float(results['sharpe']), 1.7575)
