楼主: 飘零的枫叶
51775 206

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

21
zhangtao 发表于 2011-7-17 17:46:26
20# epoh
非常感谢!
我想问下:R中有没有对高频数据和超高频数据进行分析的包?
                   另外,对金融数据进行小波分析的包是那一个?
数学好就是要天天学

22
epoh 发表于 2011-7-17 19:10:39
Package ‘wavelets’
  A package of funtions for computing wavelet filters,
  wavelet transforms and multiresolution analyses


High-Frequency Financial Data
我没见过有 R package ,但s-plus有.
Analysis of High-Frequency Financial Data with S-PLUS
  http://faculty.washington.edu/ezivot/ezresearch.htm
  paper.pdf
  HFAnalysis.ssc
  HFLibrary.SSC.
  Data

%%%%%%%%%%%%%
刚下载高等数理统计
原来你说的Fisher information matrix是用在点估计
请看MS_NotesWeek9,MS_Tutorial8
   Barbara Bogacka.rar (235.85 KB)

2.2 Point Estimation
2.2.2 Comparing estimators
Estimators can be compared through their mean square errors. If they are unbiased,
this is equivalent to comparing their variances. In many applications, we
try to find an unbiased estimator which has minimum variance, or at least low
variance. We can compare the variances of several unbiased estimators, but how
do we know if we have found an estimator with the lowest variance among all
unbiased estimators?


The answer is given by Cram´er-Rao lower bound (CRLB).
and denominator is Fisher information matrix
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
zhangtao + 5 + 5 + 5 我很赞同

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

23
zhangtao 发表于 2011-7-18 14:19:45
22# epoh
尊敬的epoh老师,您好!
    我在splus8中先装入finmetrics后,然后再运行HFlibrary.SSCHFanalysis.ssc,均无法运行。我想问您一下:附件中的这些splus文件如何在splus中运行?
数学好就是要天天学

24
zhangtao 发表于 2011-7-18 14:47: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
数学好就是要天天学

25
zhangtao 发表于 2011-7-18 14:52:16
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

> # 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  
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
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  
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",
数学好就是要天天学

26
zhangtao 发表于 2011-7-18 14:52:55
+                                                 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
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
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      
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
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
> msftq.ts = reorderTS(msftq.ts)
Problem in sub(x.data, pos.order,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> get.ts = reorderTS(get.ts)
Problem in sub(x.data, pos.order,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> geq.ts = reorderTS(geq.ts)
Problem in sub(x.data, pos.order,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> eurusd.ts = reorderTS(eurusd.ts)
Problem in sub(x.data, pos.order,  ): argument "x" is missing with no default
Use traceback() to see the call stack
>
> ## Plot data by days
> par(mfrow = c(3,3))
> plotByDays(ts = msftt.ts, coltoplot = "Price", days.max = 7)
Problem in substituteString(pattern ..: pattern
should be a single character string, length is 8

Use traceback() to see the call stack
Problem in substituteString(pattern ..: pattern should be a single character string, length is 8
Use traceback() to see the call stack
>
> par(mfrow = c(3,3))
> plotByDays(ts = eurusd.ts, coltoplot = 1, days.max = 7)
Problem in substituteString(pattern = pattern, replacement = replac..: pattern should be a single character str
ing, length is 3
Use traceback() to see the call stack
>
> ## Time interval restrictions
>
> msftt.ts = ExchangeHoursOnly(ts = msftt.ts,
+                   exch.hours = c("9:30", "16:00"), start.include = T, close.include = T)
Problem in sub(ts@data, idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> msftq.ts = ExchangeHoursOnly(ts = msftq.ts,
+                   exch.hours = c("9:30", "16:00"), start.include = T, close.include = T)
Problem in sub(ts@data, idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> get.ts = ExchangeHoursOnly(ts = get.ts,
+                   exch.hours = c("9:30", "16:00"), start.include = T, close.include = T)
Problem in sub(ts@data, idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> geq.ts = ExchangeHoursOnly(ts = geq.ts,
+                   exch.hours = c("9:30", "16:00"), start.include = T, close.include = T)
Problem in sub(ts@data, idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
>
数学好就是要天天学

27
zhangtao 发表于 2011-7-18 14:53:15
par(mfrow = c(3,3))
> plotByDays(ts = msftt.ts, coltoplot = "Price", days.max = 7)
Problem in substituteString(pattern = pattern, replacement = replac..: pattern should be a single character str
ing, length is 8
Use traceback() to see the call stack
>
>
>
> eurusd.ts = FxBizWeekOnly(eurusd.ts, bizweek.hours = c("22:00", "22:00"),
+                                                                  start.include = T, close.include = T)
Problem in sub(ts@data, idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> par(mfrow = c(2,3))
> plotByDays(ts = eurusd.ts, coltoplot = 1)
Problem in substituteString(pattern = pattern, replacement = replac..: pattern should be a single character str
ing, length is 3
Use traceback() to see the call stack
>
>
> ####################### Section 3 Data Manipulation and Characterization ###################
>
> ##### 3.1 Construction of Market Variables ########
> ## 3.1.1 Computing price changes of MSFT prices and USD/EUR bid quotes
> args(PriceChgInInterv)
function(x, ticksize = NULL, interv.type = "daily", bound.hours = c("9:30", "16:00"))
NULL
> pcTicks.msft = PriceChgInInterv(msftt.ts[, "Price"], ticksize = 1/8,
+                                                  interv.type = "daily", bound.hours = c("9:30", "16:00"))
Problem in sub(ts@data, idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
>
> pcTicks.eurusd = PriceChgInInterv(eurusd.ts[, "Bid"], ticksize = 0.0001,
+                                                  interv.type = "weekly", bound.hours = c("22:00", "22:00"))
Problem in sub(ts@data, idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
>
>
>
> ## 3.1.2 Computing durations of MSFT trades and USD/EUR quotes
> args(DurationInInterv)
function(x, units = "seconds", interv.type = "daily", bound.hours = c("9:30", "16:00"))
NULL
> duration.msftt = DurationInInterv(x = msftt.ts, units = "seconds", interv.type = "daily",
+                                                                                 bound.hours = c("9:30", "16:00"))
Problem in sub(ts@data, idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> duration.msftt[1:5,]
Problem: Object "duration.msftt" not found
Use traceback() to see the call stack
>
> duration.eurusd = DurationInInterv(x = eurusd.ts, units = "seconds", interv.type = "weekly",
+                                                                                 bound.hours = c("22:00", "22:00"))
Problem in sub(ts@data, idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> duration.eurusd[1:5,]
Problem: Object "duration.eurusd" not found
Use traceback() to see the call stack
>
> ## 3.1.3 Computing spreads of MSFT quotes and USD/EUR quotes
> args(getSpread)
function(ask, bid, ticksize = NULL)
NULL
> spread.msft = getSpread(ask = msftq.ts[, "Ask"], bid = msftq.ts[, "Bid"], ticksize = 1/8)
> # removing some bad rows with 0 bid or ask or 0 spread
> error.idx = seriesData(msftq.ts)[, "Ask"]==0 |
+                          seriesData(msftq.ts)[, "Bid"]==0 | seriesData(spread.msft)<1
> spread.msft = spread.msft[!error.idx,]
数学好就是要天天学

28
zhangtao 发表于 2011-7-18 14:53:35
spread.msft[1:5,]
        Positions Spread
5/1/1997 8:17:24 1     
5/1/1997 9:29:41 1     
5/1/1997 9:30:14 1     
5/1/1997 9:30:17 2     
5/1/1997 9:30:17 1     
>
> spread.eurusd = getSpread(ask = eurusd.ts[, "Ask"], bid = eurusd.ts[, "Bid"], ticksize = 0.0001)
> spread.eurusd[1:5,]
         Positions Spread
3/11/2001 1:07:46  5   
3/11/2001 1:07:52  5   
3/11/2001 1:07:57  5   
3/11/2001 1:08:04  5   
3/11/2001 5:42:35 10   
>
> ## 3.1.4 Computing trade direction of MSFT trades
> args(tradeDirec)
function(trade, mq, timeLag = "5s")
NULL
> mq.msft = getMidQuote(ask = msftq.ts[,"Ask"],
+              bid = msftq.ts[, "Bid"])
> trade.direc.msft = tradeDirec(trade = msftt.ts[, "Price"],
+                mq = mq.msft)
Problem in sub(trade@data, idx.trade,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> trade.direc.msft[1:5,]
Problem: Object "trade.direc.msft" not found
Use traceback() to see the call stack
>
> ## 3.1.5 Computing daily realized volatility for MSFT prices
> ## and USD/EUR mid quotes
> args(Genr.RealVol)
function(ts, interv.type = "daily", bound.hours = c("9:30", "16:00"), rv.span, rt.span, how.align = "before")
NULL
> rvDaily.msft = Genr.RealVol(ts = log(msftt.ts[, "Price"])*100, interv.type = "daily", bound.hours = c("9:30", "16:00"),
+                                                                 rv.span = timeSpan("6h30m"), rt.span = timeSpan("5m"))
Problem in sub(ts@data, !na.idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> rvDaily.msft[1:5,]
Problem: Object "rvDaily.msft" not found
Use traceback() to see the call stack
>
> ## get the mid quote of USD/EUR bid - ask quotes
> mq.eurusd = getMidQuote(ask = eurusd.ts[, "Ask"], bid = eurusd.ts[, "Bid"])
>
> rvDaily.eurusd = Genr.RealVol(ts = log(mq.eurusd)*100, interv.type = "weekly", bound.hours = c("22:00", "22:00"),
+                                                                 rv.span = timeSpan("24h"), rt.span = timeSpan("5m"))
Problem in sub(ts@data, !na.idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> rvDaily.eurusd[1:5,]
Problem: Object "rvDaily.eurusd" not found
Use traceback() to see the call stack
>
> ###### 3.2 Statistical Properties of Market Variables ######
> ## Summary stats of price changes
> summaryStats(pcTicks.msft)
Problem: Object "pcTicks.msft" not found
Use traceback() to see the call stack
> summaryStats(pcTicks.eurusd)
Problem: Object "pcTicks.eurusd" not found
Use traceback() to see the call stack
>
> ## Histograms of price changes
> pcFactor.msft = cut(seriesData(pcTicks.msft), breaks=c(min(pcTicks.msft), -3:2, max(pcTicks.msft)), include.lowest =T,
+                         labels = c("<= -3", paste(-2:2), ">= 3"), factor.result=T)
Problem: Object "pcTicks.msft" not found
Use traceback() to see the call stack
> pcFactor.eurusd = cut(seriesData(pcTicks.eurusd), breaks=c(min(pcTicks.eurusd), -6:5, max(pcTicks.eurusd)), include.lowest =T,
+                         labels = c("<= -6", paste(-5:5), ">= 6"), factor.result=T)
Problem: Object "pcTicks.eurusd" not found
Use traceback() to see the call stack
>
> par(mfrow = c(1,2))
> hist.factor(pcFactor.msft, prob = T, xlab = "Price Changes.MSFT",
+                                 main = "Histogram of MSFT\nTrading Price Changes in Ticks")
Problem: Object "pcFactor.msft" not found
Use traceback() to see the call stack
>
> hist.factor(pcFactor.eurusd, prob = T, xlab = "Price Changes.USD/EUR",
+                                 main = "Histogram of USD/EUR\nBid Quote Changes in Ticks")
Problem: Object "pcFactor.eurusd" not found
Use traceback() to see the call stack
>
>
> ## Summary stats of spreads
> summaryStats(spread.msft)

Sample Quantiles:
min 1Q median 3Q max
   1  1      1  1   3

Sample Moments:
  mean    std skewness kurtosis
1.198 0.4022    1.591    3.766

Number of Observations:  20234
> summaryStats(spread.eurusd)

Sample Quantiles:
min 1Q median 3Q max
   1  3      4  5  10

Sample Moments:
  mean   std skewness kurtosis
3.999 1.614   0.2786    3.057

Number of Observations:  127351
>
> ## Histograms of spreads
> par(mfrow = c(1,2))
> hist.factor(seriesData(spread.msft), prob = T, xlab = "Spread.MSFT",
+                                 main = "Histogram of MSFT\nSpread in Ticks")
>
> hist.factor(seriesData(spread.eurusd), prob = T, xlab = "Spread.USD/EUR",
+                                 main = "Histogram of USD/EUR\nSpread in Ticks")
>
> ## Summary Stats of durations
> summaryStats(duration.msftt)
Problem: Object "duration.msftt" not found
Use traceback() to see the call stack
Problem: Object "duration.msftt" not found
Use traceback() to see the call stack
> summaryStats(duration.eurusd)
Problem: Object "duration.eurusd" not found
Use traceback() to see the call stack
>
> ## Histograms of durations
> durFactor.msftt = cut(seriesData(duration.msftt), left.include=T,
+                                                 breaks=c(0:10, max(duration.msftt)), include.lowest =T,
+                                                 labels = c(paste(0:9), ">= 10"), factor.result=T)
Problem: Object "duration.msftt" not found
Use traceback() to see the call stack
> durFactor.eurusd = cut(seriesData(duration.eurusd), left.include=T,
+                                                 breaks=c(0:10, max(duration.eurusd)), include.lowest =T,
+                                                 labels = c(paste(0:9), ">= 10"), factor.result=T)
Problem: Object "duration.eurusd" not found
Use traceback() to see the call stack
数学好就是要天天学

29
zhangtao 发表于 2011-7-18 14:54:51
> par(mfrow = c(1,2))
> hist.factor(durFactor.msftt, prob = T, xlab = "Duration.MSFT",
+                                 main = "Histogram of MSFT\nTransaction Durations in Seconds")
Problem: Object "durFactor.msftt" not found
Use traceback() to see the call stack
>
> hist.factor(durFactor.eurusd, prob = T, xlab = "Duration.USD/EUR",
+                                 main = "Histogram of USD/EUR\nQuote Durations in Seconds")
Problem: Object "durFactor.eurusd" not found
Use traceback() to see the call stack
>
> ### Temporal dependence in price changes and bid-ask bounce
> ## Two-way classification table of lead-lag price changes
> pcLag.msft = pcTicks.msft[1:(nrow(pcTicks.msft)-1),]
Problem: Object "pcTicks.msft" not found
Use traceback() to see the call stack
> pcLead.msft = pcTicks.msft[2:nrow(pcTicks.msft),]
Problem: Object "pcTicks.msft" not found
Use traceback() to see the call stack
>
> pcLagFactor.msft = cut(seriesData(pcLag.msft), breaks=c(min(pcLag.msft), -1:0, max(pcLag.msft)), include.lowest =T,
+                         labels = paste("Lag.PC", c("-", "0", "+")), factor.result=T)
Problem: Object "pcLag.msft" not found
Use traceback() to see the call stack
> pcLeadFactor.msft = cut(seriesData(pcLead.msft), breaks=c(min(pcLead.msft), -1:0, max(pcLead.msft)), include.lowest =T,
+                         labels = paste("Lead.PC", c("-", "0", "+")), factor.result=T)
Problem: Object "pcLead.msft" not found
Use traceback() to see the call stack
>
> table(pcLagFactor.msft, pcLeadFactor.msft)
Problem: Object "pcLagFactor.msft" not found
Use traceback() to see the call stack
>
>
> #### 3.3 Calendar Patterns in Market Activities #######
>
> ### 3.3.1 Calendar patterns in volatility ###
>
> ## MSFT ##
> ## 5-min realized volatility ##
> rv5min.msft = Genr.RealVol(ts = log(msftt.ts[, "Price"])*100,
+                 interv.type = "daily", bound.hours = c("9:30", "16:00"),
+                 rv.span = timeSpan("5m"), rt.span = timeSpan("1m"))
Problem in sub(ts@data, !na.idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> rv5min.msft[1:5,]
Problem: Object "rv5min.msft" not found
Use traceback() to see the call stack
>
> # Average 5-min realized volatility across days
> args(SmoothAcrossIntervs)
function(ts, n.subinterv, n.interv, FUN)
NULL
> rv5min.ave.msft = SmoothAcrossIntervs(ts = rv5min.msft, n.subinterv = 78,
+                                    n.interv = 11, FUN = mean)
Problem: Object "rv5min.msft" not found
Use traceback() to see the call stack
> rv5min.ave.msft@title = "5-min Realized Volatility: MSFT\n(averaging across 11 trading days)"
Problem: Object "rv5min.ave.msft" not found
Use traceback() to see the call stack
>
> par(mfrow = c(1,2))
> # ACF of the 5-min realized volatility for MSFT
> acf.plot(acf(rv5min.msft, lag.max = 234, plot = F),
+      main = "ACF of 5-min Realized Volatility:\nMSFT (lags up to 3 days)")
Problem: Object "rv5min.msft" not found
Use traceback() to see the call stack
> # Plots of Calendar pattern in realized volatility for MSFT
> plot(rv5min.ave.msft, reference.grid = F,
+      x.axis.args = list(format.label = c("%H:%02M", "%Z"),
+                        time.of.day.style = "24:00"))
Problem: Object "rv5min.ave.msft" not found
Use traceback() to see the call stack
>
> ## USD/EUR ##
> ## 5-min realized volatility ##
> rv5min.eurusd = Genr.RealVol(ts = log(mq.eurusd)*100, interv.type = "weekly", bound.hours = c("22:00", "22:00"),
+                                                                 rv.span = timeSpan("5m"), rt.span = timeSpan("1m"))
Problem in sub(ts@data, !na.idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> rv5min.eurusd[1:5, ]
Problem: Object "rv5min.eurusd" not found
Use traceback() to see the call stack
>
> # Average 5-min realized volatility across days
> rv5min.ave.eurusd = SmoothAcrossIntervs(ts = rv5min.eurusd, n.subinterv = 288,
+                          n.interv = 5, FUN = mean)
Problem: Object "rv5min.eurusd" not found
Use traceback() to see the call stack
> rv5min.ave.eurusd@title = "5-min Realized Volatility: USD/EUR\n(averaging across 5 trading days)"
Problem: Object "rv5min.ave.eurusd" not found
Use traceback() to see the call stack
>
> par(mfrow = c(1,2))
> # ACF of the 5-min realized volatility for USD/EUR
> acf.plot(acf(rv5min.eurusd, lag.max = 864, plot = F),
+      main = "ACF of 5-min Realized Volatility:\nUSD/EUR (lags up to 3 days)")
Problem: Object "rv5min.eurusd" not found
Use traceback() to see the call stack
> # Plots of Calendar pattern in realized volatility for USD/EUR
> plot(rv5min.ave.eurusd, reference.grid = F,
+      x.axis.args = list(format.label = c("%H:%02M", "%Z"),
+                        time.of.day.style = "24:00"))
Problem: Object "rv5min.ave.eurusd" not found
Use traceback() to see the call stack
>
> ### 3.3.2 Calendar patterns in duration ###
> ## MSFT
> ## mean durations in 5-min intervals
> args(aggregateSeriesHF)
function(ts, interv.type = "daily", bound.hours = c("9:30", "16:00"), by, k.by, FUN, adj, drop.empty = F,
        ...)
NULL
> meanDur5min.msft = aggregateSeriesHF(duration.msftt, interv.type = "daily",
+                       bound.hours = c("9:30", "16:00"), FUN = mean,
+                      by = "minutes", k.by = 5, adj = 1, drop.empty = F, together = T)
Problem: Object "duration.msftt" not found
Use traceback() to see the call stack
> meanDur5min.msft[1:5,]
Problem: Object "meanDur5min.msft" not found
Use traceback() to see the call stack
>
> # averaging 5-min mean durations across trading days
> meanDur5min.ave.msft = SmoothAcrossIntervs(ts = meanDur5min.msft, n.subinterv = 78,
+                                    n.interv = 11, FUN = mean)
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))


>
数学好就是要天天学

30
zhangtao 发表于 2011-7-18 14:55:30
hist.factor(seriesData(spread.msft), prob = T, xlab = "Spread.MSFT",
+                                 main = "Histogram of MSFT\nSpread in Ticks")
>
> hist.factor(seriesData(spread.eurusd), prob = T, xlab = "Spread.USD/EUR",
+                                 main = "Histogram of USD/EUR\nSpread in Ticks")
>
> ## Summary Stats of durations
> summaryStats(duration.msftt)
Problem: Object "duration.msftt" not found
Use traceback() to see the call stack
Problem: Object "duration.msftt" not found
Use traceback() to see the call stack
> summaryStats(duration.eurusd)
Problem: Object "duration.eurusd" not found
Use traceback() to see the call stack
>
> ## Histograms of durations
> durFactor.msftt = cut(seriesData(duration.msftt), left.include=T,
+                                                 breaks=c(0:10, max(duration.msftt)), include.lowest =T,
+                                                 labels = c(paste(0:9), ">= 10"), factor.result=T)
Problem: Object "duration.msftt" not found
Use traceback() to see the call stack
> durFactor.eurusd = cut(seriesData(duration.eurusd), left.include=T,
+                                                 breaks=c(0:10, max(duration.eurusd)), include.lowest =T,
+                                                 labels = c(paste(0:9), ">= 10"), factor.result=T)
Problem: Object "duration.eurusd" not found
Use traceback() to see the call stack
>
> par(mfrow = c(1,2))
> hist.factor(durFactor.msftt, prob = T, xlab = "Duration.MSFT",
+                                 main = "Histogram of MSFT\nTransaction Durations in Seconds")
Problem: Object "durFactor.msftt" not found
Use traceback() to see the call stack
>
> hist.factor(durFactor.eurusd, prob = T, xlab = "Duration.USD/EUR",
+                                 main = "Histogram of USD/EUR\nQuote Durations in Seconds")
Problem: Object "durFactor.eurusd" not found
Use traceback() to see the call stack
>
> ### Temporal dependence in price changes and bid-ask bounce
> ## Two-way classification table of lead-lag price changes
> pcLag.msft = pcTicks.msft[1:(nrow(pcTicks.msft)-1),]
Problem: Object "pcTicks.msft" not found
Use traceback() to see the call stack
> pcLead.msft = pcTicks.msft[2:nrow(pcTicks.msft),]
Problem: Object "pcTicks.msft" not found
Use traceback() to see the call stack
>
> pcLagFactor.msft = cut(seriesData(pcLag.msft), breaks=c(min(pcLag.msft), -1:0, max(pcLag.msft)), include.lowest =T,
+                         labels = paste("Lag.PC", c("-", "0", "+")), factor.result=T)
Problem: Object "pcLag.msft" not found
Use traceback() to see the call stack
> pcLeadFactor.msft = cut(seriesData(pcLead.msft), breaks=c(min(pcLead.msft), -1:0, max(pcLead.msft)), include.lowest =T,
+                         labels = paste("Lead.PC", c("-", "0", "+")), factor.result=T)
Problem: Object "pcLead.msft" not found
Use traceback() to see the call stack
>
> table(pcLagFactor.msft, pcLeadFactor.msft)
Problem: Object "pcLagFactor.msft" not found
Use traceback() to see the call stack
>
>
> #### 3.3 Calendar Patterns in Market Activities #######
>
> ### 3.3.1 Calendar patterns in volatility ###
>
> ## MSFT ##
> ## 5-min realized volatility ##
> rv5min.msft = Genr.RealVol(ts = log(msftt.ts[, "Price"])*100,
+                 interv.type = "daily", bound.hours = c("9:30", "16:00"),
+                 rv.span = timeSpan("5m"), rt.span = timeSpan("1m"))
Problem in sub(ts@data, !na.idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> rv5min.msft[1:5,]
Problem: Object "rv5min.msft" not found
Use traceback() to see the call stack
>
> # Average 5-min realized volatility across days
> args(SmoothAcrossIntervs)
function(ts, n.subinterv, n.interv, FUN)
NULL
> rv5min.ave.msft = SmoothAcrossIntervs(ts = rv5min.msft, n.subinterv = 78,
+                                    n.interv = 11, FUN = mean)
Problem: Object "rv5min.msft" not found
Use traceback() to see the call stack
> rv5min.ave.msft@title = "5-min Realized Volatility: MSFT\n(averaging across 11 trading days)"
Problem: Object "rv5min.ave.msft" not found
Use traceback() to see the call stack
>
> par(mfrow = c(1,2))
> # ACF of the 5-min realized volatility for MSFT
> acf.plot(acf(rv5min.msft, lag.max = 234, plot = F),
+      main = "ACF of 5-min Realized Volatility:\nMSFT (lags up to 3 days)")
Problem: Object "rv5min.msft" not found
Use traceback() to see the call stack
> # Plots of Calendar pattern in realized volatility for MSFT
> plot(rv5min.ave.msft, reference.grid = F,
+      x.axis.args = list(format.label = c("%H:%02M", "%Z"),
+                        time.of.day.style = "24:00"))
Problem: Object "rv5min.ave.msft" not found
Use traceback() to see the call stack
>
> ## USD/EUR ##
> ## 5-min realized volatility ##
> rv5min.eurusd = Genr.RealVol(ts = log(mq.eurusd)*100, interv.type = "weekly", bound.hours = c("22:00", "22:00"),
+                                                                 rv.span = timeSpan("5m"), rt.span = timeSpan("1m"))
Problem in sub(ts@data, !na.idx,  ): argument "x" is missing with no default
Use traceback() to see the call stack
> rv5min.eurusd[1:5, ]
Problem: Object "rv5min.eurusd" not found
Use traceback() to see the call stack
>
> # Average 5-min realized volatility across days
> rv5min.ave.eurusd = SmoothAcrossIntervs(ts = rv5min.eurusd, n.subinterv = 288,
+                          n.interv = 5, FUN = mean)
Problem: Object "rv5min.eurusd" not found
Use traceback() to see the call stack
> rv5min.ave.eurusd@title = "5-min Realized Volatility: USD/EUR\n(averaging across 5 trading days)"
Problem: Object "rv5min.ave.eurusd" not found
Use traceback() to see the call stack
>
> par(mfrow = c(1,2))
> # ACF of the 5-min realized volatility for USD/EUR
> acf.plot(acf(rv5min.eurusd, lag.max = 864, plot = F),
+      main = "ACF of 5-min Realized Volatility:\nUSD/EUR (lags up to 3 days)")
Problem: Object "rv5min.eurusd" not found
Use traceback() to see the call stack
> # Plots of Calendar pattern in realized volatility for USD/EUR
> plot(rv5min.ave.eurusd, reference.grid = F,
+      x.axis.args = list(format.label = c("%H:%02M", "%Z"),
+                        time.of.day.style = "24:00"))
Problem: Object "rv5min.ave.eurusd" not found
Use traceback() to see the call stack
>
> ### 3.3.2 Calendar patterns in duration ###
> ## MSFT
> ## mean durations in 5-min intervals
> args(aggregateSeriesHF)
function(ts, interv.type = "daily", bound.hours = c("9:30", "16:00"), by, k.by, FUN, adj, drop.empty = F,
        ...)
NULL
> meanDur5min.msft = aggregateSeriesHF(duration.msftt, interv.type = "daily",
+                       bound.hours = c("9:30", "16:00"), FUN = mean,
+                      by = "minutes", k.by = 5, adj = 1, drop.empty = F, together = T)
Problem: Object "duration.msftt" not found
Use traceback() to see the call stack
> meanDur5min.msft[1:5,]
Problem: Object "meanDur5min.msft" not found
Use traceback() to see the call stack
>
> # averaging 5-min mean durations across trading days
> meanDur5min.ave.msft = SmoothAcrossIntervs(ts = meanDur5min.msft, n.subinterv = 78,
+                                    n.interv = 11, FUN = mean)
数学好就是要天天学

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

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