全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 MATLAB等数学软件专版
2011-7-25 11:53:45
88# epoh


# MNZModel.ssc                        Morley, Nelson and Zivot's UC model
#
# Created: January 8, 2005

##
## MNZ model: Ref. Morley, Nelson and Zivot (2002), "Why are
## Beveridge-Nelson and Unobserved Components Decompositions of GDP
## so Different?", forthcoming in Review of Economics and Statistics
##

## Note: parameters are taken from Table 4 of
## Morley, Nelson and Zivot (2002)
##
delta = 0.8156
phi1 = 1.3419
phi2 = -0.7060
sigma.v = 1.2368
sigma.w = 0.7485
sigma.vw = -0.8389
bigV = matrix(c(sigma.v^2,sigma.vw,sigma.vw,sigma.w^2),2,2)
Omega = matrix(0,4,4)
Omega[1:2,1:2] = bigV
a1 = matrix(0,3,1)
# solve for initial variance of stationary part
bigF = matrix(c(phi1,1,phi2,0),2,2)
vecV = c(sigma.w^2,0,0,0)
vecP = solve(diag(4)-kronecker(bigF,bigF))%*%vecV
P.ar2 = matrix(vecP,2,2)
Sigma = matrix(0,4,3)
Sigma[1,1] = -1
Sigma[2:3,2:3] = P.ar2
ssf.mnz= list(mDelta=c(delta,0,0,0),
mPhi=rbind(c(1,0,0),c(0,phi1,phi2),c(0,1,0),c(1,1,0)),
mOmega=Omega,
mSigma = Sigma)
ssf.mnz

## simulate from model
##
set.seed(569)
mnz.sim = SsfSim(ssf.mnz,n=250)
par(mfrow=c(2,1))
tsplot(mnz.sim[,c(1,4)],main="Simulated response and trend")
tsplot(mnz.sim[,2],main="Simulated cycle")

## estimate model using US postwar quarterly real GDP
##
MNZ.mod = function(parm) {
        delta = parm[1]
        phi1 = parm[2]
        phi2 = parm[3]
        sigma.v = exp(parm[4])
        sigma.w = exp(parm[5])
        rho.vw = parm[6]
        sigma.vw = sigma.v*sigma.w*rho.vw
        bigV = matrix(c(sigma.v^2,sigma.vw,sigma.vw,sigma.w^2),2,2)
        Omega = matrix(0,4,4)
        Omega[1:2,1:2] = bigV
        a1 = matrix(0,3,1)
# solve for initial variance of stationary part
        bigF = matrix(c(phi1,1,phi2,0),2,2)
        vecV = c(sigma.w^2,0,0,0)
        vecP = solve(diag(4)-kronecker(bigF,bigF))%*%vecV
        P.ar2 = matrix(vecP,2,2)
        Sigma = matrix(0,4,3)
        Sigma[1,1] = -1
        Sigma[2:3,2:3] = P.ar2
        ssf.mod= list(mDelta=c(delta,0,0,0),
        mPhi=rbind(c(1,0,0),c(0,phi1,phi2),c(0,1,0),c(1,1,0)),
        mOmega=Omega,
        mSigma = Sigma)
        CheckSsf(ssf.mod)
}

## set starting values
##
MNZ.start=c(0.81,1.34,-0.70,0.21,-0.30,-0.9)
names(MNZ.start) = c("delta","phi.1","phi.2",
"ln.sigma.v","ln.sigma.w","rho")

## estimate model by MLE
##
low.vals = c(0,0,-2,-Inf,-Inf,-0.999)
up.vals = c(2,2,2,Inf,Inf,0.999)
MNZ.mle = SsfFit(MNZ.start,lny.ts,"MNZ.mod",
lower=low.vals,upper=up.vals)

## estimated parameters and asymptotic standard errors
##
MNZ.mle$parameters
sqrt(diag(MNZ.mle$vcov))
# estimated standard deviations
exp(MNZ.mle$parameters[4:5])
# note: use delta method to get standard errors for standard deviations

# compute filtered trend and cycle
filteredEst.MNZ = SsfMomentEst(lny.ts,
MNZ.mod(MNZ.mle$parameters),task="STFIL")
trend.filter = timeSeries(data=filteredEst.MNZ$state.moment[,1],
positions=filteredEst.MNZ$positions)
cycle.filter = timeSeries(data=filteredEst.MNZ$state.moment[,2],
positions=filteredEst.MNZ$positions)

par(mfrow=c(2,1))
plot(trend.filter,lny.ts,
main="Log Real GDP and Filtered Trend from MNZ Model",reference.grid=F)
plot(cycle.filter,main="Filtered Cycle from MNZ Model",reference.grid=F)

# compute smoothed trend and cycle
smoothedEst.MNZ = SsfMomentEst(lny.ts,
MNZ.mod(MNZ.mle$parameters),task="STSMO")
trend.smooth = timeSeries(data=smoothedEst.MNZ$state.moment[,1],
positions=smoothedEst.MNZ$positions)
cycle.smooth = timeSeries(data=smoothedEst.MNZ$state.moment[,2],
positions=smoothedEst.MNZ$positions)

par(mfrow=c(2,1))
plot(trend.smooth,lny.ts,
main="Log Real GDP and Smoothed Trend from MNZ Model")
plot(cycle.smooth,main="Smoothed Cycle from MNZ Model")

plot(cycle.smooth,reference.grid=F)

# plot smoothed cycle with 95% error bands
cycle.sd= sqrt(timeSeries(data=smoothedEst.MNZ$state.variance[,2],
positions=smoothedEst.MNZ$positions))
upper = cycle.smooth + 2*cycle.sd
lower = cycle.smooth - 2*cycle.sd
par(mfrow=c(1,1))
plot(cycle.smooth,upper,lower,
plot.args=list(lty=c(1,3,3)))

# plot filtered and smoothed cycle together
plot(cycle.filter,cycle.smooth,
plot.args=list(lty=c(1,2)))
legend(0.75,-3,legend=c("filtered","smoothed"),lty=c(1,2))

# plot filtered and smoothed trend together
plot(diff(trend.filter),diff(trend.smooth))

今天系统附件传不来程序,所以粘出来,估计这个程序和数据epoh老师您有
运行以上程序,为什么会提示以下错误:
> mnz.sim = SsfSim(ssf.mnz, n = 250)
Problem: Couldn't find a function definition for "SsfSim"
Use traceback() to see the call stack
二维码

扫码加我 拉你入群

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

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

2011-7-25 11:57:10
##
low.vals = c(0, 0, -2,  - Inf,  - Inf, -0.999)
> up.vals = c(2, 2, 2, Inf, Inf, 0.999)
> MNZ.mle = SsfFit(MNZ.start, lny.ts, "MNZ.mod", lower = low.vals,
        upper = up.vals)
Problem: Object "lny.ts" not found
Use traceback() to see the call stack
装入Finmetrics模块后,又提示以上错误,我没有办法了,请epoh老师帮忙!
非常感谢!
二维码

扫码加我 拉你入群

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

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

2011-7-25 12:00:23
traceback() 这个函数有什么用?如何用?
> traceback()
14: eval(action, sys.parent())
13: doErrorAction("Problem: Object \"lny.ts\" no
t found", 1000)
12: as.character(class(x))
11: match(el, set, nomatch = NA)
10: is.na(match(el, set, nomatch = NA))
9: !is.na(match(el, set, nomatch = NA))
8: is.element(as.character(class(x)), c("bdChara
cter", "bdExclude",
7: stop.on.bdObject(data)
6: SsfFit(MNZ.start, lny.ts, "MNZ.mod", lower =
low.vals, upper =
5: eval(i, local)
4: source(auto.print = auto.print, exprs = subst
itute(exprs.literal))
3: script.run(exprs.literal = {
2: eval(expression(script.run(exprs.literal = {
1:
Message: Problem: Object "lny.ts" not found
>
以上结果如何看和分析?
二维码

扫码加我 拉你入群

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

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

2011-7-25 16:14:54
缺少数据lngdpq.txt
lngdpq=read.table("lngdpq.txt")
lngdpq.df=lngdpq[,1]

lny = as.matrix(lngdpq.df)*100

td = timeSeq(from="1/1/1947",to="4/1/1998",by="quarters")
lny.ts = timeSeries(data=lny,positions=td)
source("MNZUCModel.ssc")

lngdpq.txt

  
lngdpq.txt
大小:(2.79 KB)

 马上下载




###########
当你要执行checkSV.ssc
首先要先打开checkSV.ssc
看要用到哪些数据及函数
State Space Modeling
把这些摆在一起时

StateSpaceSurvey.ssc; sv_mcl_est.ssc; ssfnong.ssc; checkSV.ssc

他们之间大都会相互调用函数.
二维码

扫码加我 拉你入群

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

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

2011-7-25 17:54:46
94# epoh

经您指导后,运行非常好!非常感谢!
lny = as.matrix(lngdpq.df)*100
我想问一下:为什么要在上面一行乘以100,然后再做成一个矩阵?

td = timeSeq(from="1/1/1947",to="4/1/1998",by="quarters")
lny.ts = timeSeries(data=lny,positions=td)
为什么在上面两行要对数据指定位置和做成时间序列,难道原来的数据不是时间序列吗?


from="1/1/1947",to="4/1/1998",by="quarters"
以上数据的开始时间和最后时间,季节数据您是怎么知道的?我在原始数据和程序中怎么没有看出来?



缺少数据lngdpq.txt
lngdpq=read.table("lngdpq.txt")
lngdpq.df=lngdpq[,1]

lny = as.matrix(lngdpq.df)*100

td = timeSeq(from="1/1/1947",to="4/1/1998",by="quarters")
lny.ts = timeSeries(data=lny,positions=td)
source("MNZUCModel.ssc")

lngdpq.txt

本文来自: 人大经济论坛 Matlab及其他计量软件专版 版,详细出处参考:https://bbs.pinggu.org/viewthread.php?tid=1127506&page=10&from^^uid=11232
2
二维码

扫码加我 拉你入群

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

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

2011-7-25 19:02:34
StateSpaceSurvey.ssc;MNZUCModel.ssc; BNdecomposition.ssc;
都有用到lny.ts

lny = as.matrix(lngdpq.df)*100        
td = timeSeq(from="1/1/1947",to="4/1/1998",by="quarters")
lny.ts = timeSeries(data=lny,positions=td)
以上三行取自BNdecomposition.ssc

log real GDP data:lngdpq.txt
取自
  http://faculty.washington.edu/ezivot/MFTS2ndEditionAdditions.htm


ps:

data=read.table()
data 是一个"data.frame"
由于会用到tsplot画图
所以用timeSeries()转换为"timeSeries" object


通常optimization过程,为了顺利收敛.
都会100*data
就像估计garch model
都采100* logreturn
二维码

扫码加我 拉你入群

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

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

2011-7-26 13:51:43
epoh老师,您好!
    我执行:markovSwitchingExamples.SSC时提示以下错误:Problem in parse(text = "script.run(exprs.literal={\n## markovSwitc..: Syntax error: Unbalanced parentheses, expected ")" before unbalanced ("}")  on input line 148
Use traceback() to see the call stack
想尽了一切办法无法解决,您看如何解决呢?
非常感谢!
附件列表

markovSwitchingExamples.rar

大小:2.96 KB

 马上下载

本附件包括:

  • markovSwitchingExamples.SSC

二维码

扫码加我 拉你入群

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

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

2011-7-26 14:10:35
65# epoh
请把full_bekk_mvgarch.m
这三行:
scalaropt=optimset('fminunc');
scalaropt=optimset(scalaropt,'TolFun',1e-1,'Display','iter','Diagnostics','on','DiffMaxChange',1e-2);
startingparameters=scalar_bekk_mvgarch(data,p,q,scalaropt);

改为这四行:

%scalaropt=optimset('fminunc');
%scalaropt=optimset(scalaropt,'TolFun',1e-1,'Display','iter','Diagnostics','on','DiffMaxChange',1e-2);
%startingparameters=scalar_bekk_mvgarch(data,p,q,scalaropt);

尊敬的epoh老师,您好!
    为什么以上三行注释了以后,程序就可以正常运行了呢?

startingparameters=[0.6836; 0.2031; 0.3717; 0.2803; 0.9101]
   
为什么要对startingparameters设置初值,而且必须要设五个[0.6836; 0.2031; 0.3717; 0.2803; 0.9101],而不是四个初值:[0.6836; 0.2031; 0.3717; 0.2803]
非常感谢!

本文来自: 人大经济论坛 Matlab及其他计量软件专版 版,详细出处参考:https://bbs.pinggu.org/viewthread.php?tid=1127506&page=7&from^^uid=11232
二维码

扫码加我 拉你入群

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

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

2011-7-26 14:21:05
96# epoh

epoh老师,还有附件中的这个VaR程序,运行后提示以下错误,我实在没办法,还希望
老师您帮忙看看!
非常感谢!
Problem in parse(text = "script.run(exprs.liter..: Syntax error: Unbalanced parentheses, expected "}" before unbalanced (")")  on input line 126
Use traceback() to see the call stack
附件列表

valueAtRiskDemo.rar

大小:2.62 KB

 马上下载

本附件包括:

  • valueAtRiskDemo.ssc

二维码

扫码加我 拉你入群

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

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

2011-7-26 15:10:20
###"markovSwitchingExamples.ssc"
1.漏掉一个 ")",我已补上.

2.少了数据ndx.rvol我也已补上.
  ndx.ret2 = getReturns(ndx.dat[,"Close"])^2
  ndx.rvol = sqrt(aggregate(ndx.ret2, FUN=sum, by="weeks", week.align=1))

3.少了function shadePlot()
  遍寻不着,就在程序最后面.
  我把他封了.
  
markovSwitchingExam.rar
大小:(3.04 KB)

 马上下载

本附件包括:

  • markovSwitchingExamples.SSC




###########"valueAtRiskDemo.ssc"

错在底下norm.ETL多了一个")"


norm.ETL = function(x, VaR) {
## required arguments:
## x   timeSeries of returns (simple or continuous)
## VaR   VaR estimate based on normal approximation.
## optional arguments:
## value:
##    numeric value giving ETL estimate from estimated normal
##   distribution
mu = colMeans(x)
sd = colStdevs(x)
z = (mu - VaR)/sd)
ETL = mu + sd*(dnorm(z)/pnorm(z))
ETL
}


请将z = (mu - VaR)/sd)

改为z = (mu - VaR)/sd



%%%%%%%%%%matlab full_bekk
正常的话,startingparameters应该由scalar_bekk_mvgarch估计
但因为当时你的function vech()出问题
所以才有这个临时的权宜之计
先供你能跑程序
不知你重安装之后,是否正常了?

full_bekk     要估计的系数有11个
diagonal_bekk 要估计的系数有 9个
scalar_bekk   要估计的系数有 5个

以full_bekk 而言
startingparameters=[0.6836; 0.2031; 0.3717; 0.2803; 0.9101]
只是第一步而已,因为是要估计11个系数
所以startingparameters也是11个
startingparameters=[0.6836; 0.2031; 0.3717; 0.2803; 0;0;0.2803;0.9101;0;0;0.9101]
透过full_bekk_mvgarch_likelihood.m 来估计
parameters=fminunc('full_bekk_mvgarch_likelihood',startingparameters,options,data,p,q,k,k2,t);

二维码

扫码加我 拉你入群

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

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

2011-7-26 22:40:30
100# epoh
运行TVmodel中的TVCmodel-final文件夹中的:TVCestimate_Figures3_4.m,提示以下错误,请问epoh老师,您看如何解决呢?非常感谢!

Step 1: Import data and run OLS regressions ...
Step 2: Run OLS regressions and estimate variance of shocks ...
Quandt Liklihood ratio test statistic: 8.0599
Step 3: HP filter series ...
Step 4: Run Kalman filter and smoother ...

convert rhos into quarterly frequency ...

??? Undefined command/function 'nancov'.

Error in ==> TVCestimate_Figures3_4 at 285

SVstate_LR_M(i,:,:)=nancov(store_draws);


>>

epoh老师,为什么附件中的程序没有一个可以运行?如何可以运行每一个程序?
我近期要用这些程序,希望帮忙,非常感谢!
TVmodel.rar (156.24 KB)
下载次数:1
2011-7-22 16:36

TVmodel.rar在77楼,从以下链接可以下载:
本文来自: 人大经济论坛 Matlab及其他计量软件专版 版,详细出处参考:https://bbs.pinggu.org/viewthread.php?tid=1127506&page=8&from^^uid=11232
二维码

扫码加我 拉你入群

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

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

2011-7-26 22:41:53
Epoh老师,您好!您看以下问题如何解决?我想了很多办法,还是无法解决!
非常感谢您!
运行bootStrap.ssc提示以下错误:

# load resample library

module(resample)

Problem in module(resample): C:/PROGRAM FILES/INSIGHTFUL/splus80\module\resample is not a valid S-PLUS database

Use traceback() to see the call stack

附件列表

bootStrap.rar

大小:1.5 KB

 马上下载

本附件包括:

  • bootStrap.ssc

二维码

扫码加我 拉你入群

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

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

2011-7-26 22:54:15
另外,epoh老师,您好!
    我的splus8.04没有resample这个模块,您看应该怎么解决呢?
非常感谢!
二维码

扫码加我 拉你入群

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

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

2011-7-27 09:08:00
%%%TVCmodel-final
我用matlab 7.6.0(matlab2008a)
执行TVCestimate_Figures3_4 没啥问题
一直到line at 474
数据产生NaN or Inf.才终止.
  Input to EIG must not contain NaN or Inf.
  Error in ==> TVCestimate_Figures3_4 at 474
               beta79=beta79a+(V79^.5)*rd;


time period = 17
beta79a =
  1.0e+015 *
    0.0000
    0.0000
    0.0000
   -1.1529
    1.1529
   -0.0000


V79 =

  1.0e+033 *
    0.0000    0.0000    0.0000   -0.0000    0.0000   -0.0000
    0.0000    0.0000    0.0000   -0.0000    0.0000   -0.0000
    0.0000    0.0000    0.0000   -0.0000    0.0000   -0.0000
   -0.0000   -0.0000   -0.0000    1.3292   -1.3292   -0.0000
    0.0000    0.0000    0.0000   -1.3292    1.3292    0.0000
   -0.0000   -0.0000   -0.0000   -0.0000    0.0000    0.0000


time period = 18
beta79a =
    2.1541
    0.9443
    0.5065
       Inf
       Inf
       Inf


V79 =

    0.3643    0.2281    0.0524       NaN       NaN       NaN
    0.2281    0.2093    0.0314       NaN       NaN       NaN
    0.0524    0.0314    0.0190       NaN       NaN       NaN
       NaN       NaN       NaN       NaN       NaN       NaN
       NaN       NaN       NaN       NaN       NaN       NaN
       NaN       NaN       NaN       NaN       NaN       NaN



FIGURE 3 'Smoother point long-run response estimates and confidence bands'

  
   FIGURE 3.jpg


执行TVCestimate_Figures3_4
还需要安装Curve Fitting Toolbox

建议你最起码安装matlab 7.6.0(matlab2008a)
可以省掉一些麻烦


nancov.m
  
nancov.rar
大小:(2.01 KB)

 马上下载

本附件包括:

  • nancov.m




#######bootStrap.ssc
#install pacakge "resample"
in s-plus command window:
  install.pkgutils()
  library(pkgutils)
  install.packages("resample")

安装完后,
要先建立data:cerExample
  cerExample.xls

  
cerExample.xls
大小:(11.5 KB)

 马上下载



# To load the data into S-PLUS
# File/Import Data/From File
# Click [Browse] and select the file cerExample.xls
# Name the Data set cerExample
# Click Options tab, and uncheck box next to Strings as factors
# Click Okay to load the data into the data.frame cerExample

library("resample")
module("finmetrics")
td = timeSeq(from="7/1/1992",to="11/1/2000",by="months",format="%b %Y")-1
cerExample.ts = timeSeries(positions=td,data=cerExample)
source("bootStrap.ssc")

二维码

扫码加我 拉你入群

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

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

2011-7-27 16:16:30
104# epoh

# load resample library
module(resample)
Problem in module(resample): C:/PROGRAM FILES/INSIGHTFUL/splus80\module\resample is not a valid S-PLUS database
Use traceback() to see the call stack
epoh老师,您好!
      我的splus8.04没有resample这个module,
所以会提示以上问题,您看怎么解决?
二维码

扫码加我 拉你入群

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

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

2011-7-27 16:58:37
104楼已告知zhangtao兄
要先安装pacakge "resample"
#install pacakge "resample"
#in s-plus command window:
  install.pkgutils()
  library(pkgutils)
  install.packages("resample")

安装完,以后要载入
library("resample")
二维码

扫码加我 拉你入群

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

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

2011-7-27 17:10:02
x(:,4) = sum(x,2);     % introduce correlation
epoh老师,您好! x(:,4) = sum(x,2)是什么意思?
x = randn(30,4);       % uncorrelated data
%       x(:,4) = sum(x,2);     % introduce correlation
%       x(2,3) = NaN;          % introduce one missing value
%       c = nancov(x)          % compute sample covariance
二维码

扫码加我 拉你入群

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

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

2011-7-27 17:13:20
x = randn(30,4);       % uncorrelated data
    x(:,4) = sum(x,2);     % introduce correlation
    x(2,3) = NaN;          % introduce one missing value
    c = nancov(x)          % compute sample covariance
epoh老师,您好!我想调用localcov.m函数计算以上x的localcov,如何修改和调用以下函数?
function [c,n] = localcov(x,domle)
%LOCALCOV Compute cov with no error checking and assuming NaNs are removed

[m,n] = size(x);
if domle
   denom = m;
else
   denom = max(0,m-1);
end

if m==1   % and doing mle, be sure to get exact 0
   c = zeros(n,class(x));
elseif denom==0
   c = NaN(n,class(x));
else
   xc = x - repmat(mean(x),m,1);
   c = xc' * xc / denom;
end
二维码

扫码加我 拉你入群

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

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

2011-7-27 18:55:15
先说明x(:,4) = sum(x,2);
%B = sum(A,dim)
%dim=1,sum of each column
%dim=2,sum of each row
x = randn(5,3)
x =
   -0.9812   -0.5062    1.7357
   -0.6885    1.6197    1.9375
    1.3395    0.0809    1.6351
   -0.9092   -1.0811   -1.2559
   -0.4129   -1.1245   -0.2135

%增加了第四column
%sum of each row
x(:,4) = sum(x,2)
x =
   -0.9812   -0.5062    1.7357    0.2483  (-0.9812 +(-0.5062)+1.7357)
   -0.6885    1.6197    1.9375    2.8687
    1.3395    0.0809    1.6351    3.0554
   -0.9092   -1.0811   -1.2559   -3.2462
   -0.4129   -1.1245   -0.2135   -1.7509

x(2,3) = NaN  
x =
   -0.9812   -0.5062    1.7357    0.2483
   -0.6885    1.6197       NaN    2.8687
    1.3395    0.0809    1.6351    3.0554
   -0.9092   -1.0811   -1.2559   -3.2462
   -0.4129   -1.1245   -0.2135   -1.7509

%%%%%%%%%%%%%%%%%%

x = randn(30,4);       % uncorrelated data
x(:,4) = sum(x,2);     % introduce correlation
x(2,3) = NaN;          % introduce one missing value
c = nancov(x)          % compute sample covariance
调用localcov.m函数计算以上x的localcov
照function定义应该remove NaNs
但不移除,也不会产生错误.
domle设置为 0 , or 1
localcov(x,0)
c =
    0.9065   -0.0918       NaN    0.9206
   -0.0918    0.8793       NaN    0.6173
       NaN       NaN         NaN       NaN
    0.9206    0.6173       NaN    3.2602

localcov(x,1)
c =
    0.8763   -0.0887       NaN    0.8899
   -0.0887    0.8500       NaN    0.5967
       NaN       NaN          NaN       NaN
    0.8899    0.5967       NaN    3.1516
二维码

扫码加我 拉你入群

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

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

2011-7-28 09:52:46
104# epoh

epoh老师,您好!
   nancov.m
    nancov.rar (2.01 KB) 这个程序装上后,运行很好,我想问一下:nancov.m这个程序您是在那儿找到的?我的matlab上为什么没有?
   


本文来自: 人大经济论坛 Matlab及其他计量软件专版 版,详细出处参考:https://bbs.pinggu.org/viewthread.php?tid=1127506&page=11&from^^uid=11232
二维码

扫码加我 拉你入群

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

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

2011-7-28 09:58:40
104# epoh

epoh老师,您好!
       我是完全按您的指导操作的,然后提示以下错误:
我估计是不是我的splus8没有resample模块?
S-PLUS : Copyright (c) 1988, 2007 Insightful Cor
p.
S : Copyright Insightful Corp.
Enterprise Developer Version 8.0.4  for Microsof
t Windows : 2007
Working data will be in F:\0计量经济学前沿\Analy
sis of High-Frequency Financial Data with S-PLUS
\Return Calculations
> install.pkgutils()
Warning messages:
  It looks like a version of the pkgutils
package is already installed,
exiting without downloading or
installing any files.
Run install.pkgutils(update=TRUE) to
force a new install in: install.pkgutils
()

>   library(pkgutils)
>   install.packages("resample")
The downloaded packages are in
D:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\di000
E03.tmp\downloaded_packages
Warning messages:
1: argument 'lib' is missing: using
D:\Documents and
Settings\Administrator\Application
Data\Insightful\splus80_WIN386\library
in: install.packages("resample")
2: cannot remove prior installation of package
'resample' in: unpackPkg(foundpkgs[okp,
2], foundpkgs[okp, ....
> library("resample")
Problem in library("resample"): No section "resa
mple" in the library directories: D:\Documents a
nd Settings\Administrator\Application Data\Insig
htful\splus80_WIN386\library, C:\PROGRAM FILES\I
NSIGHTFUL\splus80\local\library, C:\PROGRAM FILE
S\INSIGHTFUL\splus80\library, C:\PROGRAM FILES\I
NSIGHTFUL\splus80\module
Use traceback() to see the call stack
> module("finmetrics")
S+FinMetrics Version 3.0.2 for Microsoft Windows
: 2007
> td = timeSeq(from="7/1/1992",to="11/1/2000",by="months",format="%b %Y")-1
> cerExample.ts = timeSeries(positions=td,data=cerExample)
> source("bootStrap.ssc")
Warning messages:
  file "bootStrap.ssc": incomplete last line
in: parse(n = n, file = file)
Problem in module(resample): C:/PROGRAM FILES/IN
SIGHTFUL/splus80\module\resample is not a valid
S-PLUS database
Use traceback() to see the call stack
>
二维码

扫码加我 拉你入群

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

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

2011-7-28 10:11:25
111# zhangtao

Use traceback() to see the call stack
> library("resample")
> module("finmetrics")
> td = timeSeq(from="7/1/1992",to="11/1/2000",by="months",format="%b %Y")-1
> cerExample.ts = timeSeries(positions=td,data=cerExample)
> source("bootStrap.ssc")
Warning messages:
  file "bootStrap.ssc": incomplete last line
in: parse(n = n, file = file)
> bootstrap(stack.loss, mean)
Call:
bootstrap(data = stack.loss, statistic = mean)
Number of Replications: 1000
Summary Statistics:
     Observed  Mean   Bias    SE
mean    17.52 17.58 0.0601 2.138
> temp <- bootstrap(stack.loss, mean)
> temp
Call:
bootstrap(data = stack.loss, statistic = mean)
Number of Replications: 1000
Summary Statistics:
     Observed  Mean     Bias    SE
mean    17.52 17.49 -0.03367 2.178
> summary(temp)
Call:
bootstrap(data = stack.loss, statistic = mean)
Number of Replications: 1000
Summary Statistics:
     Observed  Mean     Bias    SE
mean    17.52 17.49 -0.03367 2.178
Percentiles:
      2.5%   5%   95% 97.5%
mean 13.71 14.1 21.33 22.14
BCa Confidence Intervals:
     2.5%    5%   95% 97.5%
mean   14 14.48 22.05 23.22
Bootstrap Tilting Confidence Intervals:
      2.5%    5%   95% 97.5%
mean 13.94 14.48 21.72 22.62
t limits with bootstrap standard error:
      2.5%    5%   95% 97.5%
mean 13.94 14.48 21.72 22.62
> plot(temp)
> qqnorm(temp)
>
epoh老师,根据您的指导,运行成功了,前次是我自己操作失误,没有成功。
非常感谢!
二维码

扫码加我 拉你入群

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

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

2011-7-28 10:23:06
epoh老师,您好!
我想问一下:附件中的这个pkgutils包是做什么用的?

This library section (package) contains functions for an R-like package
utility system in S-PLUS.

The functions here are essentially the same as in R.
以上这句话是什么意思?
附件列表

pkgutils.rar

大小:280.21 KB

 马上下载

二维码

扫码加我 拉你入群

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

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

2011-7-28 10:55:00
zhangtao兄
有关pkgutils的问题
ywh19860616兄也问过
请看帖子64楼

"pkgutils" contains functions and scripts for downloading,
installing, building and checking packages.

also pls see
Insightful\splus80\help\spluspackages.pdf
page 14/58
二维码

扫码加我 拉你入群

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

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

2011-7-28 16:48:18
% ============================================================ %
% vec.m
%
% For a matrix A returns vec(A). (see Hamilton p. 265)
% ============================================================ %

function v = vec(A);
  [m n] = size(A);
  v = [];
  for i = 1:n;
    v = [v;A(:,i)];
  end;
epoh老师,您好!以上我传给您的TVmodel文件夹中的vector eoor correction model的m文件,
epoh老师,您看如何对A赋值呢?
[m n] = size(A); 为什么这一行会返回两个值m和n?
v = [];为什么要对v赋一个空的[ ]?

for i = 1:n;
    v = [v;A(:,i)];
  end;
这三行是如何实现向量误差修正的?
二维码

扫码加我 拉你入群

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

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

2011-7-28 16:49:19
114# epoh

% ============================================================ %
% vec.m
%
% For a matrix A returns vec(A). (see Hamilton p. 265)
% ============================================================ %

function v = vec(A);
  [m n] = size(A);
  v = [];
  for i = 1:n;
    v = [v;A(:,i)];
  end;
epoh老师,您好!以上我传给您的TVmodel文件夹中的vector eoor correction model的m文件,
epoh老师,您看如何对A赋值呢?
[m n] = size(A); 为什么这一行会返回两个值m和n?
v = [];为什么要对v赋一个空的[ ]?

for i = 1:n;
    v = [v;A(:,i)];
  end;
这三行是如何实现向量误差修正的?
二维码

扫码加我 拉你入群

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

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

2011-7-28 16:59:45
另外,TVmodel文件夹中的TVCmodel-final子文件夹是做什么用的?
二维码

扫码加我 拉你入群

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

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

2011-7-28 17:03:19
114# epoh
Epoh老师,您好!
我想文件附件中的HpFilter.m对附件中的数据SHindex.txt2列做HP滤波,对Ch2007.xls进行第2345列进行滤波,请问:如何修改和运行HpFilter程序?
非常感谢!
附件列表

HpFilter.rar

大小:5.12 KB

 马上下载

二维码

扫码加我 拉你入群

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

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

2011-7-28 19:01:50
%%%TVCmodel-final子文件
TVCmodel-final子文件内的文件
主要是供TVCestimate_Figures3_4.m
类似单独的一个Project

%%%%%%%%%%%
%vec.m  : convert matrix to vector
%  NOT vector eoor correction model

A=[1 2 ;3  4; 5 6;]
A =
     1     2
     3     4
     5     6
[m n] = size(A)  %m=3,n=2
v = [];
for i = 1:n;
    v = [v;A(:,i)];
end;
v'

ans =     1     3     5     2     4     6

%the same as
reshape(A,1,m*n)

ans =     1     3     5     2     4     6

%%%%%HP filter on series
load('SHindex.txt')
shindex=SHindex(:,2);
HPlambda=3000;
[gx1] = hpfilter(shindex,HPlambda)

X=xlsread('Ch2007.xls','B2:E57');
[gx2] = hpfilter(X(:,1),HPlambda);
[gx3] = hpfilter(X(:,2),HPlambda);
[gx4] = hpfilter(X(:,3),HPlambda);
[gx5] = hpfilter(X(:,4),HPlambda);
[gx2,gx3,gx4,gx5]
二维码

扫码加我 拉你入群

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

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

2011-7-30 09:03:28
119# epoh

epoh老师,您好!
         我想用附件中的data_analysis.m分析我的数据Ch2007.xls 和SHindex.txt,如何修改附件中的data_analysis.m?
         另外,附件中的data如何打开?也就是.mat文件如何打开?
          附件中的.dat文件如何打开?也就是sp500.DAT等几个文件如何打开?
非常感谢!
附件列表

HPfilter111.rar

大小:46.07 KB

 马上下载

二维码

扫码加我 拉你入群

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

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

栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群