Skip to content

Instantly share code, notes, and snippets.

@BernardOng
Created August 4, 2016 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BernardOng/a95f5335013afb221ae7d9cf3d78ddfc to your computer and use it in GitHub Desktop.
Save BernardOng/a95f5335013afb221ae7d9cf3d78ddfc to your computer and use it in GitHub Desktop.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Global functions
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
getStockXts <- function (tparm,tsers) {
# pass input string stock param, and xts series return the time series
if (tparm=="Adjusted") {
bbb <- cbind(tsers$Adjusted) }
else
bbb <- cbind(tsers$Volume)
return (bbb)
}
getWeatherXts <- function (tparm,tsers) {
# pass input string weather param, and xts series return the time series
if (tparm=="MaxTemp") {
bbb <- cbind(tsers$MaxTemp) }
else if (tparm=="MaxHum") {
bbb <- cbind(tsers$MaxHum) }
else if (tparm=="MaxWind") {
bbb <- cbind(tsers$MaxWind) }
else if (tparm=="MaxVis") {
bbb <- cbind(tsers$MaxVis) }
else if (tparm=="Cloud") {
bbb <- cbind(tsers$Cloud) }
else
bbb <- cbind(tsers$Rain)
return (bbb)
}
getCorrScore <- function (x) {
y <- ""
x <- round(x,digits=3)
if (x>=0.70) {
y <- "Very Strong Positive" }
else if (x<0.70 & x>=0.40) {
y <- "Strong Positive" }
else if (x<0.40 & x>=0.30) {
y <- "Moderate Positive" }
else if (x<0.30 & x>=0.20) {
y <- "Weak Positive"}
else if (x<0.20 & x>=0.01) {
y <- "Negligible" }
else if (x<0.01 & x>=(-0.01)) {
y <- "None" }
else if (x<(-0.01) & x>=(-0.19)) {
y <- "Negligible" }
else if (x<(-0.19) & x>=(-0.29)) {
y <- "Weak Negative" }
else if (x<(-0.29) & x>=(-0.39)) {
y <- "Moderate Negative" }
else if (x<(-0.39) & x>=(-0.69)) {
y <- "Strong Negative" }
else if (x<(-0.69)) {
y <- "Very Strong Negative" }
return (paste0(x*100,"% = ",y))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment