请选择 进入手机版 | 继续访问电脑版
楼主: zhangtao
3504 10

[问答] 为什么这个GARCH程序在R3.5.1中运行不了? [推广有奖]

  • 3关注
  • 42粉丝

学科带头人

41%

还不是VIP/贵宾

-

威望
0
论坛币
2302 个
通用积分
882.7566
学术水平
114 点
热心指数
120 点
信用等级
83 点
经验
52012 点
帖子
1553
精华
1
在线时间
2356 小时
注册时间
2005-1-13
最后登录
2024-3-13

zhangtao 发表于 2019-2-2 22:21:41 |显示全部楼层 |坛友微信交流群
相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
为什么这个GARCH程序在R3.5.1中运行不了?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:GARCH ARCH ARC RCH

数学好就是要天天学
zhangtao 发表于 2019-2-2 22:29:05 |显示全部楼层 |坛友微信交流群
011.zip (266.21 KB) 本附件包括:
  • ch1Rscripts.txt
  • ch1data.zip
  • d-axp3dx-0111.txt
  • d-fx-ukus-0711.txt
  • d-fx-usjp-0711.txt
  • d-ibm-0110.txt
  • d-mmm-0111.txt
  • d-vix0411.txt
  • m-ge3dx-4011.txt
  • m-ibmsp-2611.txt
  • ma.R
  • ohlc.R
  • 中日.docx

ch1Rscripts.txt (3.96 KB)
ch1data.zip (128.94 KB) 本附件包括:
  • d-axp3dx-0111.txt
  • d-fx-ukus-0711.txt
  • d-fx-usjp-0711.txt
  • d-ibm-0110.txt
  • d-mmm-0111.txt
  • d-vix0411.txt
  • m-ge3dx-4011.txt
  • m-ibmsp-2611.txt






数学好就是要天天学

使用道具

escaflowne1985 在职认证  发表于 2019-2-2 22:45:50 |显示全部楼层 |坛友微信交流群
对应包需要手动

使用道具

zhangtao 发表于 2019-2-3 08:52:32 |显示全部楼层 |坛友微信交流群
> ### Chapter 1 ###
> library(quantmod)   # Load the package
> getSymbols("AAPL")  # Download daily prices of Apple stock from Yahoo
[1] "AAPL"
> dim(AAPL)  # (dimension): See the size of the downloaded data.
[1] 3042    6
> head(AAPL)  # See the first 6 rows of the data
           AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
2007-01-03  12.32714  12.36857 11.70000   11.97143   309579900      8.016820
2007-01-04  12.00714  12.27857 11.97429   12.23714   211815100      8.194759
2007-01-05  12.25286  12.31428 12.05714   12.15000   208685400      8.136404
2007-01-08  12.28000  12.36143 12.18286   12.21000   199276700      8.176582
2007-01-09  12.35000  13.28286 12.16429   13.22429   837324600      8.855811
2007-01-10  13.53571  13.97143 13.35000   13.85714   738220000      9.279611
> tail(AAPL)   # See the last 6 rows of the data
           AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
2019-01-25    155.48    158.13   154.32     157.76    33535500        157.76
2019-01-28    155.79    156.33   153.66     156.30    26192100        156.30
2019-01-29    156.25    158.13   154.11     154.68    41587200        154.68
2019-01-30    163.25    166.15   160.23     165.25    61109800        165.25
2019-01-31    166.11    169.00   164.56     166.44    40739600        166.44
2019-02-01    166.96    168.98   165.93     166.52    32647100        166.52
> chartSeries(AAPL,theme="white")  # Plot the daily price and volume
> chartSeries(AAPL)#Not shown giving the same plot with black background.
> getSymbols("AAPL",from="2005-01-02", to="2010-12-31")
[1] "AAPL"
> head(AAPL)
           AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
2005-01-03  4.627143  4.650714 4.471428   4.520714   172998000      3.027354
2005-01-04  4.556428  4.676429 4.497857   4.567143   274202600      3.058446
2005-01-05  4.604286  4.660714 4.575000   4.607143   170108400      3.085232
2005-01-06  4.619286  4.636428 4.523571   4.610714   176388800      3.087624
2005-01-07  4.642857  4.973571 4.625000   4.946429   556862600      3.312439
2005-01-10  4.987857  5.050000 4.848571   4.925714   431327400      3.298568
> getSymbols("UNRATE",src="FRED")#Download unemployment rates from FRED.
[1] "UNRATE"
> head(UNRATE)
           UNRATE
1948-01-01    3.4
1948-02-01    3.8
1948-03-01    4.0
1948-04-01    3.9
1948-05-01    3.5
1948-06-01    3.6
> chartSeries(UNRATE,theme="white")  # Plot monthly unemployment rates
> getSymbols("INTC",src="google")  # Download data from Google.
错误: ‘getSymbols.google’ is defunct.
Google Finance stopped providing data in March, 2018.
You could try setting src = "yahoo" instead.
See help("Defunct") and help("quantmod-defunct")
> head(INTC)
Error in head(INTC) : 找不到对象'INTC'
> getSymbols("^TNX") # Download CBOE 10-year Treasures Notes
[1] "TNX"
Warning message:
^TNX contains missing values. Some functions will not work if objects contain missing values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> head(TNX)  
           TNX.Open TNX.High TNX.Low TNX.Close TNX.Volume TNX.Adjusted
2007-01-03    4.658    4.692   4.636     4.664          0        4.664
2007-01-04    4.656    4.662   4.602     4.618          0        4.618
2007-01-05    4.587    4.700   4.583     4.646          0        4.646
2007-01-08    4.668    4.678   4.654     4.660          0        4.660
2007-01-09    4.660    4.670   4.644     4.656          0        4.656
2007-01-10    4.666    4.700   4.660     4.682          0        4.682
> chartSeries(TNX,theme="white",TA=NULL) # Obtain plot without volume.
> #
> setwd("C:/Users/rst/book/introTS/data") # Set my working directory
Error in setwd("C:/Users/rst/book/introTS/data") : 无法改变工作目录
> library(fBasics) # Load package
> da=read.table('d-ibm-0110.txt',header=T) # Load text data with names.
Error in file(file, "rt") : 无法打开链结
此外: Warning message:
In file(file, "rt") :
  无法打开文件'd-ibm-0110.txt': No such file or directory
> head(da) # See the first 6 rows
Error in head(da) : 找不到对象'da'
> dim(da)  # Dimension of the data object "da".
错误: 找不到对象'da'
> da <- read.csv("d-vix0411.csv",header=T) # Load csv data with names.
Error in file(file, "rt") : 无法打开链结
此外: Warning message:
In file(file, "rt") :
  无法打开文件'd-vix0411.csv': No such file or directory
> #
> library(quantmod)
> getSymbols("AAPL",from="2007-01-03",to="2011-12-02") #Specify period
[1] "AAPL"
> AAPL.rtn=diff(log(AAPL$AAPL.Adjusted)) # Compute log returns
> chartSeries(AAPL.rtn,theme="white")
> getSymbols("^TNX",from="2007-01-03",to="2011-12-02")
[1] "TNX"
Warning message:
^TNX contains missing values. Some functions will not work if objects contain missing values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> TNX.rtn=diff(TNX$TNX.Adjusted) # Compute changes
> chartSeries(TNX.rtn,theme="white")
> getSymbols("DEXUSEU",src="FRED") #Obtain exchange rates from FRED
[1] "DEXUSEU"
> head(DEXUSEU)
           DEXUSEU
1999-01-04  1.1812
1999-01-05  1.1760
1999-01-06  1.1636
1999-01-07  1.1672
1999-01-08  1.1554
1999-01-11  1.1534
> tail(DEXUSEU)
           DEXUSEU
2019-01-18  1.1362
2019-01-21      NA
2019-01-22  1.1359
2019-01-23  1.1390
2019-01-24  1.1322
2019-01-25  1.1407
> USEU.rtn=diff(log(DEXUSEU$DEXUSEU))
> chartSeries(DEXUSEU,theme="white")
> chartSeries(USEU.rtn,theme="white")
> #
> library(fBasics) # Load package
> da=read.table("d-mmm-0111.txt",header=T) # Load data
Error in file(file, "rt") : 无法打开链结
此外: Warning message:
In file(file, "rt") :
  无法打开文件'd-mmm-0111.txt': No such file or directory
> # header=T means the first row of data file contains names.
> # deafult is no names.
> head(da) #Show the first 6 rows of data
Error in head(da) : 找不到对象'da'
> mmm=da[,2]  # Obtain 3m simple returns
错误: 找不到对象'da'
> basicStats(mmm) #Compute summary statistics
Error in as.matrix(x) : 找不到对象'mmm'
> mean(mmm)
Error in mean(mmm) : 找不到对象'mmm'
> var(mmm)
Error in is.data.frame(x) : 找不到对象'mmm'
> stdev(mmm) # standard deviation
Error in stdev(mmm) : 找不到对象'mmm'
> t.test(mmm)  # Testing mean return = 0
Error in t.test(mmm) : 找不到对象'mmm'
> s3=skewness(mmm)
Error in skewness(mmm) : 找不到对象'mmm'
> T=length(mmm) # Sample size
错误: 找不到对象'mmm'
> t3=s3/sqrt(6/T) # Skewness test
错误: 找不到对象's3'
> pp=2*(1-pnorm(t3)) # Compute p-value
Error in pnorm(t3) : 找不到对象't3'
> s4=kurtosis(mmm)
Error in kurtosis(mmm) : 找不到对象'mmm'
> t4=s4/sqrt(24/T) # Kurtosis test
错误: 找不到对象's4'
> normalTest(mmm,method='jb') # JB-test
Error in normalTest(mmm, method = "jb") : 找不到对象'mmm'
> #
> library(fBasics)
> da=read.table("d-mmm-0111.txt",header=T) # Load data
Error in file(file, "rt") : 无法打开链结
此外: Warning message:
In file(file, "rt") :
  无法打开文件'd-mmm-0111.txt': No such file or directory
> mmm=da[,2] # Locate 3M simple returns
错误: 找不到对象'da'
> hist(mmm,nclass=30) # Histogram
Error in hist(mmm, nclass = 30) : 找不到对象'mmm'
> d1=density(mmm)  # Obtain density estimate
Error in density(mmm) : 找不到对象'mmm'
> range(mmm)  # Range of 3M returns
错误: 找不到对象'mmm'
> x=seq(-.1,.1,.001) # Create a sequence of x with increment 0.001.
> y1=dnorm(x,mean(mmm),stdev(mmm))
Error in mean(mmm) : 找不到对象'mmm'
> plot(d1$x,d1$y,xlab='rtn',ylab='density',type='l')
Error in plot(d1$x, d1$y, xlab = "rtn", ylab = "density", type = "l") :
  找不到对象'd1'
> lines(x,y1,lty=2)
Error in xy.coords(x, y) : 找不到对象'y1'
> library(quantmod)
> getSymbols("AAPL",from="2011-01-03",to="2011-06-30")
[1] "AAPL"
> X=AAPL[,1:4] # Locate open, high, low, and close prices
> xx=cbind(as.numeric(X[,1]),as.numeric(X[,2]),as.numeric(X[,3]),as.numeric(X[,4]))
> source("ohlc.R") # Compile the R script
Error in file(filename, "r", encoding = encoding) : 无法打开链结
此外: Warning message:
In file(filename, "r", encoding = encoding) :
  无法打开文件'ohlc.R': No such file or directory
> ohlc(xx,xl="days",yl="price",title="Apple Stock")
Error in ohlc(xx, xl = "days", yl = "price", title = "Apple Stock") :
  没有"ohlc"这个函数
> source("ma.R")  # Compile R script
Error in file(filename, "r", encoding = encoding) : 无法打开链结
此外: Warning message:
In file(filename, "r", encoding = encoding) :
  无法打开文件'ma.R': No such file or directory
> getSymbols("AAPL",from="2010-01-02",to="2011-12-08")
[1] "AAPL"
> x1=as.numeric(AAPL$AAPL.Close) # Locate close price
> ma(x1,21)
Error in ma(x1, 21) : 没有"ma"这个函数
> da=read.table("m-ibmsp-2611.txt",header=T)
Error in file(file, "rt") : 无法打开链结
此外: Warning message:
In file(file, "rt") :
  无法打开文件'm-ibmsp-2611.txt': No such file or directory
> head(da)
Error in head(da) : 找不到对象'da'
> ibm=log(da$ibm+1) # Transform to log returns
错误: 找不到对象'da'
> sp=log(da$sp+1)
错误: 找不到对象'da'
> tdx=c(1:nrow(da))/12+1926 # Create time index
Error in nrow(da) : 找不到对象'da'
> par(mfcol=c(2,1))
> plot(tdx,ibm,xlab='year',ylab='lrtn',type='l')
Error in plot(tdx, ibm, xlab = "year", ylab = "lrtn", type = "l") :
  找不到对象'tdx'
> title(main='(a) IBM returns')
> plot(tdx,sp,xlab='year',ylab='lrtn',type='l') # X-axis first.
Error in plot(tdx, sp, xlab = "year", ylab = "lrtn", type = "l") :
  找不到对象'tdx'
> title(main='(b) SP index')
> cor(ibm,sp)  # Obtain sample correlation
Error in is.data.frame(y) : 找不到对象'sp'
> m1=lm(ibm~sp)  # Fit the Market Model (linear model)
Error in eval(predvars, data, env) : 找不到对象'ibm'
> summary(m1)
Error in summary(m1) : 找不到对象'm1'
> plot(sp,ibm,cex=0.8)  # Obtain scatter plot
Error in plot(sp, ibm, cex = 0.8) : 找不到对象'sp'
> abline(0.008,.807) # Add the linear regression line
> #
> da=read.table("m-ibmsp-2611.txt",header=T) #Load  data
Error in file(file, "rt") : 无法打开链结
此外: Warning message:
In file(file, "rt") :
  无法打开文件'm-ibmsp-2611.txt': No such file or directory
> dim(da)
错误: 找不到对象'da'
> ibm=log(da$ibm+1) # Compute log returns
错误: 找不到对象'da'
> sp=log(da$sp+1)
错误: 找不到对象'da'
> rt=cbind(ibm,sp) # Obtain bivariate returns
Error in cbind(ibm, sp) : 找不到对象'ibm'
> m1=apply(rt,2,mean) # Obtain sample means
Error in apply(rt, 2, mean) : dim(X)的值必需是正数
> v1=cov(rt) # Obtain sample covariance matrix
Error in cov(rt) : 要么同时设定'x'和'y',要么只设定矩阵式的'x'
> m1
错误: 找不到对象'm1'
> v1
错误: 找不到对象'v1'
> library(mnormt) # Load package
> x=rmnorm(1029,mean=m1,varcov=v1) # Simulation
Error in chol(varcov) : 找不到对象'v1'
> dim(x)
NULL
> plot(x[,2],x[,1],xlab='sim-sp',ylab='sim-ibm',cex=0.8)
Error in x[, 2] : 量度数目不对
>

使用道具

zhangtao 发表于 2019-2-3 12:43:50 |显示全部楼层 |坛友微信交流群
好人解决一下

使用道具

tulipsliu 在职认证  发表于 2019-6-26 17:13:25 |显示全部楼层 |坛友微信交流群
哇哦,你在用R软件了?epoh 的R 用得很溜啊。不过很久没见他。

使用道具

tulipsliu 在职认证  发表于 2019-8-7 19:16:15 |显示全部楼层 |坛友微信交流群
我下载你的资料运行,可以的。
你没设置工作路径吧?
我现在用 RSTUDIO
点 session
点改变工作目录 切换到你的放这个数据文件的目录
这个时候读取文件 R才能找到数据文件


我运行一点问题都没有;

老朋友路过

使用道具

tulipsliu 在职认证  发表于 2019-8-7 19:42:13 |显示全部楼层 |坛友微信交流群
我看了你改变工作目录,你的代码是从网上下载的吗?
那是别人作者的工作目录 c盘下某某某文件夹
你电脑里都没这个目录,怎么设定和改变目录?
我给你演示下我是怎么设定自己的目录的,我下载了你的资料。然后放在我的 E盘
setwd("E:/Mystudio/ch1data")
ctrl+shift +H 快速设定工作目录

没了 如果不是RSTUDIO
R的菜单也有设定工作目录的
随便把你的数据放在某一个盘某一个文件夹   轻松设定
我刚才设定后命令窗口它自动生成了这个命令 我是菜单设定的

命令等价

使用道具

tulipsliu 在职认证  发表于 2019-9-6 21:45:27 |显示全部楼层 |坛友微信交流群

我又来了;
getSymbols("INTC",src="google")  # Download data from Google.
错误: ‘getSymbols.google’ is defunct.
Google Finance stopped providing data in March, 2018.
You could try setting src = "yahoo" instead.
See help("Defunct") and help("quantmod-defunct")

google 不提供数据,你可以设定 src="yahoo" 替换,基本解决。

是 setwd 的问题吗?


哈哈 我们2011年就认识吧?当年epoh 大神和我们一起讨论很多东西。

不想吹,但是觉得你好不长进。竟然入门级的错误你也可以过去八年了这样玩?


拉黑我吧,我不想关注你,也不想你关注我。

使用道具

Yolanda.x 发表于 2019-9-14 09:32:01 |显示全部楼层 |坛友微信交流群
tulipsliu 发表于 2019-9-6 21:45
我又来了;
getSymbols("INTC",src="google")  # Download data from Google.
错误: ‘get ...
你好,请问在R语言的rugarch包中,如何模拟得到数据生成过程为ARFIMA-GARCH模型的仿真数据啊,arfima参数的阶数是分数阶的,不知道如何设置,请问可以抽空帮我解答么?谢谢

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-3-28 18:22