[R-SIG-Finance] help-time series

Yohan Chalabi chalabi at phys.ethz.ch
Mon Mar 2 17:44:48 CET 2009


>>>> "YR" == Yana Roth <yana.roth at yahoo.com>
>>>> on Mon, 2 Mar 2009 08:12:26 -0800 (PST)

   YR> Hello,
   YR> I am working with libraries
   YR>  
   YR> timeDate)
   YR> library(timeSeries)
   YR> library(tseries)
   YR> library(RODBC)
   YR> library(PerformanceAnalytics)
   YR> library(fTrading)
   YR>  
   YR> and try to convert returns to monthly returns. I think the
   YR> main problem that when it convert to time series object it
   YR> doesn't prroduce the right time format , therefore when I apply
   YR> monthly it doesnt read right the function.
   YR> Also when I converted data to csv it didn't help.
   YR> Anyway, I sen u the data and the code and output of error. I
   YR> would b thankfull if u could help.
   YR>  data<-read.xls(file=Prices.xls)

library(timeSeries) # have you updated your packages ??

# I prefer to load the data set from a csv files with ";" delimiter 
data <- read.csv("Prices.csv", sep = ";")

   YR> tdata<-as.timeSeries(data) doesn't work

tdata <- as.timeSeries(data) # does work ...

# or could have been done with
 
tdata <- readSeries("Prices.csv")

   YR> c(start(tdata), end(tdata))  #beginning and end of the time
   YR> series (it doesnt work)
   YR> library(fCalendar)

library(timeDate) # but already loaded by timeSeries !!!

   YR>
   YR> price.ts<-timeSeries(data=data,charvec=rownames(data),
   YR> format=%Y-%m-%d,units=colnames(data))
   YR>  
   YR> produce an error
   YR> Warning message:
   YR> In timeDate(charvec = charvec, format = format, zone = zone,
   YR> FinCenter = FinCenter) :
   YR>   'charvec' entries of different number of characters are
   YR> replaced by NA's
   YR>
   YR>  
   YR> tsret<-returns(price.ts)
   YR> head(tsret)
   YR> output
   YR>  2.621954e-05 -1.076771e-03 -0.0030647848  0.003368925
   YR> [2,] 2.621885e-05  8.432440e-04 -0.0003460069 -0.007477860
   YR> [3,] 2.621816e-05 -1.864423e-03  0.0022385116  0.005220514
   YR> [4,] 7.865036e-05  1.280149e-03  0.0002193982  0.015714158
   YR> [5,] 2.621541e-05  8.727527e-05  0.0014423604  0.001540914
   YR> [6,] 2.621472e-05 -2.186654e-03  0.0043773979 -0.009590629
   YR>
   YR> applySeries(tsret, by=monthly, FUN=sum)

# should be
applySeries(tsret, by = "monthly", FUN = colSums)


   YR> produce an error
   YR> Errore in midnightStandard(charvec, format) :
   YR>   'charvec' has non-NA entries of different number of
   YR> characters
   YR> Inoltre: Warning messages:
   YR> 1: In min(x) : no non-missing arguments to min; returning Inf
   YR> 2: In max(x) : no non-missing arguments to max; returning -Inf
   YR>  
   YR>  
   YR> thank you
   YR>
   YR>
   YR>
   YR>





-- 
PhD student
Swiss Federal Institute of Technology
Zurich

www.ethz.ch



More information about the R-SIG-Finance mailing list