Renko Chart in R

I am trying to construct Renko Chart using the obtained from Yahoo finance and was wondering if there is any package to do so. I had a look at the most financial packages but was only able to find Candlestick charts.

For more information on Renko charts use the link given here


Solution 1:

Really cool question! Apparently, there is really nothing of that sort available for R. There were some attempts to do similar things (e.g., waterfall charts) on various sites, but they all don't quite hit the spot. Soooo... I made a little weekend project out of it with data.table and ggplot.


rrenko

There are still bugs, instabilities, and visual things that I would love to optimize (and the code is full of commented out debug notes), but the main idea should be there. Open for feedback and points for improvement.

Caveats: There are still case where the data transformation screws up, especially if the size is very small or very large. This should be fixable in the near future. Also, the renko() function at the moment expects a dataframe with two columns: date (x-axis) and close (y-axis).

Installation

devtools::install_github("RomanAbashin/rrenko")
library(rrenko)

Code

renko(df, size = 5, style = "modern") + 
    scale_y_continuous(breaks = seq(0, 150, 10)) +
    labs(x = "", y = "")

1

renko(df, size = 5, style = "classic") + 
    scale_y_continuous(breaks = seq(0, 150, 10)) +
    labs(x = "", y = "")

2

Data

set.seed(1702)
df <- data.frame(date = seq.Date(as.Date("2014-05-02"), as.Date("2018-05-04"), by = "week"),
                 close = abs(100 + cumsum(sample(seq(-4.9, 4.9, 0.1), 210, replace = TRUE))))

> head(df)
         date close
1: 2014-05-02 104.0
2: 2014-05-09 108.7
3: 2014-05-16 111.5
4: 2014-05-23 110.3
5: 2014-05-30 108.9
6: 2014-06-06 106.5

Solution 2:

I'm R investment developer, I used some parts of Roman's code to optimize some lines of my Renko code. Roman's ggplot skills are awesome. The plot function was just possible because of Roman's code.

If someone is interesting:

https://github.com/Kinzel/k_rrenko

It will need the packages: xts, ggplot2 and data.table

"Ativo" need to be a xts, with one of columns named "close" to work.

EDIT:

After TeeKea request, how to use it is simple:

"Ativo" is a EURUSD xts 15-min of 2015-01-01 to 2015-06-01. If the "close" column is not found, it will be used the last one.

> head(Ativo)
                       Open    High     Low   Close
2015-01-01 20:00:00 1.20965 1.21022 1.20959 1.21006
2015-01-01 20:15:00 1.21004 1.21004 1.20979 1.21003
2015-01-01 20:30:00 1.21033 1.21041 1.20982 1.21007
2015-01-01 20:45:00 1.21006 1.21007 1.20978 1.21002
2015-01-01 21:00:00 1.21000 1.21002 1.20983 1.21002
2015-01-02 00:00:00 1.21037 1.21063 1.21024 1.21037

How to use krenko_plot:

krenko_plot(Ativo, 0.01,withDates = F)

Link to image krenko_plot

Compared to plot.xts

plot.xts(Ativo, type='candles')

Link to image plot.xts

There are two main variables: size and threshold.

"size" is the size of the bricks. Is needed to run.

"threshold" is the threshold of new a brick. Default is 1.

The first brick is removed to ensure reliability.