Technical Analysis with R
Preface
Acknowledgement
Sturcture of the book
About Author
1
Introduction
1.1
What is R and RStudio?
1.2
Download
1.2.1
Download R
1.3
Using RStduio
1.4
Interactive console
1.5
Code Editor
1.6
Assignment
1.7
Hello World
1.8
Script and Data Files
1.9
Readability
2
Working with Data
2.1
Data Type
2.1.1
Logical
2.1.2
Integer
2.1.3
Numeric
2.1.4
Complex
2.1.5
Character
2.2
Data type conversion
2.2.1
Date
2.3
Data Structure
2.3.1
Vector
2.3.2
Factor
2.3.3
Matrix
2.3.4
Array
2.3.5
Dataframe
Exercise
2.3.6
List
2.4
Functions
2.4.1
Defining a function
Exercise
2.4.2
Assignment of function outputs
2.4.3
Help on function
2.4.4
Source code of a function
2.5
Financial Data
2.6
Data Management
2.6.1
Loading built-in dataset
2.6.2
Peeping Data
2.6.3
Sorting Data
2.6.4
Joining dataframes
2.6.5
Stacking Dataframe
2.6.6
Selecting Variables
2.6.7
Selecting Observation based on row number
2.6.8
Selecting Observation based on condition
2.6.9
Selecting Observation and Columns
2.6.10
Create New Column
2.6.11
Remove Duplicated Observation
2.6.12
Collapse Data by Group
2.7
Packages
2.7.1
dplyr package
2.7.2
reshape package
2.7.3
Application to World Bank Data
2.8
External Datasets
2.8.1
Working Directory
2.8.2
Import from CSV
2.8.3
Import from Stata
2.8.4
Import from Excel
2.8.5
Export to CSV
2.8.6
Export to xlsx
2.8.7
Export to Word: Knitr
2.8.8
Export Table: stargazer
3
Plotting
3.1
ggplot2 package
3.1.1
Qplot
3.1.2
ggplot
3.1.3
Aesthetic
3.1.4
Decoration
3.1.5
Basic themes
3.1.6
ggthemes package
3.1.7
Application: Worldbank
3.2
dygraphs package
3.2.1
Get Data Using Quantmod
3.2.2
Standard dynamic graph
3.2.3
Shading
3.2.4
Event line
3.2.5
Candle Chart
4
Statistical Analysis
4.1
Basic Statistics
4.2
Random number
4.3
Regression
4.3.1
Simple linear regression
4.3.2
Muliple linear regression
4.3.3
Interaction terms
4.3.4
Robust standard error
4.4
Time Series Analysis
4.4.1
Time Series data
4.4.2
Extensible Time Series Data
4.4.3
ARMA
4.4.4
GARCH
4.4.5
VAR
4.5
Panel Data
4.5.1
Clustering
4.5.2
Fixed Effect Model
4.6
Simulation
4.6.1
Random Walk
4.6.2
Roll Model
5
Programming
5.1
Logical statements
5.1.1
Relational Operators
5.1.2
Logical Operators
5.2
Conditional
Exercises
5.2.1
Application: Checking Data Type
5.2.2
Application: Missing data
5.3
Loop
5.3.1
While loop
5.3.2
For Loop over integers
5.3.3
Loop over vectors
5.3.4
Example: Technical Indicators
Exercise
5.4
Apply Family
5.4.1
apply
5.4.2
sapply and lapply
5.5
Reduce
5.5.1
On vector
5.5.2
On list
5.6
Tricks
5.6.1
Timing code
5.6.2
Suppress annoying message
5.6.3
All files names in a folder
6
Scrapping
6.1
PDF files
6.1.1
Offline pdf file
6.1.2
Online pdf file
6.1.3
Scrapping through massive download
6.2
Scrapping from Web
6.2.1
Wikipedia Table
6.2.2
Other Websites
7
Quantmod
7.1
Downloading data
7.2
Charting
7.3
Technical Indicators
7.3.1
Simple Moving Average
7.3.2
Exponential moving average
7.3.3
Bollinger band
7.3.4
Momentum
7.3.5
ROC
7.3.6
MACD
7.3.7
RSI
7.4
Charting with Indicators
7.4.1
Charting SMA
7.4.2
Charting EMA
7.4.3
Charting Bollinger band
7.4.4
Charting Momentum
7.4.5
Charting ROC
7.4.6
Charting MACD
7.4.7
Charting RSI
7.4.8
Charting Custom TA
7.5
Charting Price changes of two stocks
7.6
Performance Evaluation
7.7
Evaluating Trading Rules
7.7.1
Simple filter Buy
7.7.2
Simple fiter buy-sell
Exercise
7.7.3
An example using RSI
7.7.4
More efficient code
7.8
Combining two indicators: EMA and RSI
Exercise
7.9
Trading Size
7.10
Non-Day Trading
Exercise
8
Quanstrat
8.1
Install custom packages
8.2
Blotter Package
8.2.1
Buy and hold
8.2.2
Buy Filter Rule
8.3
Simple Filter Rule
8.3.1
Step 1: Initialization
8.3.2
Step 2: Define indicator
8.3.3
Step 3: Trading Signals
8.3.4
Step 4. Trading Rules
8.3.5
Step 5. Evaluation Results
8.4
Buy and Hold
8.4.1
Step 1: Initialization
8.4.2
Steps 2-4: Applying trading rule
8.4.3
Step 5: Evaluation
8.5
SMA Rule
8.5.1
Step 1: Initialization
8.5.2
Step 2: Indicator
8.5.3
Step 3: Signals
8.5.4
Step 4: Rules
8.5.5
Step 5: Evaluation
8.6
SMA rule with volatility filter
8.6.1
Step 1: Initialization
8.6.2
Step 2: Indicator
8.6.3
Step 3: Signals
8.6.4
Step 4: Rules
8.6.5
Step 5: Evaluation
9
Dynamic Report
9.1
Sweave: R code in LaTex
9.2
Knitr: Rmarkdown
10
Download pdf
Published with bookdown
Techincal Analysis with R
Chapter 6
Scrapping
We will cover two common ways to extract files that is not from database directly:
pdf files, and
html files.