Пример #1
0
    def init_param_spatial(self, restriction='shomo', groups=None,
                           use_target=False, method='SLSQP', cfree=False,
                           use_penalty=False):
        """Estimate scalar BEKK with variance targeting.

        Parameters
        ----------
        restriction : str
            Restriction on parameters.

            Must be
                - 'hetero' (heterogeneous)
                - 'ghomo' (group homogeneous)
                - 'h**o' (homogeneous)
                - 'shomo' (scalar homogeneous)

        cfree : bool
            Whether to leave C matrix free (True) or not (False)
        groups : list of lists of tuples
            Encoded groups of items
        method : str
            Optimization method. See scipy.optimize.minimize

        Returns
        -------
        ParamSpatial instance
            Parameter object

        """
        param = ParamSpatial.from_groups(groups=groups,
                                         target=estimate_uvar(self.innov),
                                         abstart=(.2, .7))

        if restriction == 'shomo':
            return param

        kwargs = {'use_target': False, 'groups': groups,
                  'use_target': use_target,
                  'use_penalty': use_penalty, 'model': 'spatial',
                  'cfree': cfree, 'method': method}
        est_partial = partial(self.estimate, **kwargs)

        if restriction in ('h**o', 'ghomo', 'hetero'):
            result = est_partial(param_start=param, restriction='shomo')
            param = result.param_final

        if restriction in ('ghomo', 'hetero'):
            result = est_partial(param_start=param, restriction='h**o')
            param = result.param_final

        if restriction in ('hetero'):
            result = est_partial(param_start=param, restriction='ghomo')
            param = result.param_final

        return param
Пример #2
0
    def estimate_loop(self,
                      model='standard',
                      use_target=True,
                      groups=None,
                      restriction='scalar',
                      cfree=False,
                      method='SLSQP',
                      ngrid=2,
                      use_penalty=False):
        """Estimate parameters starting from a grid of a and b.

        Parameters
        ----------
        model : str
            Specific model to estimate.

            Must be
                - 'standard'
                - 'spatial'

        restriction : str
            Restriction on parameters.

            Must be
                - 'full' =  'diagonal'
                - 'group'
                - 'scalar'

        groups : list of lists of tuples
            Encoded groups of items
        use_target : bool
            Whether to use variance targeting (True) or not (False)
        cfree : bool
            Whether to leave C matrix free (True) or not (False)
        method : str
            Optimization method. See scipy.optimize.minimize
        ngrid : int
            Number of starting values in one dimension
        use_penalty : bool
            Whether to include penalty term in the likelihood

        Returns
        -------
        BEKKResults instance
            Estimation results object

        """
        target = estimate_uvar(self.innov)
        nstocks = self.innov.shape[1]
        achoice = np.linspace(.01, .5, ngrid)
        bchoice = np.linspace(.1, .9, ngrid)
        out = dict()
        for abstart in itertools.product(achoice, bchoice):
            if model == 'spatial':
                param = ParamSpatial.from_groups(groups=groups,
                                                 target=target,
                                                 abstart=abstart)
            if model == 'standard':
                param = ParamStandard(nstocks=nstocks,
                                      target=target,
                                      abstart=abstart)
            if param.constraint() >= 1:
                continue
            result = self.estimate(param_start=param,
                                   method=method,
                                   use_target=use_target,
                                   cfree=cfree,
                                   model=model,
                                   restriction=restriction,
                                   groups=groups,
                                   use_penalty=use_penalty)
            out[abstart] = (result.opt_out.fun, result)

        df = pd.DataFrame.from_dict(out, orient='index')
        return df.sort_values(by=0).iloc[0, 1]
Пример #3
0
    def init_param_spatial(self,
                           restriction='shomo',
                           groups=None,
                           use_target=False,
                           method='SLSQP',
                           cfree=False,
                           use_penalty=False):
        """Estimate scalar BEKK with variance targeting.

        Parameters
        ----------
        restriction : str
            Restriction on parameters.

            Must be
                - 'hetero' (heterogeneous)
                - 'ghomo' (group homogeneous)
                - 'h**o' (homogeneous)
                - 'shomo' (scalar homogeneous)

        cfree : bool
            Whether to leave C matrix free (True) or not (False)
        groups : list of lists of tuples
            Encoded groups of items
        method : str
            Optimization method. See scipy.optimize.minimize

        Returns
        -------
        ParamSpatial instance
            Parameter object

        """
        param = ParamSpatial.from_groups(groups=groups,
                                         target=estimate_uvar(self.innov),
                                         abstart=(.2, .7))

        if restriction == 'shomo':
            return param

        kwargs = {
            'use_target': False,
            'groups': groups,
            'use_target': use_target,
            'use_penalty': use_penalty,
            'model': 'spatial',
            'cfree': cfree,
            'method': method
        }
        est_partial = partial(self.estimate, **kwargs)

        if restriction in ('h**o', 'ghomo', 'hetero'):
            result = est_partial(param_start=param, restriction='shomo')
            param = result.param_final

        if restriction in ('ghomo', 'hetero'):
            result = est_partial(param_start=param, restriction='h**o')
            param = result.param_final

        if restriction in ('hetero'):
            result = est_partial(param_start=param, restriction='ghomo')
            param = result.param_final

        return param
Пример #4
0
    def estimate_loop(self, model='standard', use_target=True, groups=None,
                      restriction='scalar', cfree=False,
                      method='SLSQP', ngrid=2, use_penalty=False):
        """Estimate parameters starting from a grid of a and b.

        Parameters
        ----------
        model : str
            Specific model to estimate.

            Must be
                - 'standard'
                - 'spatial'

        restriction : str
            Restriction on parameters.

            Must be
                - 'full' =  'diagonal'
                - 'group'
                - 'scalar'

        groups : list of lists of tuples
            Encoded groups of items
        use_target : bool
            Whether to use variance targeting (True) or not (False)
        cfree : bool
            Whether to leave C matrix free (True) or not (False)
        method : str
            Optimization method. See scipy.optimize.minimize
        ngrid : int
            Number of starting values in one dimension
        use_penalty : bool
            Whether to include penalty term in the likelihood

        Returns
        -------
        BEKKResults instance
            Estimation results object

        """
        target = estimate_uvar(self.innov)
        nstocks = self.innov.shape[1]
        achoice = np.linspace(.01, .5, ngrid)
        bchoice = np.linspace(.1, .9, ngrid)
        out = dict()
        for abstart in itertools.product(achoice, bchoice):
            if model == 'spatial':
                param = ParamSpatial.from_groups(groups=groups,
                                                 target=target,
                                                 abstart=abstart)
            if model == 'standard':
                param = ParamStandard(nstocks=nstocks, target=target,
                                      abstart=abstart)
            if param.constraint() >= 1:
                continue
            result = self.estimate(param_start=param, method=method,
                                   use_target=use_target, cfree=cfree,
                                   model=model, restriction=restriction,
                                   groups=groups, use_penalty=use_penalty)
            out[abstart] = (result.opt_out.fun, result)

        df = pd.DataFrame.from_dict(out, orient='index')
        return df.sort_values(by=0).iloc[0, 1]