• R Notes
  • 1 About
    • 1.1 Usage
    • 1.2 Render book
    • 1.3 Preview book
  • 2 RStudio
    • 2.1 Dark Theme
    • 2.2 Update R
      • 2.2.1 Update R on Mac
      • 2.2.2 Update R on Windows
      • 2.2.3 Caveats about updating R
    • 2.3 Packages Management
      • 2.3.1 Load packages
      • 2.3.2 Install packages
      • 2.3.3 Update packages
      • 2.3.4 Put your R package on GitHub
    • 2.4 Using Git with RStudio
    • 2.5 GitHub Copilot
    • 2.6 Save R Workspace
    • 2.7 Pane Layout
    • 2.8 Options
    • 2.9 R Startup
      • 2.9.1 .Rprofile
      • 2.9.2 .Renviron
    • 2.10 FAQ
  • 3 VS Code
    • 3.1 Keyboard shortcuts
    • 3.2 languageserver package
      • 3.2.1 Highlight Features:
      • 3.2.2 lintr
    • 3.3 Radian
      • 3.3.1 Configuration
    • 3.4 Plot Viewer
    • 3.5 R Debugger
    • 3.6 Emulating rstudioapi functions
    • 3.7 Work with Rmd
      • 3.7.1 Render book
      • 3.7.2 View book
    • 3.8 Extensions
    • 3.9 Jupyter Notebooks
    • 3.10 Render Jupyter notebook
      • 3.10.1 Code cell modes
      • 3.10.2 Keyboard shortcuts
      • 3.10.3 Insert Image
      • 3.10.4 View data frames
      • 3.10.5 Export Jupyter notebook
    • 3.11 Issues
    • 3.12 FAQ
  • 4 Rmd
    • 4.1 YAML metadata
      • 4.1.1 Top-level YAML metadata
      • 4.1.2 MathJax Options
      • 4.1.3 Document dependency
    • 4.2 Render Rmd
      • 4.2.1 Render a single document
      • 4.2.2 Render multiple documents as a website
    • 4.3 Chunk Options
      • 4.3.1 Commonly used chunk options
      • 4.3.2 External Config Files
      • 4.3.3 Hooks
    • 4.4 Print Verbatim R code chunks
      • 4.4.1 Verbatim inline code
      • 4.4.2 Verbatim R code chunks
    • 4.5 Rmd Basics
      • 4.5.1 Unnumbered Sections
      • 4.5.2 Knitting in the global environment
    • 4.6 Citations
      • 4.6.1 Bibliographies
      • 4.6.2 Bibliography placement
    • 4.7 Cross References
      • 4.7.1 Using bookdown
      • 4.7.2 Using the LaTeX Way
    • 4.8 Equations
      • 4.8.1 RStudio Equation Live Preview
    • 4.9 Theorems
    • 4.10 Figures
      • 4.10.1 Output directly to document
      • 4.10.2 Fixed fig.width
      • 4.10.3 Save and reload
      • 4.10.4 Control figure size
      • 4.10.5 Control output size
      • Latex symbols in Fig. caption
      • Refer to another figure in figure caption
    • 4.11 Tables
      • 4.11.1 knitr::kable
      • 4.11.2 Data frame printing
      • 4.11.3 Stargazer
      • 4.11.4 xtable
      • 4.11.5 kableExtra
      • 4.11.6 huxtable
    • 4.12 Rmd GitHub Pages
      • Project structure
      • _site.yml config
      • index.Rmd
      • R scripts
      • Workflow
      • CSS Style
  • 5 bookdown
    • 5.1 bookdown project structure
      • _output.yml
      • _bookdown.yml
      • index.Rmd
      • .Rmd files
    • 5.2 Rendering bookdown
      • 5.2.1 Rendering bookdown website
      • 5.2.2 Rendering bookdown book
    • 5.3 Toggle Visibility of Solutions
  • 6 Quarto
    • 6.0.1 Only re-render changed files
    • 6.1 Book Structure
    • 6.2 Course Folder Structure
    • 6.3 Code chunks
    • 6.4 Knitr Options
    • 6.5 PDF Options
      • 6.5.1 Title Margin
      • 6.5.2 Templates
      • 6.5.3 Add Appendices
      • 6.5.4 Add TOC
    • 6.6 HTML Theming
      • Custom Themes
      • Theme Options
    • 6.7 Render Quarto
      • In terminal
      • In VS Code
      • In R
    • 6.8 Cross References
      • Cross-references to Equations
    • 6.9 Equations
      • 6.9.1 Individual qmd file
      • 6.9.2 Quarto project
      • 6.9.3 Cross-referencing Equations
      • 6.9.4 Math delimiters
    • 6.10 Extensions
      • 6.10.1 Color Text
      • 6.10.2 Emoji
    • 6.11 Divs and Spans
      • 6.11.1 Block Attributes
      • 6.11.2 Inline Attributes
    • 6.12 Theorems
    • 6.13 Tables
    • 6.14 Raw Content
    • 6.15 Lists
    • 6.16 Callouts
      • 6.16.1 Nested Callouts
      • 6.16.2 Cross-reference Callouts
    • 6.17 Conditional Content
      • 6.17.1 Set up multiple profiles
      • 6.17.2 Conditional Code Blocks
    • 6.18 FAQ
  • 7 xaringan Presentation
    • 7.1 Render Slides
    • 7.2 Remark Markdown Basics
      • 7.2.1 Create a New Slide
      • 7.2.2 Slide Properties
      • 7.2.3 Add Attributes
    • 7.3 Math Environments
      • 7.3.1 Color equations
    • 7.4 Bullet list
      • 7.4.1 Ordered list with letters
    • 7.5 Tables
    • 7.6 Images
    • 7.7 Presenter Notes
    • 7.8 CSS and themes
    • 7.9 Smart Punctuation
    • 7.10 Working offline
    • 7.11 Parser
    • 7.12 xaringanExtra
    • 7.13 FAQ
  • 8 Basic R
    • 8.1 Data Input & Output
      • 8.1.1 Read Data
      • 8.1.2 Write Data
    • 8.2 Functions
      • 8.2.1 Inspecting Object Types and Structure
      • 8.2.2 Type of Variables
      • 8.2.3 Variable Scope
      • 8.2.4 Control Structures
    • 8.3 Basic R functions
      • 8.3.1 Workspace Management
      • 8.3.2 Data Display and Output
      • 8.3.3 Data Manipulation and Transformation
      • 8.3.4 Generate Random Seeds
      • 8.3.5 Draw random samples
      • 8.3.6 Fit a distribution
      • 8.3.7 Operation on list
    • 8.4 Data Splitting and Grouping
      • 8.4.1 The split() Function
      • 8.4.2 Split-and-Apply Operations
    • 8.5 *apply() Family
      • 8.5.1 Parallel version of apply function
      • 8.5.2 Related Functions
    • 8.6 Statistical Summary Functions
      • 8.6.1 The summary() Function
      • 8.6.2 User-defined summary function
      • 8.6.3 stargazer() function
      • 8.6.4 Box plot statistics
    • 8.7 Contingency Table
      • 8.7.1 Basic Frequency Counting
      • 8.7.2 Creating Contingency Tables
      • 8.7.3 Working with Arrays and Multi-dimensional Tables
      • 8.7.4 Flattening and Exporting Tables
      • 8.7.5 Table Visualization and Formatting
    • 8.8 Data Frame Operations
      • Column/Row-wise Operations
      • 8.8.1 Process NA values
    • 8.9 Matrix multiplication
    • 8.10 String Operations
  • 9 Tidyverse
    • 9.1 Basic operations on tibbles
      • 9.1.1 Check Unique Values
      • 9.1.2 Column Names
      • 9.1.3 Column Operations
      • 9.1.4 mutate
      • 9.1.5 Concatenate rows into a tibble
      • 9.1.6 Data Subsetting
      • 9.1.7 Indirection
      • 9.1.8 Dynamic Selection
      • 9.1.9 Merge
    • 9.2 Pipe Operator
      • 9.2.1 Native Pipe |>
    • 9.3 Categorical Variables
      • 9.3.1 Manipulate String Columns
      • 9.3.2 Factors
    • 9.4 Group and Apply Functions
      • 9.4.1 group_by()
      • 9.4.2 Subset rows
      • 9.4.3 Summarize
      • 9.4.4 split-apply-combine
      • 9.4.5 dplyr::group_modify()
  • 10 Graphics
    • 10.1 Multipanel Plot
      • 10.1.1 With Base R
      • 10.1.2 With cowplot package
    • 10.2 Goodlooking Colors
      • 10.2.1 Color models
      • 10.2.2 Base R functions to specify colors
      • 10.2.3 colorspace Package
      • 10.2.4 RColorBrewer
      • 10.2.5 Grey Scale
      • 10.2.6 viridis
      • 10.2.7 ggsci
      • 10.2.8 Generate and Show Color Palettes
      • 10.2.9 Color Interpolation
    • 10.3 Math Expression in Figures
    • 10.4 Control Graphics Devices
      • 10.4.1 Save PNG
    • 10.5 ggplot
      • 10.5.1 Wide table to Long table
      • 10.5.2 Dual y-axis plot
      • 10.5.3 aes()
      • 10.5.4 Continuous scales for data
      • 10.5.5 Add regression line
      • 10.5.6 Subplots / Faceting
      • 10.5.7 Parameters
      • 10.5.8 guides(), together with guide_legend()
      • 10.5.9 Template for multi-series
      • 10.5.10 grid.gedit()
    • 10.6 plot Raster data
      • 10.6.1 Add Patterns to Shapes
    • 10.7 Histogram
    • 10.8 QQ-plot
    • 10.9 Heatmap
  • 11 Time Series
    • 11.1 Date
    • 11.2 Process Data
      • 11.2.1 tidyquant
      • 11.2.2 From tibble to xts
    • 11.3 Portfolio Return
    • 11.4 Plot TS
      • 11.4.1 plot.xts
      • 11.4.2 autoplot
    • 11.5 Time Series Regression
      • 11.5.1 Lag Polynomial
  • 12 Regression
    • 12.1 OLS
      • 12.1.1 Get the coef estimates
      • 12.1.2 Covariance Matrix
      • 12.1.3 Model performance
      • 12.1.4 Diagnostic Plots
      • 12.1.5 Model Summary
      • 12.1.6 Dummy variable
      • 12.1.7 Prediction
    • 12.2 Panel
      • 12.2.1 Dynamic Panel
  • 13 Machine Learning
    • 13.1 Imbalanced datasets
      • 13.1.1 Downsampling and Upweighting
    • 13.2 Random Forest
      • Implementation in R
      • Imbalance Classification
    • 13.3 Neural Network
  • 14 Stata
    • 14.1 Basic syntax
      • 14.1.1 Package management
      • 14.1.2 Types and Declarations
      • 14.1.3 Create new variables
      • 14.1.4 Refer to a range of variables
      • 14.1.5 System Variables
      • 14.1.6 Matrix
      • 14.1.7 Factor Variables
      • 14.1.8 Time series varlists
      • 14.1.9 Labels
      • 14.1.10 Output format
    • 14.2 Data Manipulation
      • 14.2.1 Import and Export
      • 14.2.2 Save Estimation Results
      • 14.2.3 Stored Results
    • 14.3 Predict
    • 14.4 Forecast
      • 14.4.1 Essential Procedure
      • 14.4.2 Creates a new forecast model
      • 14.4.3 Add equations/identifies
      • 14.4.4 Solve the foreceast
      • 14.4.5 Use example: forecast a panel
    • 14.5 Panel
    • 14.6 Arellano-Bond Estimator
      • 14.6.1 xtabond Syntax
      • 14.6.2 Use Example
      • 14.6.3 Diagnostic Tests
      • 14.6.4 Predetermined Covariates
      • 14.6.5 Endogenous Covariates
      • 14.6.6 xtabond2
      • 14.6.7 xtdpd
      • 14.6.8 System GMM Estimation
    • 14.7 Common Correlated Effects Models
      • 14.7.1 Econometric model
      • 14.7.2 Estimation
      • 14.7.3 Long run effects
      • 14.7.4 Boostrap
  • Published with bookdown

R Notes

Chapter 11 Time Series

http://r-statistics.co/Time-Series-Analysis-With-R.html

Commonly used R packages for processing Financial data:

  • quantmod

  • quandl

  • tidyquant https://cran.r-project.org/web/packages/tidyquant/vignettes/TQ00-introduction-to-tidyquant.html

  • PerformanceAnalytics, zoo, xts

    • PerformanceAnalytics Charts and Tables Overview

      PA-charts.R

    • Github.io page by Carl and Peterson: https://timelyportfolio.github.io/PerformanceAnalytics/index.html

    • Brian Peterson’s PA website: https://braverock.r-universe.dev/PerformanceAnalytics