예제 #1
0
 def test_market_hours_calculations(self):
     with trading.TradingEnvironment():
         # DST in US/Eastern began on Sunday March 14, 2010
         before = datetime.datetime(2010, 3, 12, 14, 31, tzinfo=pytz.utc)
         after = factory.get_next_trading_dt(before,
                                             datetime.timedelta(days=1))
         self.assertEqual(after.hour, 13)
예제 #2
0
    def test_ending_before_pay_date(self):
        # post some trades in the market
        events = factory.create_trade_history(1, [10, 10, 10, 10, 10],
                                              [100, 100, 100, 100, 100],
                                              oneday, self.sim_params)

        pay_date = self.sim_params.first_open
        # find pay date that is much later.
        for i in xrange(30):
            pay_date = factory.get_next_trading_dt(pay_date, oneday)
        dividend = factory.create_dividend(1, 10.00, events[0].dt,
                                           events[1].dt, pay_date)

        buy_txn = create_txn(events[1], 10.0, 100)
        events.insert(2, buy_txn)
        events.insert(1, dividend)
        results = calculate_results(self, events)

        self.assertEqual(len(results), 5)
        cumulative_returns = \
            [event['cumulative_perf']['returns'] for event in results]
        self.assertEqual(cumulative_returns, [0, 0, 0, 0.0, 0.0])
        daily_returns = [event['daily_perf']['returns'] for event in results]
        self.assertEqual(daily_returns, [0, 0, 0, 0, 0])
        cash_flows = [event['daily_perf']['capital_used'] for event in results]
        self.assertEqual(cash_flows, [0, -1000, 0, 0, 0])
        cumulative_cash_flows = \
            [event['cumulative_perf']['capital_used'] for event in results]
        self.assertEqual(cumulative_cash_flows,
                         [0, -1000, -1000, -1000, -1000])
예제 #3
0
    def test_ending_before_pay_date(self):
        # post some trades in the market
        events = factory.create_trade_history(
            1, [10, 10, 10, 10, 10], [100, 100, 100, 100, 100], oneday, self.sim_params
        )

        pay_date = self.sim_params.first_open
        # find pay date that is much later.
        for i in xrange(30):
            pay_date = factory.get_next_trading_dt(pay_date, oneday)
        dividend = factory.create_dividend(1, 10.00, events[0].dt, events[1].dt, pay_date)

        buy_txn = create_txn(1, 10.0, 100, events[1].dt)
        events.insert(2, buy_txn)
        events.insert(1, dividend)
        results = calculate_results(self, events)

        self.assertEqual(len(results), 5)
        cumulative_returns = [event["cumulative_perf"]["returns"] for event in results]
        self.assertEqual(cumulative_returns, [0, 0, 0, 0.0, 0.0])
        daily_returns = [event["daily_perf"]["returns"] for event in results]
        self.assertEqual(daily_returns, [0, 0, 0, 0, 0])
        cash_flows = [event["daily_perf"]["capital_used"] for event in results]
        self.assertEqual(cash_flows, [0, -1000, 0, 0, 0])
        cumulative_cash_flows = [event["cumulative_perf"]["capital_used"] for event in results]
        self.assertEqual(cumulative_cash_flows, [0, -1000, -1000, -1000, -1000])
예제 #4
0
 def test_market_hours_calculations(self):
     with trading.TradingEnvironment():
         # DST in US/Eastern began on Sunday March 14, 2010
         before = datetime(2010, 3, 12, 14, 31, tzinfo=pytz.utc)
         after = factory.get_next_trading_dt(
             before,
             timedelta(days=1)
         )
         self.assertEqual(after.hour, 13)
예제 #5
0
    def test_ending_before_pay_date(self):
        # post some trades in the market
        events = factory.create_trade_history(
            1,
            [10, 10, 10, 10, 10],
            [100, 100, 100, 100, 100],
            oneday,
            self.sim_params
        )

        pay_date = self.sim_params.first_open
        # find pay date that is much later.
        for i in range(30):
            pay_date = factory.get_next_trading_dt(pay_date, oneday)
        dividend = factory.create_dividend(
            1,
            10.00,
            events[0].dt,
            events[0].dt,
            pay_date
        )

        txns = [create_txn(events[1], 10.0, 100)]

        results = calculate_results(
            self,
            events,
            dividend_events=[dividend],
            txns=txns,
        )

        self.assertEqual(len(results), 5)
        cumulative_returns = \
            [event['cumulative_perf']['returns'] for event in results]
        self.assertEqual(cumulative_returns, [0, 0, 0, 0.0, 0.0])
        daily_returns = [event['daily_perf']['returns'] for event in results]
        self.assertEqual(daily_returns, [0, 0, 0, 0, 0])
        cash_flows = [event['daily_perf']['capital_used'] for event in results]
        self.assertEqual(cash_flows, [0, -1000, 0, 0, 0])
        cumulative_cash_flows = \
            [event['cumulative_perf']['capital_used'] for event in results]
        self.assertEqual(
            cumulative_cash_flows,
            [0, -1000, -1000, -1000, -1000]
        )