[R-SIG-Finance] what's wrong with diff.zoo

mat matthieu.stigler at gmail.com
Sun Mar 7 13:46:21 CET 2010


Hi all

I have a strange output using diff.zoo, where diff reduces the dim 
object by more than 1:

See:
 >class(PPP)
[1] "zooreg" "zoo"  
 > frequency(PPP)
[1] 12
 > dim(PPP)
[1] 202   3
 > dim(diff(PPP))
[1] 67  3

#What is happening? Dim is not 201 3 as I would expect, like I get with ts:
 >dim(diff(as.ts(PPP)))
[1] 201   3

#Differentiation seems to be done only for selected months...
 > head(PPP)
          PriceIT   PriceUS ExRateUSIT
1973(1) 0.0000000 0.0000000  0.0000000
1973(2) 0.5089089 0.7017644  1.9819006
1973(3) 2.0202688 1.6298400  3.0273857
1973(4) 3.0153056 2.3202898 -0.6350275
1973(5) 4.4895300 3.0060137 -0.6944147
1973(6) 4.9761509 3.6870589 -1.6951727
 > head(diff(PPP))
           PriceIT   PriceUS ExRateUSIT
1973(4)  0.9950369 0.6904498 -3.6624133
1973(7)  0.4842643 0.2259853  2.3995976
1973(10) 0.9478780 0.8810579 -0.1979420
1974(1)  1.3730158 0.8620694 -6.4295795
1974(4)  1.2959112 0.4175387  0.2104218
1974(7)  2.4591418 0.8130157  0.9254661

#Series is from:
library(zoo)
source("priceLev.R") #see below

Thanks a lot for your help, I'm really stuck...

Mat

I had problems copy/paste this directly into R console, but saving it as 
priceLev.R and sourcing it was ok:


PPP<-structure(c(19.60000038147, 19.70000076294, 20, 20.20000076294,
20.5, 20.60000038147, 20.70000076294, 20.70000076294, 21, 21.20000076294,
21.29999923706, 21.70000076294, 22, 22.39999961853, 23, 23.29999923706,
23.70000076294, 24.10000038147, 24.70000076294, 25.20000076294,
26, 26.5, 27, 27.10000038147, 27.5, 27.89999961853, 27.89999961853,
28.20000076294, 28.5, 28.79999923706, 28.89999961853, 29.10000038147,
29.29999923706, 29.70000076294, 30, 30.29999923706, 30.5, 31,
31.70000076294, 32.70000076294, 33.20000076294, 33.29999923706,
33.5, 33.79999923706, 34.40000152588, 35.59999847412, 36.29999923706,
36.79999923706, 37.29999923706, 38.09999847412, 38.79999923706,
39.20000076294, 39.70000076294, 40, 40.29999923706, 40.70000076294,
41.09999847412, 41.40000152588, 42.09999847412, 42.29999923706,
42.79999923706, 43.20000076294, 43.59999847412, 44.09999847412,
44.59999847412, 44.90000152588, 45.29999923706, 45.40000152588,
46.09999847412, 46.59999847412, 47, 47.40000152588, 48.29999923706,
48.90000152588, 49.70000076294, 50.40000152588, 51.09999847412,
51.59999847412, 52, 52.59999847412, 53.79999923706, 55.09999847412,
55.70000076294, 56.70000076294, 58.5, 59.59999847412, 60.20000076294,
61, 61.59999847412, 62.09999847412, 63.20000076294, 63.90000152588,
65.30000305176, 66.40000152588, 67.80000305176, 68.69999694824,
69.90000152588, 71.19999694824, 72.19999694824, 73.30000305176,
74.19999694824, 75, 75.69999694824, 76.19999694824, 77.30000305176,
78.69999694824, 80.09999847412, 80.90000152588, 82, 83.09999847412,
83.80000305176, 84.5, 85.5, 86.40000152588, 87.69999694824, 89.30000305176,
90.5, 92.30000305176, 93.5, 94.09999847412, 95.40000152588, 96.80000305176,
97.59999847412, 98.59999847412, 99.59999847412, 100.19999694824,
101.09999847412, 101.5, 102.80000305176, 104.5, 105.59999847412,
106.09999847412, 107.40000152588, 108.5, 109.19999694824, 110.09999847412,
110.69999694824, 111.30000305176, 111.69999694824, 112, 112.90000152588,
114, 114.69999694824, 115.40000152588, 116.59999847412, 117.80000305176,
118.69999694824, 119.69999694824, 120.40000152588, 121, 121.5,
121.69999694824, 122.19999694824, 123.69999694824, 124.5, 125.30000305176,
126, 126.80000305176, 127.30000305176, 127.59999847412, 128.10000610352,
128.60000610352, 128.60000610352, 128.89999389648, 129.19999694824,
130, 130.39999389648, 130.80000305176, 131.60000610352, 132.10000610352,
132.60000610352, 133, 133.5, 133.89999389648, 134.30000305176,
134.69999694824, 135.60000610352, 136.89999389648, 137.19999694824,
137.5, 138.19999694824, 138.5, 139.19999694824, 139.60000610352,
140, 140.5, 140.89999389648, 141.5, 142.19999694824, 143.30000305176,
144.5, 145, 146.10000610352, 147.30000305176, 148, 149, 149.60000610352,
150.30000305176, 150.69999694824, 150.89999389648, 151.60000610352,
153.10000610352, 42.5999984741, 42.9000015259, 43.2999992371,
43.5999984741, 43.9000015259, 44.2000007629, 44.2999992371, 45.0999984741,
45.2000007629, 45.5999984741, 45.9000015259, 46.2000007629, 46.5999984741,
47.2000007629, 47.7999992371, 48, 48.5999984741, 49, 49.4000015259,
50, 50.5999984741, 51.0999984741, 51.5, 51.9000015259, 52.0999984741,
52.5, 52.7000007629, 52.9000015259, 53.2000007629, 53.5999984741,
54.2000007629, 54.2999992371, 54.5999984741, 54.9000015259, 55.2999992371,
55.5, 55.5999984741, 55.7999992371, 55.9000015259, 56.0999984741,
56.5, 56.7999992371, 57.0999984741, 57.4000015259, 57.5999984741,
57.9000015259, 58, 58.2000007629, 58.5, 59.0999984741, 59.5,
60, 60.2999992371, 60.7000007629, 61, 61.2000007629, 61.4000015259,
61.5999984741, 61.9000015259, 62.0999984741, 62.5, 62.9000015259,
63.4000015259, 63.9000015259, 64.5, 65.1999969482, 65.6999969482,
66, 66.5, 67.0999984741, 67.4000015259, 67.6999969482, 68.3000030518,
69.0999984741, 69.8000030518, 70.5999984741, 71.5, 72.3000030518,
73.0999984741, 73.8000030518, 74.5999984741, 75.1999969482, 75.9000015259,
76.6999969482, 77.8000030518, 78.9000015259, 80.0999984741, 81,
81.8000030518, 82.6999969482, 82.6999969482, 83.3000030518, 84,
84.8000030518, 85.5, 86.3000030518, 87, 87.9000015259, 88.5,
89.0999984741, 89.8000030518, 90.5999984741, 91.5999984741, 92.3000030518,
93.1999969482, 93.4000015259, 93.6999969482, 94, 94.3000030518,
94.5999984741, 94.5, 94.9000015259, 95.8000030518, 97, 97.5,
97.6999969482, 97.9000015259, 98.1999969482, 98, 97.5999984741,
97.8000030518, 97.9000015259, 97.9000015259, 98.5999984741, 99.1999969482,
99.5, 99.9000015259, 100.1999969482, 100.6999969482, 101, 101.1999969482,
101.3000030518, 101.9000015259, 102.4000015259, 102.5999984741,
103.0999984741, 103.4000015259, 103.6999969482, 104.0999984741,
104.5, 105, 105.3000030518, 105.3000030518, 105.3000030518, 105.5,
106, 106.4000015259, 106.9000015259, 107.3000030518, 107.5999984741,
107.8000030518, 108, 108.3000030518, 108.6999969482, 109, 109.3000030518,
109.5999984741, 109.3000030518, 108.8000030518, 108.5999984741,
108.9000015259, 109.5, 109.5, 109.6999969482, 110.1999969482,
110.3000030518, 110.4000015259, 110.5, 111.1999969482, 111.5999984741,
112.0999984741, 112.6999969482, 113.0999984741, 113.5, 113.8000030518,
114.4000015259, 115, 115.3000030518, 115.4000015259, 115.4000015259,
115.6999969482, 116, 116.5, 117.0999984741, 117.5, 118, 118.5,
119, 119.8000030518, 120.1999969482, 120.3000030518, 120.5, 121.0999984741,
121.5999984741, 122.3000030518, 123.0999984741, 123.8000030518,
124.0999984741, 124.4000015259, 124.5999984741, 125, 125.5999984741,
0.00170791273132914, 0.00174209951913706, 0.00176040845258218,
0.00169710137902025, 0.00169609381850337, 0.0016792046735684,
0.00171998616788486, 0.00174231201103162, 0.00176909737593850,
0.00176559905254172, 0.00169038840243291, 0.00164579257106955,
0.00154330508995765, 0.00152751052610713, 0.00156870134431149,
0.00157200571003395, 0.00158080266451816, 0.00153789372388514,
0.00155219247186651, 0.00152690408919378, 0.00151030025882740,
0.0014992053772286, 0.00149961004098130, 0.00151791138210253,
0.00155041165776418, 0.00156779122961396, 0.00158420865760686,
0.00157669023618497, 0.00159370176532851, 0.00159820997361459,
0.00153869820346857, 0.00149628918637955, 0.00147399143728242,
0.00147449127396179, 0.00147210366254964, 0.001464493321869,
0.00142450142450142, 0.00130210030432208, 0.00121129900062598,
0.00113710017662363, 0.00116759682220348, 0.00117799501854215,
0.00119430080008036, 0.00119360230910755, 0.00118369811305430,
0.00116840174992149, 0.00115540150202195, 0.00115210030473245,
0.00113720364788047, 0.00113269527966656, 0.00112759908181671,
0.00112640515330342, 0.00112790438476952, 0.00112949684031799,
0.00113300327052292, 0.00113319581068863, 0.0011317978765388,
0.00113530572839516, 0.00113879652617039, 0.00114160461084470,
0.00114689423295764, 0.00116189904399275, 0.00116919410456185,
0.00116440190827110, 0.00114880470740695, 0.00116339946972441,
0.00118040065178541, 0.00119520008695516, 0.00120499348594498,
0.00123169392646559, 0.00118570513198108, 0.00118629587872915,
0.00119550017935439, 0.00118989544621630, 0.00118880621116386,
0.00118580356321465, 0.00117439812096301, 0.00118280204099774,
0.00121919992832387, 0.00122189634673585, 0.00123260489724270,
0.00121119629142077, 0.00121119629142077, 0.00123289363839214,
0.00124269912368631, 0.00123459841491511, 0.00116349423223834,
0.00114169585595958, 0.00118600047471892, 0.00119730364063127,
0.00120260238929126, 0.00118009415111576, 0.00117420504297619,
0.00114409932379843, 0.00110000106750649, 0.00107040024502102,
0.00104718620797518, 0.000980613256761468, 0.000969649910456641,
0.000927867583147656, 0.000876370465502322, 0.000843525938422606,
0.000823295979829121, 0.000803735801681492, 0.000842027275228413,
0.000837303506576214, 0.00083921485467683, 0.000828939961655155,
0.000814186402967888, 0.000791652779081, 0.000773221759850004,
0.000756658609619449, 0.00077919851937074, 0.000736143901754949,
0.000723452890870574, 0.000718081299390519, 0.00070862183088102,
0.000694473409094806, 0.000680809361993181, 0.000714929155512817,
0.00072742616872993, 0.000714397961872782, 0.000699437666460164,
0.00068853453006531, 0.000681310291427974, 0.00066182213723944,
0.000652141291441826, 0.000629033682327389, 0.000623978237540331,
0.000631787746464218, 0.000615085574381394, 0.000599923208071712,
0.000585950087094921, 0.000600099611261314, 0.000619513417282865,
0.000610321768907887, 0.000589511431606801, 0.000590040105729007,
0.000571043507422813, 0.000561649461352701, 0.000534533528145891,
0.000526598495131594, 0.000536754233000383, 0.000522870343728599,
0.000513146818997007, 0.000489715964740451, 0.000481116189559779,
0.000506101044383357, 0.000503917974554817, 0.000511791668803899,
0.000526224404774398, 0.000533757489838498, 0.000525370111122406,
0.000560089149346125, 0.000570216463691828, 0.000583600817041144,
0.000601272286874565, 0.000629639672710148, 0.000645815416462228,
0.000641251743442265, 0.000654236179260713, 0.000652273182391623,
0.000676448079471965, 0.000704061753916339, 0.000709104198499191,
0.000720632404196826, 0.000713735141009144, 0.000724931887198181,
0.000759203418417369, 0.0007705703819913, 0.000765755403403666,
0.000773419154661628, 0.000774713326752632, 0.000759589821496392,
0.000747406521267597, 0.000743947953430204, 0.000762857979627377,
0.00076770719167874, 0.000807174154425746, 0.000830744187376882,
0.000821773713091906, 0.000800243277082303, 0.000806016075652368,
0.00080580827232252, 0.000794401024342725, 0.000765954804926349,
0.00073138978164888, 0.000715343373114671, 0.00071779778378185,
0.000738901704515748, 0.000769100631071927, 0.000771837212823204,
0.000743428098333353, 0.000737854892260688, 0.000728597449908925,
0.000728969211551167, 0.000706299507030033, 0.000697155593265228,
0.000731320244617571, 0.000722418082886736, 0.00071215938252162,
0.000730332160273162), .Dim = c(202L, 3L), .Dimnames = list(NULL,
    c("PriceIT", "PriceUS", "ExRateUSIT")), index = c(1973,
1973.08333333333, 1973.16666666667, 1973.25, 1973.33333333333,
1973.41666666667, 1973.5, 1973.58333333333, 1973.66666666667,
1973.75, 1973.83333333333, 1973.91666666667, 1974, 1974.08333333333,
1974.16666666667, 1974.25, 1974.33333333333, 1974.41666666667,
1974.5, 1974.58333333333, 1974.66666666667, 1974.75, 1974.83333333333,
1974.91666666667, 1975, 1975.08333333333, 1975.16666666667, 1975.25,
1975.33333333333, 1975.41666666667, 1975.5, 1975.58333333333,
1975.66666666667, 1975.75, 1975.83333333333, 1975.91666666667,
1976, 1976.08333333333, 1976.16666666667, 1976.25, 1976.33333333333,
1976.41666666667, 1976.5, 1976.58333333333, 1976.66666666667,
1976.75, 1976.83333333333, 1976.91666666667, 1977, 1977.08333333333,
1977.16666666667, 1977.25, 1977.33333333333, 1977.41666666667,
1977.5, 1977.58333333333, 1977.66666666667, 1977.75, 1977.83333333333,
1977.91666666667, 1978, 1978.08333333333, 1978.16666666667, 1978.25,
1978.33333333333, 1978.41666666667, 1978.5, 1978.58333333333,
1978.66666666667, 1978.75, 1978.83333333333, 1978.91666666667,
1979, 1979.08333333333, 1979.16666666667, 1979.25, 1979.33333333333,
1979.41666666667, 1979.5, 1979.58333333333, 1979.66666666667,
1979.75, 1979.83333333333, 1979.91666666667, 1980, 1980.08333333333,
1980.16666666667, 1980.25, 1980.33333333333, 1980.41666666667,
1980.5, 1980.58333333333, 1980.66666666667, 1980.75, 1980.83333333333,
1980.91666666667, 1981, 1981.08333333333, 1981.16666666667, 1981.25,
1981.33333333333, 1981.41666666667, 1981.5, 1981.58333333333,
1981.66666666667, 1981.75, 1981.83333333333, 1981.91666666667,
1982, 1982.08333333333, 1982.16666666667, 1982.25, 1982.33333333333,
1982.41666666667, 1982.5, 1982.58333333333, 1982.66666666667,
1982.75, 1982.83333333333, 1982.91666666667, 1983, 1983.08333333333,
1983.16666666667, 1983.25, 1983.33333333333, 1983.41666666667,
1983.5, 1983.58333333333, 1983.66666666667, 1983.75, 1983.83333333333,
1983.91666666667, 1984, 1984.08333333333, 1984.16666666667, 1984.25,
1984.33333333333, 1984.41666666667, 1984.5, 1984.58333333333,
1984.66666666667, 1984.75, 1984.83333333333, 1984.91666666667,
1985, 1985.08333333333, 1985.16666666667, 1985.25, 1985.33333333333,
1985.41666666667, 1985.5, 1985.58333333333, 1985.66666666667,
1985.75, 1985.83333333333, 1985.91666666667, 1986, 1986.08333333333,
1986.16666666667, 1986.25, 1986.33333333333, 1986.41666666667,
1986.5, 1986.58333333333, 1986.66666666667, 1986.75, 1986.83333333333,
1986.91666666667, 1987, 1987.08333333333, 1987.16666666667, 1987.25,
1987.33333333333, 1987.41666666667, 1987.5, 1987.58333333333,
1987.66666666667, 1987.75, 1987.83333333333, 1987.91666666667,
1988, 1988.08333333333, 1988.16666666667, 1988.25, 1988.33333333333,
1988.41666666667, 1988.5, 1988.58333333333, 1988.66666666667,
1988.75, 1988.83333333333, 1988.91666666667, 1989, 1989.08333333333,
1989.16666666667, 1989.25, 1989.33333333333, 1989.41666666667,
1989.5, 1989.58333333333, 1989.66666666667, 1989.75), class = c("zooreg",
"zoo"), frequency = 12)


sessionInfo()
R version 2.9.2 (2009-08-24)
x86_64-pc-linux-gnu

locale:
LC_CTYPE=fr_CH.UTF-8;LC_NUMERIC=C;LC_TIME=fr_CH.UTF-8;LC_COLLATE=fr_CH.UTF-8;LC_MONETARY=fr_CH.UTF-8;LC_MESSAGES=fr_CH.UTF-8;LC_PAPER=fr_CH.UTF-8;LC_NAME=fr_CH.UTF-8;LC_ADDRESS=fr_CH.UTF-8;LC_TELEPHONE=fr_CH.UTF-8;LC_MEASUREMENT=fr_CH.UTF-8;LC_IDENTIFICATION=fr_CH.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

other attached packages:
[1] zoo_1.6-2    rkward_0.5.1

loaded via a namespace (and not attached):
[1] grid_2.9.2      lattice_0.17-26 tools_2.9.2



More information about the R-SIG-Finance mailing list