-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update stochastics.R #63
base: master
Are you sure you want to change the base?
Conversation
added try.xts(HLC) in the SMI function
Why? What was this supposed to address? |
hi Joshua,
it does not solve a particular issue. anyway, in the *stoch* function there
is *try.xts*, so if *HLC *is a DF with dates, the *stoch*'s output will be
an xts, whereas the *SMI*'s output will be a DF.
Davide
…On 4 April 2018 at 12:27, Joshua Ulrich ***@***.***> wrote:
Why? What problem did this solve?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#63 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AZT7MrGvLmhNsDKA7u5kM6Tyk8RHIzxdks5tlKALgaJpZM4TGe-p>
.
|
Thanks for explaining! I can't confirm your claim with a simple example: library(quantmod) # for HLC
data(ttrc)
x <- ttrc
rownames(x) <- x$Date
x$Date <- NULL
hlc <- HLC(x)
# both of these should return a data.frame
str(stoch(hlc)) # error
str(SMI(hlc)) # matrix The output of both functions should be the same class as the input. But that is not the case for both... so it looks like you've uncovered a few issues. I would appreciate if you would take a look, but I can investigate if you don't. I would also greatly appreciate if you could add tests that catch these two cases (and any others you may uncover). Thanks! |
the error in
str(stoch(hlc))
is due to the function runMax and runMin: they do not return an xts if the
input is an xts deriving from a data.frame, even if there is the reclass
function at the end. try this:
DF <- ttrc
rownames(DF) <- DF$Date
DF <- DF['Close']
XTS <- try.xts(DF, error = as.matrix)
str(XTS)
str(runMax(DF)) # data.frame, even if it should be converted to an xts
str(runMax(XTS)) # data.frame, even if it is an xts
DT <- as.data.table(ttrc)
DT <- DT[, .(Date, Close)]
XTS2 <- try.xts(DT, error = as.matrix)
str(XTS2)
str(runMax(DT)) # xts
str(runMax(XTS2)) # xts
this is probably due to the fact that XTS has this attribute:
Original class: 'data.frame'
as you can see from the code below, stoch applied to a DF returns an error,
while it returns an xts when it is applied to a DT. on the other hand, the
function SMI doesn't know how to deal with a DF/DT with Date, and it will
always return a matrix (or an error if the column Date of the DT is
supplied).
library(data.table)
data(ttrc)
DF <- ttrc
rownames(DF) <- DF$Date
DF$Date <- NULL
DF$Open <- NULL
DF$Volume <- NULL
str(DF)
# DF is a data.frame containing cols High|Low|Close
str(stoch(DF)) # error
str(SMI(DF)) # matrix
DT <- as.data.table(ttrc)
DT[, c('Open', 'Volume') := NULL]
str(DT)
# DT is a data.table containing cols Date|High|Low|Close
str(stoch(DT)) # xts
str(stoch(DT[, c('High', 'Low', 'Close')])) # matrix
str(SMI(DT)) # error
str(SMI(DT[, c('High', 'Low', 'Close')])) # matrix
I hope I was able to clarify my point.
davide
…On 4 April 2018 at 13:08, Joshua Ulrich ***@***.***> wrote:
Thanks for explaining! I can't confirm your claim with a simple example:
library(quantmod) # for HLC
data(ttrc)
x <- ttrc
rownames(x) <- x$Datex$Date <- NULLhlc <- HLC(x)
# both of these should return a data.frame
str(stoch(hlc)) # error
str(SMI(hlc)) # matrix
The output of both functions should be the same class as the input. But
that is not the case for both... so it looks like you've uncovered a few
issues. I would appreciate if you would take a look, but I can investigate
if you don't. I would also greatly appreciate if you could add tests that
catch these two cases (and any others you may uncover). Thanks!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#63 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AZT7MoZpMl5CDIXTyk5Q0tXBB31A7cSOks5tlKmQgaJpZM4TGe-p>
.
|
added try.xts(HLC) in the SMI function