Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _common_results(self, beta, cov, method, iter_count, nobs, cov_type,
sigma, individual, debiased):
results = AttrDict()
results['method'] = method
results['iter'] = iter_count
results['nobs'] = nobs
results['cov_type'] = cov_type
results['index'] = self._dependent[0].rows
results['original_index'] = self._original_index
results['sigma'] = sigma
results['individual'] = individual
results['params'] = beta
results['df_model'] = beta.shape[0]
results['param_names'] = self._param_names
results['cov'] = cov
results['debiased'] = debiased
total_ss = resid_ss = 0.0
resid = []
def __init__(self, x, eps, sigma, full_sigma, *, gls=False, debiased=False, constraints=None):
self._eps = eps
self._x = x
self._nobs = eps.shape[0]
self._k = len(x)
self._sigma = sigma
self._full_sigma = full_sigma
self._gls = gls
self._debiased = debiased
self._constraints = constraints
self._name = 'Homoskedastic (Unadjusted) Covariance'
self._str_extra = AttrDict(Debiased=self._debiased, GLS=self._gls)
self._cov_config = AttrDict(debiased=self._debiased)
def __init__(self, center=False, debiased=False):
self._center = center
self._debiased = debiased
self._bandwidth = 0
self._name = 'Homoskedastic (Unadjusted) Weighting'
self._config = AttrDict(center=center, debiased=debiased)
def _postestimation(self, params, cov, debiased, df_resid, weps, y, x, root_w):
"""Common post-estimation values"""
deferred_f = self._f_statistic_robust(params, cov, debiased, df_resid)
f_stat = self._f_statistic(weps, y, x, root_w, df_resid)
r2o, r2w, r2b = self._rsquared(params)
f_pooled = InapplicableTestStatistic(reason='Model has no effects',
name='Pooled F-stat')
entity_info, time_info, other_info = self._info()
nobs = weps.shape[0]
sigma2 = float(weps.T @ weps / nobs)
loglik = -0.5 * nobs * (np.log(2 * np.pi) + np.log(sigma2) + 1)
res = AttrDict(params=params, deferred_cov=cov.deferred_cov,
deferred_f=deferred_f, f_stat=f_stat,
debiased=debiased, name=self._name, var_names=self.exog.vars,
r2w=r2w, r2b=r2b, r2=r2w, r2o=r2o, s2=cov.s2,
model=self, cov_type=cov.name, index=self.dependent.index,
entity_info=entity_info, time_info=time_info, other_info=other_info,
f_pooled=f_pooled, loglik=loglik, not_null=self._not_null,
original_index=self._original_index)
return res
def _common_indiv_results(self, index, beta, cov, wresid, resid, method,
cov_type, cov_est, iter_count, debiased, constant, total_ss,
*, weight_est=None):
loc = 0
for i in range(index):
loc += self._wx[i].shape[1]
i = index
stats = AttrDict()
# Static properties
stats['eq_label'] = self._eq_labels[i]
stats['dependent'] = self._dependent[i].cols[0]
stats['instruments'] = self._instr[i].cols if self._instr[i].shape[1] > 0 else None
stats['endog'] = self._endog[i].cols if self._endog[i].shape[1] > 0 else None
stats['method'] = method
stats['cov_type'] = cov_type
stats['cov_estimator'] = cov_est
stats['cov_config'] = cov_est.cov_config
stats['weight_estimator'] = weight_est
stats['index'] = self._dependent[i].rows
stats['original_index'] = self._original_index
stats['iter'] = iter_count
stats['debiased'] = debiased
stats['has_constant'] = bool(constant)
stats['constant_loc'] = self._constant_loc[i]
def config(self):
"""
Weight estimator configuration
Returns
-------
config : AttrDict
Dictionary containing weight estimator configuration information
"""
out = AttrDict([(k, v) for k, v in self._config.items()])
out['bandwidth'] = self.bandwidth
return out
if not excess_returns:
param_names.append('lambda-risk_free')
for factor in self.factors.cols:
param_names.append('lambda-{0}'.format(factor))
# Pivot vcv to remove unnecessary and have correct order
order = np.reshape(np.arange(s1), (nport, nf + 1))
order[:, 0] = np.arange(s2, s3)
order = order.ravel()
order = np.r_[order, s1:s2]
full_vcv = full_vcv[order][:, order]
factor_names = list(self.factors.cols)
rp_names = factor_names[:]
if not excess_returns:
rp_names.insert(0, 'risk_free')
res = AttrDict(params=params, cov=full_vcv, betas=betas, rp=rp, rp_cov=rp_cov,
alphas=alphas, alpha_vcv=alpha_vcv, jstat=jstat,
rsquared=r2, total_ss=total_ss, residual_ss=residual_ss,
param_names=param_names, portfolio_names=self.portfolios.cols,
factor_names=factor_names, name=self._name,
cov_type=cov_type, model=self, nobs=nobs, rp_names=rp_names,
cov_est=cov_est)
return LinearFactorModelResults(res)