Skip to content

Instantly share code, notes, and snippets.

@aronlindberg
Created February 15, 2015 16:14
Show Gist options
  • Save aronlindberg/c784405c3fa815bde48c to your computer and use it in GitHub Desktop.
Save aronlindberg/c784405c3fa815bde48c to your computer and use it in GitHub Desktop.
library(data.table)
# install.packages(c("data.table", "quantmod"))
library(data.table)
library(quantmod)
library(jsonlite)
item_title = "Obelisk"
item_id = "29668"
region_id = "10000002"
query_addr = paste0("http://public-crest.eveonline.com/market/",region_id,"/types/",item_id,"/history/")
market.json <- fromJSON(readLines(query_addr))
market.data.json <- data.table(market.json$items)
market.data <- market.data.json[,list(Date = as.Date(date),
Volume= volume,
High = highPrice,
Low = lowPrice,
Close =avgPrice[-1],
Open = avgPrice)]
n <- nrow(market.data)
market.data <- market.data[1:n-1,]
low_flag = quantile(market.data$Low,.25)/5
high_flag = quantile(market.data$High,.75)*5
market.data$Low[market.data$Low<=low_flag] <-min(market.data$Open,market.data$Close)
market.data$High[market.data$High>=high_flag] <-max(market.data$Open,market.data$Close)
market.data.ts <- xts(market.data[,-1,with=F], order.by=market.data[,Date], period=7)
chartSeries(market.data.ts,
name = item_title,
TA = "addBBands(15,2);addVo();addMACD(5,15,5);addRSI();addLines(h=30, on=4);addLines(h=70, on=4)",
subset = "last 12 weeks")
@aronlindberg
Copy link
Author

I think the problem here is simply that none of the values are as extreme as you specify them. Both market.data$Low[market.data$Low<=low_flag] and market.data$High[market.data$High>=high_flag] are empty because nothing matches the low_flag and high_flag cutoffs. You'll see that market.data$High>=high_flag and market.data$Low<=low_flag are FALSE for all values.

If you change the cutoffs, for example to low_flag = quantile(market.data$Low,.25) and high_flag = quantile(market.data$High,.75) there will be some matches (e.g. where market.data$Low<=low_flag is TRUE for some cases) and the replacement will happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment