[R-SIG-Finance] positions in timeSeries object
spencerg
spencer.graves at prodsyse.com
Sat May 9 22:17:21 CEST 2009
First you need to examine the results of each step to isolate the
problem.
When I tried to replicate your problem, I first replaced
"as.data.frame(scan(...))" with the following:
DF <- read.table('ibm1.txt', header=TRUE, sep='|')
I also replaced "df" by "DF", because "df" is the function for the
density of an F distribution, and I'd prefer not to mask that with a
data.frame.
After that, I solved the problem by studying the examples in the
help file for "timeDate".
To get there, however, I found that there were two functions
called "timeDate", in packages "timeDate" and "fCalendar". I found this
as follows:
library(RSiteSearch)
tD <- RSiteSearch.function('timeDate')
sum(tD$Function=='timeDate')
HTML(tD[tD$Function=='timeDate', ])
These two functions are probably identical, but I don't know that.
Hope this helps.
Spencer Graves
Sarkar, Arup wrote:
> Hi: I am trying the following code to incorporate positions in the time
> series object. Can some please help me.
>
>
>
> Data File Format:
>
>
>
> SYMBOL|DATE|EX|TIME|PRICE|SIZE|COND|CORR|G127
>
> IBM|11/03/2008|N|9:30:07|93.0800|73600|@|0|0
>
> IBM|11/03/2008|N|9:30:07|92.9700|500|@|0|0
>
> IBM|11/03/2008|N|9:30:07|93.1100|100|@|0|0
>
> IBM|11/03/2008|N|9:30:07|92.9700|100|@|0|0
>
> IBM|11/03/2008|N|9:30:07|92.8500|200|@|0|0
>
> IBM|11/03/2008|N|9:30:07|92.8200|100|@|0|0
>
> IBM|11/03/2008|N|9:30:08|92.7500|100|@|0|0
>
> IBM|11/03/2008|N|9:30:08|92.7500|100|@|0|0
>
> IBM|11/03/2008|N|9:30:08|92.7500|100|@|0|0
>
> IBM|11/03/2008|N|9:30:08|92.7500|100|@|0|0
>
> IBM|11/03/2008|N|9:30:08|92.7500|100|@|0|0
>
> IBM|11/03/2008|N|9:30:08|93.0000|100|@|0|0
>
>
>
> R script:
>
>
>
> ## Columns Names
>
> fields.list =
> list(Symbol="",Date="",Ex="",Time="",Price=0,Size=0,Cond="",Corr=0,G127=0)
>
> #create a data frame
>
> df =
> as.data.frame(scan(file="c:/ibm_1.txt",what=fields.list,sep="|",skip=1,multi
> .line=TRUE,strip.white=TRUE),stringsAsFactors=F)
>
> dates.tmp = timeDate(charvec = df[, "Date"])
>
> times.tmp = df[, "Time"]
>
> td.tmp = paste(dates.tmp,times.tmp, sep=" ")
>
> ans = timeSeries(data = df[, setdiff(colIds(df), c("Date","Time"))],pos =
> td.tmp)
>
>
>
> I am getting the following output when I am using the following command
> ans[1:5, ]
>
>
>
> Symbol Ex Price Size Cond Corr G127
>
> 1 "IBM" "N" "93.08" " 73600" "@" "0" "0"
>
> 2 "IBM" "N" "92.97" " 500" "@" "0" "0"
>
> 3 "IBM" "N" "93.11" " 100" "@" "0" "0"
>
> 4 "IBM" "N" "92.97" " 100" "@" "0" "0"
>
> 5 "IBM" "N" "92.85" " 200" "@" "0" "0"
>
>
>
> I want to have the following output, how can I achieve it. Any help is
> highly appreciated.
>
>
>
> Positions Symbol Ex Price Size Cond Corr G127
>
> "11/03/2008 9:30:07" "IBM" "N" "93.08" " 73600" "@" "0" "0"
>
> "11/03/2008 9:30:07" "IBM" "N" "92.97" " 500" "@" "0" "0"
>
> "11/03/2008 9:30:07" "IBM" "N" "93.11" " 100" "@" "0" "0"
>
> "11/03/2008 9:30:07" "IBM" "N" "92.97" " 100" "@" "0" "0"
>
> "11/03/2008 9:30:07" "IBM" "N" "92.85" " 200" "@" "0" "0"
>
>
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>
>
More information about the R-SIG-Finance
mailing list