Exemplo n.º 1
0
 def test_NetGroupExposure_1(self):
     """检验输入"""
     with self.assertRaises(TypeError):
         NetGroupExposure('a', 'b', 'c')
     # with self.assertRaises(AssertionError):
     #     labels = {'AAPL': 'TECH', 'MSFT': 'TECH', 'TSLA': 'CC', 'GM': 'CC'}
     #     # 限定不平衡
     #     min_exposures = {'TECH': -0.5, 'CC': -0.25}
     #     max_exposures = {'TECH': 0.5}
     #     NetGroupExposure(labels, min_exposures, max_exposures)
     with self.assertRaises(Exception):
         labels = {'AAPL': 'TECH', 'MSFT': 'TECH', 'TSLA': 'CC', 'GM': 'CC'}
         min_exposures = {'TECH': -0.5, 'CC': -0.25}
         max_exposures = {'TECH': 0.5, 'CC': -0.5}  # 最大值小于最小值
         ne = NetGroupExposure(labels, min_exposures, max_exposures)
         self.check(ne, 1, 1, 1)
Exemplo n.º 2
0
 def test_NetGroupExposure_4(self):
     """分组双边限制(下限为负,上限为正)"""
     cons_obj = NetGroupExposure(self.labels, self.min_weights,
                                 self.max_weights)
     desired_value = 0.25
     desired_weights = pd.Series(
         [-0.2028, 0.1029, -0.284156, 0.084156, -0.062988, 0.3629, 0.4],
         index=self.stocks)
     self.check(cons_obj, desired_value, desired_weights)
Exemplo n.º 3
0
 def test_NetGroupExposure_3(self):
     """分组净空头单边限制"""
     # 最大值负数
     max_weights = pd.Series([-0.05] * 4, index=self.max_weights.keys())
     cons_obj = NetGroupExposure(self.labels, self.min_weights, max_weights)
     desired_value = 0.08
     desired_weights = pd.Series(
         [-0.2908, 0.1908, -0.3606, 0.1606, -0.2485, 0.1985, -0.05],
         index=self.stocks)
     self.check(cons_obj, desired_value, desired_weights)
Exemplo n.º 4
0
 def test_NetGroupExposure_2(self):
     """分组净多头单边限制"""
     min_weights = pd.Series([0.0, 0.1, 0.2, 0.3],
                             index=self.min_weights.keys())
     cons_obj = NetGroupExposure(self.labels, min_weights, self.max_weights)
     desired_value = 0.21
     # 精度累死
     desired_weights = pd.Series(
         [-0.1612, 0.1612, -0.1207, 0.2207, -0.068, 0.368, 0.400],
         index=self.stocks)
     self.check(cons_obj, desired_value, desired_weights)
Exemplo n.º 5
0
    def test_NetGroupExposure_5(self):
        """取消单组最大或最小限制"""
        min_weights = pd.Series([-0.3, 0.1, 0., 0.3],
                                index=self.min_weights.keys())
        max_weights = pd.Series([0.35] * 4, index=self.max_weights.keys())
        # 取消A组最小限制
        min_weights.loc['A'] = NotConstrained  # 可多分配空头
        # 取消C组最大限制
        max_weights.loc['C'] = NotConstrained

        cons_obj = NetGroupExposure(self.labels, min_weights, max_weights)
        desired_value = 0.41
        desired_weights = pd.Series([-1, -0.000197, -0., 0.1, 0, 0.0498, 0.35],
                                    index=self.stocks)
        self.check(cons_obj, desired_value, desired_weights)