[R-SIG-Finance] RMetrics fBasics market data retrieval and timeSeries functionality still being maintained at all?
David-Michael Lincke
dlincke at lincke.net
Mon Aug 13 03:11:39 CEST 2007
Diethelm,
Thank you for your response. Asyt.ts in my example is a timeSeries object
constructed using yahooSeries(). Trying out the example you provided I get:
> IBM = yahooSeries("IBM")
trying URL
'http://chart.yahoo.com/table.csv?s=IBM&a=7&b=12&c=2006&d=7&e=12&f=2007&g=d&
x=.csv'
Content type 'text/csv' length unknown
opened URL
downloaded 12Kb
Read 250 items
Error in matrix(unlist(x2), byrow = TRUE, nrow = length(x2)) :
matrix: invalid 'ncol' value (< 0)
Error in .yahooSeries(symbols[1], from = from, to = to, nDaysBack =
nDaysBack, :
cannot get a slot ("data") from an object of type "character"
After applying the patch to yahooImport() that I posted in my initial
message the import works:
> IBM = yahooSeries("IBM")
trying URL
'http://chart.yahoo.com/table.csv?s=IBM&a=7&b=12&c=2006&d=7&e=12&f=2007&g=d&
x=.csv'
Content type 'text/csv' length unknown
opened URL
downloaded 12Kb
Read 250 items
Read 7 items
> colnames(IBM)
[1] "IBM.Open" "IBM.High" "IBM.Low" "IBM.Close" "IBM.Volume"
Given that plot() has been overloaded to deal with timeSeries objects I
would have expected it to have some default functionality when passed a
timeSeries object short of unceremoniously failing in a lower level function
call. I did not realize it only works on single columns/data series.
As for ohlcDailyPlot(), I checked the source code later on and realized that
it expects column names that are different from how the market data
retrieval functions construct their timeSeries objects. This is easily
adjusted for. However, it's not exactly a smooth solution from a design
point of view. Also, the documentation does not mention the need for an
explicit prior call to par(mfrow = c(2, 1)) for it to result in a proper
plot. But I guess maybe that's obvious to a more seasoned R user than me.
Anyway, thank you for pointing me in the right direction. The code in
yahooImport(), however, really is broken as you can clearly verify by taking
a look at the date format delivered by Yahoo which does not have spelled out
three letter month names as expected by the source code.
David
-----Original Message-----
From: Diethelm Wuertz [mailto:wuertz at itp.phys.ethz.ch]
Sent: Sunday, August 12, 2007 6:06 PM
To: David-Michael Lincke; r-sig-finance at stat.math.ethz.ch
Subject: Re: [R-SIG-Finance] RMetrics fBasics market data retrieval and
timeSeries functionality still being maintained at all?
David-Michael Lincke wrote:
> Is the functionality in the RMetrics fBasics package for market data
> retrieval and timeSeries object functionality still being maintained at
all?
>
> A quick test of mine
What is your test ? --- useless if you don't tell us what you have done
> showed that the Yahoo import functions don't work at
> all as they expect a different date format from what's being delivered.
>
This is wrong what you tell us.
Have you read the help pages ? --- I think definitely not.
yahooImport() is a function which delivers a web object of the download
with many
information which is helpful for downloading data on a regular time
schedule and to
store them in a database. Nota bene, there is a data slot which keeps
the timeSeries
object.
For simply downloading a time series, you should use the function
yahooSeries(). This
delivers a 'timeSeries' object.
Note, the download depends on the time format used by Yahoo. This has
changed a few
months ago, noticed on this mailing list. --- Therefore you should use a
recent version of
Rmetrics and you should also update your software on a regular base.
> Specifically the following changes are necessary in lines 24 to 28 of
> yahooImport:
>
>
>
> x2 = strsplit(x1[regexpr("-..-..,", x1) > 0], ",")
>
> x1 = matrix(unlist(x2), byrow = TRUE, nrow = length(x2))
>
> z = matrix(as.numeric(x1[, -1]), ncol = dim(x1)[2] -
>
> 1)
>
> rowNames = as.character(as.Date(x1[, 1]))
>
>
>
> Once that hurdle is taken, however, it seems that all plotting
functionality
> on timeSeries objects is broken as well:
>
>
>
No, definitely not ...
Try ...
IBM = yahooSeries("IBM")
colnames(IBM)
par(mfrow = c(1,1))
plot(IBM[, "IBM.Open"], type = "l")
lines(IBM[, "IBM.Close"],col = "red")
Rmetrics has also many tailored plotting functions, plot is only
used for univariate timeSeries objects, multivariate timeSeries
objects can be displayed using the additional functions lines()
and points()!
>
>> plot.timeSeries(asyt.ts)
>>
>
> Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ
>
>
>> lines.timeSeries(asyt.ts)
>>
>
> Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ
>
>
>> ohlcDailyPlot(asyt.ts)
>>
>
>
What is asyt.ts ? --- We can only help if you tell us what you have done ...
> Error in plotOHLC(X, origin = "1970-01-01", xlab = xlab[1], ylab =
ylab[1])
> : x is not a open/high/low/close time series
>
>
>
> If this first experience is representative of the state of things with
> RMetrics then I'm not sure this is worth pursuing any further and I'm
> probably better off sticking with Matlab.
>
I wan't comment this ....
ohlcDailyPlot() expects a timeSeries object with column names c("Open",
"High", "Low", "Close", "Volume")
They can be in any order, but the names must be exactly the column names
mentioned.
Try:
colnames(IBM) <- c("Open", "High", "Low", "Close", "Volume")
par(mfrow = c(2, 1))
ohlcDailyPlot(IBM)
... it works fine!
Diethelm
> David
>
>
> [[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