Technical analysis tools are widely used by professional portfolio managers and traders to help them decide on trading strategies and tactics. They are in great demand as well by amateur traders including apparently a huge number of housewives in Taiwan who are conversant with MACD and Bollinger bands.
This blog describes my effort in building a basic technical analysis app using Shiny/R platform in a relatively short period of time.
The App
The image on the right is a screenshot of the app. It is a single page app that has a sidebar which is an input area where you can specify what technical analyses you want to see. The right part of the screen is the output and it shows two graphs one on top of each other. These graphs show the tech analysis charts for the stocks, currencies or items ("Securities") that have been selected in the input sidebar.
The app is quite simple but provides a lot of flexibility as it was designed to handle up to two Securities at a time.
The app allows you to look at historical daily prices of the Securities and runs technical analyses on them including candlesticks, MACD, Bollinger Bands, and RSI. There is also an option to use log prices.
Prices are retrieved online courtesy of Yahoo! Finance.
Building The App
Building the app requires knowledge of R and Shiny.
Starting with a working knowledge of R, it took me about 25 working hours to build the app with the bulk of it spent on learning how to use Shiny and making mistakes programming in Shiny (maybe 12 to 16 hours). Layout and formatting also took some time to get right (5 to 7 hours). The actual core of the program to get it running actually took little time (only a few hours) as R and Shiny have many features and accompany packages that simplify the process of pulling in data and displaying the output.
Someone who is accomplished in R and Shiny can produce the app in a few hours.
The three main workhorses of the Shiny app are the quantmod package, the TTR (Technical Trading Rules) package and the CSS.
Quantmod provides access to Yahoo! Finance's database which is extensive and includes indices and securities of foreign markets as well. Quantmod also provides access to other databases including Google. The Shiny code is shown below.
data2 <- getSymbols(randomVals()[2], src = "yahoo", from = input$dates[1], to = input$dates[2], auto.assign = FALSE)
TTR provides the canned software to produce the technical charts given the data from Yahoo! Finance. Shiny code is shown below.
And CSS provides the canned formatting that makes your app look 5 times better! The Shiny code is shown below. A subdirectory named www has to be created containing the css file that has the theme of your choice which in this case is bootstrap.min.css from Bootswatch.com
theme = "bootstrap.min.css"
As you can see, all three are so simple to use yet so powerful.
Going Forward
My experience in building this Shiny app was very positive. I was awed both by how easy it is to get free financial data and by how easy it is to analyse the data using open sourced software and packages.
I could easily have expanded the choices for technical analysis in the app with just a few minutes of additional work but decided against it due to layout constraints. This is something I intend to do in the near future.
Now, go build your own technical analysis app!
About Author
Gregory Domingo
Built his career in the financial services industry (fixed income research and fixed income portfolio management) in New York. and moved back to the Philippines in 1995. Has been involved since then in senior management positions in both...