将下列r代码改成python代码: resid <- list() for (i in 1:ncol(returns)) { resid[[i]] <- residuals(garchFit(~garch(1,1), data=as.numeric(returns[,i]), trace=FALSE, cond.dist="sstd"), standardize=TRUE) }
时间: 2024-03-12 22:45:01 浏览: 126
线性回归-R:Stat 308 2020年SpringR代码
下面是将R代码改写成Python代码的示例:
```python
import pandas as pd
from arch import arch_model
returns = pd.read_csv("path/to/returns.csv")
resid = []
for i in range(returns.shape[1]):
garch = arch_model(returns.iloc[:, i], mean="Zero", vol="GARCH", p=1, q=1, dist="Normal")
res = garch.fit(disp="off").resid
resid.append(res)
print(resid)
```
注意,上述代码需要安装 arch 包。
阅读全文