Ejemplo n.º 1
0
 def computeClipped(self, train):
     '''
     compute the clipped estimate covariance 
     
     Parameters
     -----
     train: ndarray
         training data
         
     Return
     -----
     empirical estimate covariance
     '''
     clipped = pyRMT.clipped(train, return_covariance=True)
     return clipped * self._standarized_factor
Ejemplo n.º 2
0
 def getClippedCovariance(self):
     return pyRMT.clipped(np.transpose(self.stockReturns),
                          return_covariance=True)
local_df = df[start_date_i: start_portfolio_i]
local_df = local_df.replace(0, np.nan).dropna(axis=1)
columns = list(local_df.columns)
drop = list(set(cryptos) - set(columns))

local_df = returns[start_date_i: start_portfolio_i]
local_df = local_df.iloc[1:]  # remove first row
local_df = local_df.drop(drop, axis=1)
columns = list(local_df.columns)

mu = expected_returns.mean_historical_return(local_df,returns_data=True,frequency=365)
rf = 0.00 #risk free rate - 0.02 (in this case = 0)
mu_excess = mu - rf

Sigma = risk_models.sample_cov(local_df,returns_data=True,frequency=365)
Sigma = rmt.clipped(Sigma,return_covariance=True)
Sigma = pd.DataFrame(data=Sigma,index=columns,columns=columns)

ones = [1] * (len(columns))
arr_ones = np.array(ones)
arr_ones = pd.DataFrame([arr_ones], columns=columns)

Sigma_inv = pd.DataFrame(np.linalg.pinv(Sigma.values), Sigma.columns, Sigma.index)

x = arr_ones.dot(Sigma_inv)
y = x.dot(arr_ones.T)
y = y ** -1
y=y[0]
weights = Sigma_inv.multiply(y[0])
print(weights)
weights = weights.dot(arr_ones.T)
 def __init__(self, _ret, has_mean):
     self._ret = _ret
     if has_mean:
         self._ret -= self._ret.mean(axis=0)
     self._clip_cov = clipped(self._ret, return_covariance=True)