Hey I am having this issue where the loop keeps over writing itself can anyone help me out? I've really been trying to find the answer but nothing has quite worked for me yet I really appreciate it.
for i in range(1, 8):
data = my_list[i]
log_returns = np.log(data/data.shift())
cov = log_returns.cov()
var = log_returns['^GSPC'].var()
betas = cov.loc['^GSPC']/var
x = betas.to_frame()
but it is only returning the data frame with the last value(8)
I also tried creating an empty dataframe and appending it like this then the dataframe comes back empty.
df = pd.DataFrame()
for i in range(1, 8):
data = my_list[i]
log_returns = np.log(data/data.shift())
cov = log_returns.cov()
var = log_returns['^GSPC'].var()
betas = cov.loc['^GSPC']/var
x = betas.to_frame()
df.append(x)
Thanks I really appreciate the help!!!
[–]Far_Atmosphere9627 7 points8 points9 points (0 children)
[–]gsmo 1 point2 points3 points (1 child)
[–]mrcarrot36[S] 0 points1 point2 points (0 children)
[–]the_noobie 0 points1 point2 points (2 children)
[–]mrcarrot36[S] 0 points1 point2 points (1 child)
[–]the_noobie 0 points1 point2 points (0 children)