예제 #1
0
    def test_daily_txns_with_bar_data(self):
        daily_txn = daily_txns_with_bar_data(
            self.transactions, self.market_data)
        expected = DataFrame(data=[['A', 100000, 1.0, 1000000.],
                                   ['A', 100000, 1.0, 2000000.],
                                   ['A', 100000, 1.0, 3000000.]],
                             columns=['symbol', 'amount', 'price', 'volume'],
                             index=self.dates)

        assert_frame_equal(daily_txn, expected, check_less_precise=True)
예제 #2
0
    def test_daily_txns_with_bar_data(self):
        daily_txn = daily_txns_with_bar_data(
            self.transactions, self.market_data)
        expected = DataFrame(data=[['A', 100000, 1.0, 1000000.],
                                   ['A', 100000, 1.0, 2000000.],
                                   ['A', 100000, 1.0, 3000000.]],
                             columns=['symbol', 'amount', 'price', 'volume'],
                             index=self.dates)

        assert_frame_equal(daily_txn, expected, check_less_precise=True)
예제 #3
0
    def test_apply_slippage_penalty(self, starting_base, impact,
                                    expected_adj_returns):
        returns = Series([1., 1., 1.], index=self.dates)
        daily_txn = daily_txns_with_bar_data(
            self.transactions, self.market_data)

        adj_returns = apply_slippage_penalty(
            returns, daily_txn, starting_base, 1000000, impact=impact)
        expected_adj_returns = Series(expected_adj_returns, index=self.dates)

        assert_series_equal(adj_returns, expected_adj_returns)
예제 #4
0
    def test_apply_slippage_penalty(self, starting_base, impact,
                                    expected_adj_returns):
        returns = Series([1., 1., 1.], index=self.dates)
        daily_txn = daily_txns_with_bar_data(
            self.transactions, self.market_data)

        adj_returns = apply_slippage_penalty(
            returns, daily_txn, starting_base, 1000000, impact=impact)
        expected_adj_returns = Series(expected_adj_returns, index=self.dates)

        assert_series_equal(adj_returns, expected_adj_returns)
예제 #5
0
    def capacity_sweep(self,
                       returns,
                       transactions,
                       market_data,
                       bt_starting_capital,
                       min_pv=100000,
                       max_pv=300000000,
                       step_size=1000000):
        """
        考虑资金量(每百万元)带来市场冲击后的修正夏普率

        Parameters
        ----------
        returns : pd.Series
            Timeseries of portfolio returns to be adjusted for various
            degrees of slippage.
        transactions : pd.DataFrame
            Prices and amounts of executed trades. One row per trade.
             - See full explanation in tears.create_full_tear_sheet.
        market_data : pd.Panel, optional
            Panel with items axis of 'price' and 'volume' DataFrames.
            The major and minor axes should match those of the
            the passed positions DataFrame (same dates and symbols).
        min_pv:int
            最小入场资金
        max_pv:int
            最大入场资金
        step_size:int
            步长

        Returns
        -------
        考虑资金量(每百万元)带来市场冲击后的修正夏普率(adj_sharpe)
        资金量为index,单位为百万元
        """
        txn_daily_w_bar = capacity.daily_txns_with_bar_data(
            transactions, market_data)

        captial_base_sweep = pd.Series()
        for start_pv in range(min_pv, max_pv, step_size):
            adj_ret = capacity.apply_slippage_penalty(returns, txn_daily_w_bar,
                                                      start_pv,
                                                      bt_starting_capital)
            sharpe = empyrical.sharpe_ratio(adj_ret)
            if sharpe < -1:
                break
            captial_base_sweep.loc[start_pv] = sharpe
        captial_base_sweep.index = captial_base_sweep.index / MM_DISPLAY_UNIT
        return captial_base_sweep
예제 #6
0
    def test_daily_txns_with_bar_data(self):
        daily_txn = daily_txns_with_bar_data(self.transactions,
                                             self.market_data)

        columns = ["symbol", "amount", "price", "volume"]
        expected = pd.DataFrame(
            data=[
                ["A", 100000, 1.0, 1000000.0],
                ["A", 100000, 1.0, 2000000.0],
                ["A", 100000, 1.0, 3000000.0],
            ],
            columns=columns,
            index=self.dates,
        )

        assert_frame_equal(daily_txn, expected)