楼主: 飘零的枫叶
51749 206

[问答] 用lingo软件如何对DEA-DA模型进行编程 [推广有奖]

31
zhangtao 发表于 2011-7-18 14:55:49
Problem: Object "meanDur5min.msft" not found
Use traceback() to see the call stack
> meanDur5min.ave.msft@title = "5-min Mean Durations: MSFT\n(averaging across 11 trading days)"
Problem: Object "meanDur5min.ave.msft" not found
Use traceback() to see the call stack
>
> # plots of ACF and calendar pattern in durations
> par(mfrow = c(1,2))
> acf.plot(acf(meanDur5min.msft, lag.max = 234, plot = F),
+      main = "ACF of 5-min Mean Durations:\nMSFT (lags up to 3 days)")
Problem: Object "meanDur5min.msft" not found
Use traceback() to see the call stack
> plot(meanDur5min.ave.msft, reference.grid = F,
+      x.axis.args = list(format.label = c("%H:%02M", "%Z"),
+                        time.of.day.style = "24:00"))
Problem: Object "meanDur5min.ave.msft" not found
Use traceback() to see the call stack
>
> ## USD/EUR
> ## mean durations in 5-min intervals
> meanDur5min.eurusd = aggregateSeriesHF(duration.eurusd, interv.type = "weekly",
+                       bound.hours = c("22:00", "22:00"), FUN = mean,
+                      by = "minutes", k.by = 5, adj = 1, drop.empty = F, together = T)
Problem: Object "duration.eurusd" not found
Use traceback() to see the call stack
> meanDur5min.eurusd[1:5,]
Problem: Object "meanDur5min.eurusd" not found
Use traceback() to see the call stack
>
> # averaging 5-min mean durations across trading days
> meanDur5min.ave.eurusd = SmoothAcrossIntervs(ts = meanDur5min.eurusd, n.subinterv = 288,
+                                    n.interv = 5, FUN = mean)
Problem: Object "meanDur5min.eurusd" not found
Use traceback() to see the call stack
> meanDur5min.ave.eurusd@title = "5-min Mean Durations: USD/EUR\n(averaging across 11 trading days)"
Problem: Object "meanDur5min.ave.eurusd" not found
Use traceback() to see the call stack
>
> # plots of ACF and calendar pattern in durations
>         #removing the NAs in meanDur5min before plotting ACF
>         na.idx = is.na(seriesData(meanDur5min.eurusd))
Problem: Object "meanDur5min.eurusd" not found
Use traceback() to see the call stack
> par(mfrow = c(1,2))
> acf.plot(acf(meanDur5min.eurusd[!na.idx,], lag.max = 864, plot = F),
+      main = "ACF of 5-min Mean Durations:\nUSD/EUR (lags up to 3 days)")
Problem: Object "meanDur5min.eurusd" not found
Use traceback() to see the call stack
> plot(meanDur5min.ave.eurusd, reference.grid = F,
+      x.axis.args = list(format.label = c("%H:%02M", "%Z"),
+                        time.of.day.style = "24:00"))
Problem: Object "meanDur5min.ave.eurusd" not found
Use traceback() to see the call stack
>
> ### 3.3.3 Calendar patterns in the frequency of trades or quotes ###
> ## MSFT
> # construct an aux series to count trades
> aux.msft = timeSeries(data.frame(Ticks = rep(1, nrow(msftt.ts))),
+             pos = msftt.ts@positions)
>
> # the number of trades in 5-min intervals
> trades5min.msft = aggregateSeriesHF(aux.msft, interv.type = "daily",
+                       bound.hours = c("9:30", "16:00"), FUN = sum,
+                      by = "minutes", k.by = 5, adj = 1, drop.empty = F, together = T)
Problem in sub(ts@data, idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> trades5min.msft[1:5,]
Problem: Object "trades5min.msft" not found
Use traceback() to see the call stack
>
> # averaging the number of trades in 5-min intervals across trading days
> trades5min.ave.msft = SmoothAcrossIntervs(ts = trades5min.msft, n.subinterv = 78,
+                                    n.interv = 11, FUN = mean)
Problem: Object "trades5min.msft" not found
Use traceback() to see the call stack
> trades5min.ave.msft@title = "Number of Trades in 5-min Intervs: MSFT\n(averaging across 11 trading days)"
Problem: Object "trades5min.ave.msft" not found
Use traceback() to see the call stack
>
数学好就是要天天学

32
zhangtao 发表于 2011-7-18 14:56:13
# plots of ACF and calendar pattern in trades number
> par(mfrow = c(1,2))
> acf.plot(acf(trades5min.msft, lag.max = 234, plot = F),
+      main = "ACF of Number of Trades in 5-min Intervs:\nMSFT (lags up to 3 days)")
Problem: Object "trades5min.msft" not found
Use traceback() to see the call stack
> plot(trades5min.ave.msft, reference.grid = F,
+      x.axis.args = list(format.label = c("%H:%02M", "%Z"),
+                        time.of.day.style = "24:00"))
Problem: Object "trades5min.ave.msft" not found
Use traceback() to see the call stack
>
> ## USD/EUR
> # construct an aux series to count quotes
> aux.eurusd = timeSeries(data.frame(Ticks = rep(1, nrow(eurusd.ts))),
+               pos = eurusd.ts@positions)
>
> # the number of quotes in 5-min intervals
> quotes5min.eurusd = aggregateSeriesHF(aux.eurusd, interv.type = "weekly",
+                       bound.hours = c("22:00", "22:00"), FUN = sum,
+                      by = "minutes", k.by = 5, adj = 1, drop.empty = F, together = T)
Problem in sub(ts@data, idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> quotes5min.eurusd[1:5,]
Problem: Object "quotes5min.eurusd" not found
Use traceback() to see the call stack
>
> # averaging the number of quotes in 5-min intervals across trading days
> quotes5min.ave.eurusd = SmoothAcrossIntervs(ts = quotes5min.eurusd, n.subinterv = 288,
+                                    n.interv = 5, FUN = mean)
Problem: Object "quotes5min.eurusd" not found
Use traceback() to see the call stack
> quotes5min.ave.eurusd@title = "Number of Quotes in 5-min Intervs: USD/EUR\n(averaging across 11 trading days)"
Problem: Object "quotes5min.ave.eurusd" not found
Use traceback() to see the call stack
>
> # plots of ACF and calendar pattern in quotes number
> par(mfrow = c(1,2))
> acf.plot(acf(quotes5min.eurusd, lag.max = 864, plot = F),
+      main = "ACF of Number of Quotes in 5-min Intervs:\nUSD/EUR (lags up to 3 days)")
Problem: Object "quotes5min.eurusd" not found
Use traceback() to see the call stack
> plot(quotes5min.ave.eurusd, reference.grid = F,
+      x.axis.args = list(format.label = c("%H:%02M", "%Z"),
+                        time.of.day.style = "24:00"))
Problem: Object "quotes5min.ave.eurusd" not found
Use traceback() to see the call stack
>
数学好就是要天天学

33
zhangtao 发表于 2011-7-18 14:59:03
traceback()
5: eval(action, sys.parent())
4: doErrorAction("Problem: Object \"quotes5min.ave.eurusd\" not found", 1000)
3: plot(quotes5min.ave.eurusd, reference.grid = F, x.axis.args = list(format.label = c("%H:%02M", "%Z"),
2: eval(expression(plot(quotes5min.ave.eurusd, reference.grid = F, x.axis.args = list(format.label = c("%H:%02M
",
1:
Message: Problem: Object "quotes5min.ave.eurusd" not found
数学好就是要天天学

34
zhangtao 发表于 2011-7-18 19:03:41
> gibbs1 <- function(nits,y,mu0=0,tau0=1){
+ alphas <- 0.1
+ betas <- 0.01
+ mus <- 0.0
+ taus <- 1.0
+ x <- array(0,c(nits+1,2))
+ x[1,1] <- mu0
+ x[1,2] <- tau0
+ n <- length(y)
+ ybar <- mean(y)
+ for(t in 2:(nits+1)){
+ x[t,1]_RNORM(1,(n*ybar*x[t-1,2]+mus*taus)/
错误: 意外的输入 于
"for(t in 2:(nits+1)){
x[t,1]_"
> (n*x[t-1,2]+taus),
错误: 意外的','在"(n*x[t-1,2]+taus),"里
> sqrt(1/(n*x[t-1,2]+taus)))
错误: 意外的')'在"sqrt(1/(n*x[t-1,2]+taus)))"里
> sn_sum((y-x[t,1])^2)
错误: 没有"sn_sum"这个函数
> x[t,2]_RGAMMA(1,alphas+n/2)
错误: 意外的输入在"x[t,2]_"里
> /(betas+sn/2)}
错误: 意外的'/'在"/"里
> x
错误: 找不到对象'x'
> }
epoh老师,以上代码错在什么地方?
数学好就是要天天学

35
epoh 发表于 2011-7-18 20:54:48
nits=100
set.seed(123)
y=rnorm(100)
gibbs1 <- function(nits,y,mu0=0,tau0=1){
alphas <- 0.1
betas <- 0.01
mus <- 0.0
taus <- 1.0
x <- array(0,c(nits+1,2))
x[1,1] <- mu0
x[1,2] <- tau0
n <- length(y)
ybar <- mean(y)
for(t in 2:(nits+1)){
x[t,1]=rnorm(1,(n*ybar*x[t-1,2]+mus*taus)/(n*x[t-1,2]+taus),sqrt(1/(n*x[t-1,2]+taus)))
sn=sum((y-x[t,1])^2)
x[t,2]=rgamma(1,alphas+n/2)/(betas+sn/2)}
x
}
gibbs1(nits,y)
               [,1]              [,2]
  [1,]  0.0000000000 1.0000000
  [2,]  0.0188227055 1.2388372
  [3,]  0.0676069255 1.1429600
  .......
  .......
[99,]  0.1772417126 1.2318935
[100,]  0.1989838980 0.9707243
[101,] -0.0488330617 1.2237534

#########
HFLibrary三四年前我曾用过,
不过因为是建构于S-PLUS 6.2,
现在在s-plus 8.0执行上,的确有些问题,
虽然FinMetrics 3.0.已经带进了HFLibrary
不过还是存在些问题.
我再抽空看看.
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
zhangtao + 5 + 5 + 5 真的非常感谢!

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

36
zhangtao 发表于 2011-7-18 22:18:18
35# epoh
我用的是splus8.0, Finmetrics3.02,
我不明白的是这个HFlibrary.ssc是做什么用的?在
splus中如何调用?我把它copy and then paste into 到splus的根目录中的library
文件夹中,但是在splus中无法load library,所以不知道如何使用HFlibrary.
还有附件中的几个ssc程序也无法在splus8中运行。
数学好就是要天天学

37
ywh19860616 发表于 2011-7-18 22:56:53
哈哈,epoh老师,我和zhangtao兄有同样疑问

.ssc是s-plus软件中自己编写的程序后缀名吗?

S-PLUS script for examples in paper: HFAnalysis.ssc
S-PLUS HF library: HFLibrary.SSC. Note: some of the functions in the HF library require the S+FinMetrics?
HFLibrary.SSC怎么判别是一个包?
我看了C:\Program Files\Insightful\splus80\library里面的,都没有SSC结尾的。
能不能这样说,他是一个外部包,而不是s-plus自带的?

还有一般安装包是用
install.packages("  ")
我看到一个包pkgutils是这样安装的install.pkgutils(),有什么区别规则吗?
一份耕耘,一份收获。

38
ywh19860616 发表于 2011-7-19 07:10:57
模块module和包library有何区别?是moduel包含了library?
一份耕耘,一份收获。

39
zhangtao 发表于 2011-7-19 10:15:13
> # Created on 02/20/2003
# By Bingcheng Yan
# Last updated on 11/06/2003
## Moved utility functions to the HF Library
## The library has to be attached to run this script file
## Functions used in the script file:
## TAQLoad()
## OlsenLoad()
## reorderTS()
## plotByDays()
## ExchangeHoursOnly()
## FxBizWeekOnly()
## align.withinDay()
## align.withinWeek()
## diff.withinDay()
## diff.withinWeek()
## is.tsBW()
## tsBW()
## DurationInInterv()
## PriceChgInInterv()
## getSpread()
## SmoothAcrossIntervs()
## tableSmoother()
## rbindtimeSeries()
## aggregateSeriesHF()
## tradeDirec()
## Genr.RealVol()
## Attach the FxLibrary
attach("D:\\Consulting\\FxLibrary", pos = 2, name = "FxLibrary")
> ## Load the FinMetrics module
module("finmetrics", first = F)
> #################### Section 2 Data Proceesing ####################################
### loading MSFT Trade data ####
msftt.ts = TAQLoad(file = "D:\\CompFinProg\\HFAnalysis\\trade_msft.txt", type = "trade")
> msftt.ts[1:5,  ]
        Positions Cond Ex Symbol Corr G127    Price Size Seq
5/1/1997 8:01:02 T    T  MSFT   0    0    121.1250 1500 0  
5/1/1997 8:02:24 T    T  MSFT   0    0    121.5625  500 0  
5/1/1997 8:03:20 T    T  MSFT   0    0    121.5625 1000 0  
5/1/1997 8:03:22 T    T  MSFT   0    0    121.5625 1200 0  
        Positions Cond Ex Symbol Corr G127    Price Size Seq
5/1/1997 8:38:15 T    T  MSFT   0    0    121.6250 1000 0  
> slotNames(msftt.ts)
[1] "data"              "positions"         "start.position"    "end.position"      "future.positions"
[6] "units"             "title"             "documentation"     "attributes"        "fiscal.year.start"
[11] "type"            
> msftt.ts@data[1:5,  ]
  Cond Ex Symbol Corr G127    Price Size Seq
1    T  T   MSFT    0    0 121.1250 1500   0
2    T  T   MSFT    0    0 121.5625  500   0
3    T  T   MSFT    0    0 121.5625 1000   0
4    T  T   MSFT    0    0 121.5625 1200   0
  Cond Ex Symbol Corr G127    Price Size Seq
5    T  T   MSFT    0    0 121.6250 1000   0
> msftt.ts@positions[1:5]
[1] 5/1/1997 8:01:02 5/1/1997 8:02:24 5/1/1997 8:03:20 5/1/1997 8:03:22 5/1/1997 8:38:15
> ### loading MSFT Quote data ###
msftq.ts = TAQLoad("D:\\CompFinProg\\HFAnalysis\\quote_msft.txt", type = "quote")
> msftq.ts[1:5,  ]
        Positions Ex MMID Symbol     Bid BidSize Mode     Ask AskSize Seq
5/1/1997 8:17:24 T       MSFT   121.500 11      12   121.625 11      0  
5/1/1997 9:00:44 T       MSFT   121.750 10      12   121.625 11      0  
5/1/1997 9:07:27 T       MSFT   121.750 10      12   121.625 10      0  
5/1/1997 9:16:30 T       MSFT   121.875 10      12   121.625 10      0  
        Positions Ex MMID Symbol     Bid BidSize Mode     Ask AskSize Seq
5/1/1997 9:20:29 T       MSFT   121.875 10      12   121.625  3      0  
> ### loading GE Trade data ####
get.ts = TAQLoad("D:\\CompFinProg\\HFAnalysis\\trade_ge.txt", type = "trade")
> get.ts[1:5,  ]
        Positions Cond Ex Symbol Corr G127   Price  Size     Seq
5/1/1997 9:30:17      N  GE     0    0    110.625 78700 3689550
5/1/1997 9:30:20      M  GE     0    0    110.625   100       0
5/1/1997 9:30:20      M  GE     0    0    110.625   100       0
5/1/1997 9:30:20      M  GE     0    0    110.625   300       0
        Positions Cond Ex Symbol Corr G127   Price  Size     Seq
5/1/1997 9:30:20      M  GE     0    0    110.625   100       0
> ### loading GE Quote data ###
geq.ts = TAQLoad("D:\\CompFinProg\\HFAnalysis\\quote_ge.txt", type = "quote")
> geq.ts[1:5,  ]
        Positions Ex MMID Symbol     Bid BidSize Mode    Ask AskSize     Seq
5/1/1997 9:00:44 T  TRIM GE       0.000 0       12     0.00  0            0
5/1/1997 9:00:44 T  MADF GE       0.000 0       12     0.00  0            0
5/1/1997 9:30:20 C       GE     106.125 5       12     0.00  0            0
5/1/1997 9:30:27 N       GE     110.625 5       10   110.75 10      3689560
        Positions Ex MMID Symbol     Bid BidSize Mode    Ask AskSize     Seq
5/1/1997 9:30:30 M       GE     109.125 5       12   111.00  1            0
> ### loading USD/EUR data ###
eurusd.ts = OlsenLoad("D:\\CompFinProg\\HFAnalysis\\eur_usd.txt")
> eurusd.ts[1:5,  ]
         Positions    Bid    Ask Institution
3/11/2001 1:07:46 0.9337 0.9342 AREX      
3/11/2001 1:07:52 0.9336 0.9341 AREX      
3/11/2001 1:07:57 0.9334 0.9339 AREX      
3/11/2001 1:08:04 0.9337 0.9342 AREX      
         Positions    Bid    Ask Institution
3/11/2001 5:42:35 0.9330 0.9340 CMBK      
> eurusd.ts[1:5, "Bid"]
         Positions    Bid
3/11/2001 1:07:46 0.9337
3/11/2001 1:07:52 0.9336
3/11/2001 1:07:57 0.9334
3/11/2001 1:08:04 0.9337
         Positions    Bid
3/11/2001 5:42:35 0.9330
> #### Data examination and cleaning ###
# Re-order data series
msftt.ts = reorderTS(msftt.ts)
Problem in sub(x.data, pos.order,  ): argument "x" is missing with no default
Use traceback() to see the call stack
数学好就是要天天学

40
zhangtao 发表于 2011-7-19 10:18:35
Problem in sub(x.data, pos.order,  ): argument "x" is missing with no default
以上这个错误不解决,程序无法继续进行,这个x.data是什么?有没有?如何创建?
## Moved utility functions to the HF Library
## The library has to be attached to run this script file
这个HFLibarary.SSC如何attached?

## Attach the FxLibrary
attach("D:\\Consulting\\FxLibrary", pos = 2, name = "FxLibrary")
这个FxLibary是什么,有什么用?原程序包中没有这个FxLibary,那儿有?
以上问题如果解决,估计程序就可以用了。
数学好就是要天天学

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-9 19:28