Kernel stuck in "Busy" after cell execution

Asked

Viewed 13 times

0

I’m trying to run the following cell of a Jupyter Notebook:

for cada_carteira in range(numero_carteiras):
peso = np.random.random(numero_acoes)
peso /= np.sum(peso)
retorno = np.dot(peso, retorno_med)
volatilidade = np.sqrt(np.dot(peso.T, np.dot(cov_diaria, peso)))
sharpe = retorno / volatilidade
utilidade = retorno - 0.5*A*volatilidade**2
sharpe_ratio.append(sharpe)
retorno_carteira.append(retorno)
volatilidade_carteira.append(volatilidade)
peso_acoes.append(peso)
utilidade_mark.append(utilidade)

The execution is successful and the cell is given as "finished" (not in infinite loop), but the Kernel of my Notebook gets stuck in the "Busy" state after the execution of this cell. This causes me to have to interrupt my Kernel (Esc+i+i) to be able to run the next cell.

I was able to identify that the problem occurs when I append a Numpy Array to a list on the line peso_acoes.append(peso), but I can’t fix it. I’ve tried peso_acoes.append(peso.copy()) and peso_acoes.append(list(peso)) and did not succeed.

The preceding cells follow as below:

acoes = ['ALPA4.SA', 'BRAP4.SA', 'JBSS3.SA']
dados = pd.DataFrame()
for a in acoes:
    dados[a]=web.DataReader(a, data_source = 'yahoo', start = '2021-08-01')['Adj Close']

# calculo dos retornos diários e anuais
retorno_diario = dados.pct_change()
retorno_med = retorno_diario.mean()
desv_pad = retorno_diario.std()

# cálculo da covariância diária e anual
cov_diaria = retorno_diario.cov()

# vamos criar 4 listas para armazenar os valores do retorno da carteira, o peso de cada ação, a volatilidade e o sharpe ratio
# empty lists to store returns, volatility and weights of imiginary portfolios
retorno_carteira = []
peso_acoes = []
volatilidade_carteira = []
sharpe_ratio = []
utilidade_mark = []

# vamos usar uma simulação aleatória
numero_acoes = len(acoes)
numero_carteiras = 1000

np.random.seed(101)

A = 3

What can I do to normalize the kernel?

  • I have given up my nbextensions and your settings and the code is back to normal. I don’t know what extent caused the problem and I don’t even know how this problem arises, but I managed to solve it.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.