This post is part of a series of "learning everything with R: An R book list". You can clink on this link to see other relevant posts.

As R is more and more popular in the industry as well as in the academics for analyzing financial data. For people unfamiliar with R, this post suggests some books for learning financial data analysis using R. From our teaching and learning R experience, the fast way to learn R is to start with the topics you have been familiar with. Thus, the book list below suits people with some background in finance but are not R user. These books below will provide useful guidance for your R learning journey. Try to read and compare these books to find what really fits you.

Fundamental theories: Time series modeling with R

Book Cover Extracted summary
Book Title: Time Series Analysis and Its Applications
With R Examples

Author: Shumway, Robert H., Stoffer, David S.
This book presents a balanced and comprehensive
treatment of both time and frequency domain methods
with accompanying theory. Theory and methodology
are separated to allow presentations on different levels.
Book Title: Applied Time Series Analysis with R
Author: Wayne A. Woodward, Henry L. Gray, Alan C. Elliott
This book includes examples across a variety of fields,
develops theory, and provides an R-based software
package to aid in addressing time series problems
in a broad spectrum of fields.
Book Title: Analyzing Financial Data and
Implementing Financial Models Using R

Author: Clifford Ang
This book teaches students how to use R to analyze
financial data and implement financial models from
start (e.g., obtaining data) to finish (e.g.,
generating output expected for a particular analysis)
using real-world data
Book Title: Practical Time Series Forecasting with R:
A Hands-On Guide

Author: Galit Shmueli and Kenneth C. Lichtendahl
This book providea an applied approach to time-series
forecasting which is an essential component of predictive
analytics. This book also introduces popular forecasting
methods and approaches used in a variety of business applications.
Book Title: Modeling Financial Time Series with S-PLUS®
Author: Eric Zivot and Jiahui Wang
This book represents an integration of theory, methods
, and examples using the S-PLUS statistical modeling
language and the S+FinMetrics module to facilitate the
practice of financial econometrics. This is the first
book to show the power of S-PLUS for the analysis of
time series data.
Book Title: Time Series Analysis With Applications in R
Author: Jonathan D.Cryer and Kung-Sik Chan
This book presents an accessible approach to understanding
time series models and their applications. The new edition
devotes two chapters to the frequency domain
and three to time series regression models, models for
heteroscedasticity, and threshold models.
Book Title: Statistics and Data Analysis for Financial Engineering
Author: David Ruppert and David S. Matteson
This book contains an ideal blend of innovative
research and practical applications, tackles
relevant investor problems, and provides a
multi-disciplined approach, solving problems
from both fundamental and non-traditional methods
Book Title: Financial Analytics with R
Author: David Ruppert and David S. Matteson
This book give examples using financial markets and
economic data to illustrate important concepts.
R Labs with real-data exercises give students practice
in data analysis.
Book Title: R in Finance and Economics
Author: Abhay Kumar Singh and David E Allen
This book provides an introduction to the statistical software
R and its application with an empirical approach in finance
and economics. It is specifically targeted towards undergraduate
and graduate students. It provides beginner-level introduction
to R using RStudio and reproducible research examples.
Book Title: An Introduction to Analysis of Financial Data with R
Author: Ruey S. Tsay
This book explores basic concepts of visualization of financial
data. Through a fundamental balance between theory and
applications, the book supplies readers with an accessible approach
to financial econometric models and their applications to
real-world empirical research.
Book Title: Statistical Analysis of Financial Data in R
Author: René Carmona
Although there are many books on mathematical finance, few deal
with the statistical aspects of modern data analysis as applied
to financial problems. This textbook fills this gap by addressing
some of the most challenging issues facing financial engineers. It
shows how modern statistical techniques can be used in
the solutions of concrete financial problems.
Book Title: Multivariate Time Series Analysis
Author: Ruey S. Tsay
This book is the much anticipated sequel coming from one of
the most influential and prominent experts on the topic of time
series. Through a fundamental balance of theory and methodology,
the book supplies readers with a comprehensible approach to
financial econometric models and their applications to real-world
empirical research.
Book Title: Computational Finance
Author: Argimiro Arratia
This book teaches you how to use the statistical tools
and methods available in the free software R, for
processing and analyzing real financial data
Book Title: Forecasting: principles and practice
Author: Rob J Hyndman and George Athana­sopou­los
This textbook provides a comprehensive introduction to
forecasting methods and presents enough information about
each method for readers to use them sensibly.

Practice: Trading, option pricing, and portforlio optimization with R

Book Cover Extracted summary
Book Title: Automated Trading with R
Quantitative Research and Platform Development

Author: Christopher Conlan
This book has full source code and step-by-step
explanation for plug-and-play trading platform.
Platform can be used in brokerage-level simulation
or production before reading every chapter
Book Title: Option Pricing and Estimation of Financial Models with R
Author: Stefano M. Iacus
This book presents inference and simulation of stochastic process
in the field of model calibration for financial times series
modelled by continuous time processes and numerical option pricing.
It also introduces the bases of probability theory and goes on to
explain how to model financial times series with continuous models.
Book Title: Quantitative Trading with R
Author: Georgakopoulos, H.
This book offers a winning strategy for devising
expertly-crafted and workable trading models using
the R open source programming language, providing
readers with a step-by-step approach to understanding
complex quantitative finance problems and building
functional computer code.
Book Title: Mastering R for Quantitative Finance
Author: Edina Berlinger et al.
This book is organized as a step-by-step practical guide to
using R. Starting with time series analysis, you will also
learn how to forecast the volume for VWAP Trading.
Among other topics, the book covers FX derivatives,
interest rate derivatives, and optimal hedging.
Book Title: Numerical Methods and Optimization in Finance
Author: Manfred Gilli et al.
This book describes computational finance tools.
It covers fundamental numerical analysis and
computational techniques, such as option pricing,
and gives special attention to simulation
and optimization.
Book Title: Tools for Computational Finance
Author: Seydel, Rüdiger
This book covers on an introductory level the very
important issue of computational aspects of
derivative pricing.
Book Title: Financial Risk Forecasting
Author: Jon Danielsson
This book is a complete introduction to practical
quantitative risk management, with a focus on market
risk. It brings together the three key disciplines
of finance, statistics and modeling (programming)
Book Title: Financial Risk Modelling and Portfolio
Optimization with R, 2nd Edition

Author: Bernhard Pfaff
This book is a great collection of many R finance
package introductions. It will be especially useful
for the experienced financial data analysts. It also
provides a plethora of R code examples

Notice that the information above is directly collected from the publisher website and we just summarize it for you. Further details about these books can be assessed by clicking the links to the book publisher. If you would like to get a quick review of financial data analysis using R, see our recent presentation here.

Finally, since more and more books are published these years to address using R in financial data analysis, the book list above might not be comprehensive. You are very welcome to leave the comments below to tell us what we missed. We will try to add them to the list ASAP!

Page last updated on 25 Nov. 2016.

R is a great tool to visualize your data: it is free to use and has lots packages to make beautiful plots. In this post, we gonna teach you how to make time plots to visualize stock returns with data from Yahoo finance. For those not familiar with how to automatically download data from Yahoo Finance with R, we suggest that you take a look at our recent presentation.  Or just follow the steps bellow and copy the code and paste it to R console (RStudio is recommended).

Step 1: Setting the working environment

[code]# Setting the working environment -----------------------------------------
## Install packages for this tutorial
install.packages("quantmod",dependencies = T)
install.packages("PerformanceAnalytics",dependencies = T)
##Make sure R gives English outputs
Sys.setlocale(category = "LC_ALL", locale = "english")
##increase the threshold so R will not convert the ouput into scientific notation
options(scipen = 100)[/code]

Step 2: Loading Data from Yahoo Finance

We gonna extract US stocks prices (SP500) and Australian Stocks prices (ASX200) from Yahoo Finance with quanmod package. Notice that we further convert the daily prices into monthly with the command to.period.

SP500 <- getSymbolsundefined"^GSPC",from = "2000-01-01",to = "2016-08-31", auto.assign = FALSE) #Retrieve data for SP500 from yahoo finance
ASX200 <- getSymbolsundefined"^AXJO",from = "2000-01-01",to = "2016-08-31", auto.assign = FALSE)
M.SP500 <- to.periodundefinedSP500,period = "months")
M.ASX200 <- to.periodundefinedASX200,period = "months")[/code]

Step 3: Converting prices into returns

Here, we use adjusted closing prices which include the adjustments for divident payments and stock splits to calculate total returns or holding period returns. If you want to calculate price return or capital gains, you use closing prices

[code]price.M.SP500 <- M.SP500[,6]
Return.M.SP500 <- diff(log(price.M.SP500))[-1] #-1 is used to delete the NA value
price.M.ASX200 <- M.ASX200[,6]
Return.M.ASX200 <- diff(log(price.M.ASX200))[-1] #-1 is used to delete the NA value[/code]

Step 4: Draw the time plot!

chart.TimeSeries(cbind(Return.M.SP500,Return.M.ASX200),legend.loc="bottomleft",date.format ="%b-%Y",las = 2, ylab = "Returns",main = "Time Series Plot")[/code]

A little more

We can add grey shaded areas to the plot to mark the important period like the period of global financial crisis(set from 2007-01-31 to 2008-12-31 in this tutorial). This is done by using the arguments, period.areas and period.color.
[code]chart.TimeSeries(cbind(Return.M.SP500,Return.M.ASX200),legend.loc="bottomleft",date.format ="%b-%Y",las = 2, ylab = "Returns",main = "Time Series Plot",period.areas = c("2007-01-31::2008-12-31"),period.color = c("gray"))[/code]

你/妳知道這波退休金制度改革不只影響到軍公教,而是所有台灣人民的退休金嗎? 你/妳知道這波退休金制度改革將會對於世代間所得分配有重要影響嗎? 你/妳知道這波退休金制度改革是審議制,藉由人民參與討論直到2017年才會有正式官方版本嗎? 你/妳知道澳洲也正在進行退休金制度,且跟台灣有著不太相同的改革目標嗎? 退休金制度已經被各國視為能否維持財政永續和人民安定的重要力量,或許多看看他人的做法能帶給台灣一些新的想法。
退休金制度牽繫著每位勞動者的退休生活品質,最早退休金制度可追溯到1889年德國建立起年金保險體系,再到後來隨收隨付制(Pay as you go),此皆由政府負擔,視為國家福利的一部分,此時退休基金是完全的公有化。這種由國家稅收來照顧年長國民的制度,係以世代間所得分配的觀點來進行,年輕世代將部分所得經由政府轉給退休者,等到年輕一代退休再由下一代接棒投入工作所得。這樣的制度要能夠永續進行必須至少要幾個前提,第一個是勞動者平均薪資須大於或等於通貨膨脹,再者勞動人口要能維持或持續增長讓扶養比維持在適當比率,政府對於退休基金的提撥比率要足夠。但自1981年以來,由於人口老化和政府的稅收不足以支撐這個體系,很多國家已逐漸轉向退休金私有化(Pension privatization)制度,也就是由勞動者和雇者主要負擔未來退休生活,政府則轉為輔助者的角色。


在正式版本未出爐前,台灣或可參考鄰近先進國家的作法,特別是相似人口數的地區如澳洲,澳洲目前也在進行退休金改革,並已出現可供討論的版本。澳洲向來以福利國家著稱,但另一特色是澳洲更融合了開放市場,其退休金制度特色在於不分工作性質,雇主和員工定期提撥一定比例(目前為9%)的員工薪水至員工退休金帳戶,此退休金帳戶係由不同財務公司營運(據學者2012年統計,目前有200多家),員工可自行決定由哪家公司或自己營運退休金管理。這些定期投入的錢,等到員工退休後即可提領使用,跟台灣勞工或政府雇員目前可終身領取(勞工僅限於是勞保年金可終身領取,勞工退休金則是領完為止)不同的是,澳洲員工退休後僅能領取先前提撥的錢連同投資獲益的錢,這樣的制度學理上又稱Defined Contribution (DC),與美國401(k)類似。

不過,當員工或是無工作的國民的退休金不足以支付其退休生活時,澳洲國民可以向政府centrelink 請領老人年金(age pension);此外,針對收入較低且有退休金帳戶的國民(年收入37000以下),政府每年目前最高補助500澳幣到其退休金帳戶。因此我們可以看到澳洲退休制度並非完全仰賴員工本身的提撥,相當於與政府共同承擔國民老年後的退休生活支出。這概念相當於台灣2008年開辦的國民年金,但國民年金侷限於無工作者,且每月必須繳納保費。要注意的是澳洲老人年金並不需要繳交任何費用。我們整理一個表格如下以比較兩地之退休金制度差異


比較點 台灣 澳洲
對象 依不同工作性質有不同退休制度 不分工作性質
年金領取終止 無,終身領取 (但對勞工而言僅限於勞保年金) 直到退休金帳戶歸0
其他退休保障 未參與任何工作保險者可領取國民年金 退休金不足額者可向政府請領老人年金
薪資提撥率 依工作性質而有不同:
  • 勞工是6~12% (雇主強制6%,剩下6%依員工意願)
  • 軍公教12%(政府負擔提撥費用的65%)
  • 9%,預計2022年提高到12%
    退休基金管理 由政府組成委員會管理 由民間公司或自己管理收益
    改革重點 退休基金永續經營 檢視現行退休金制度是否能有效率地帶給成員最佳的結果
    改革進程 預計2017年3~5月完成報告送交政府 預計2020年完成報告送交政府,詳見此份報告第3頁

    從上表比較看來,對於個人退休金而言,澳洲傾向於讓國民承擔更多退休責任和風險(自選退休金營運方式),充分將退休基金私有化或個人化,人民有完全的退休金自主權,這種制度學理上稱確定提撥制(Defined contribution plan;DC),澳洲政府的角色相對退位很多,僅在當國民退休金不足時以老人年金補足。雖然台灣人民不論工作性質皆須提撥固定比率薪水至退休帳戶,但台灣則還是比較偏向由政府掌握人民退休金,不僅管理也負責退休金之營運,但人民最終拿到多少退休金取決於所約定退休辦法,這種制度又稱確定給付制(Defined benefit plan;DB)


    結語: 邁向適足退休金制度

    過去退休金制度著重於提撥率即退休金基金的投入,已有學者呼籲,應從退休金的適足與否來思考,即金額是否足以過有品質的退休金生活。從澳洲最近的改革來看,似乎也是朝向此方向發展,澳洲年金協會(The Association of Superannuation Funds of Australia, ASFA),已經研擬出幾個退休生活的標準,這樣的適足觀點正巧與過去筆者研究的教育財政適足不謀而合,畢竟人民真正關心的是最終的結果是否足夠支付退休生活。事實上,已經有相當的文獻進行個人退休金模擬試算,藉由統計模擬方法如Bootstrapping, Monte Carlo等,用各種投資組合,結合個人相關資訊如收入、提撥率等算出最終可能的退休金金額,從而評估是否適足。


    1. 本文更新於 2017.05.07
    2. 本文部分文字刊登於The Epic Times
    Zhang, L. -C. (2016, November 28). Comparing pension systems in Australia and Taiwan (Part 2), The Epic Times, p. B4. [In Chinese: 張良丞 (2016)。台灣與澳洲退休金制度之比較(下)] [Web version] [News paper version]
    Zhang, L. -C. (2016, October 28). Comparing pension systems in Australia and Taiwan (Part 1), The Epic Times, p. B4. [In Chinese: 張良丞 (2016)。台灣與澳洲退休金制度之比較(上)] [Web version] [News paper version]