2018年3月31日 星期六

JFE 1.2: Portfolio Backtesting

  1. Portfolio Backtesting here is basically based on R package fPortfolio. The method is designed for portfolio optimization, JFE provides more covariance estimators and GMVP strategy for backtesting. JFE offers a comprehensive computation(Backtesting All in One) for 6 covariance estimators combined with 2 strategies, which is a little bit time-consuming, 3-min for DJ30 dataset.
  2. To use this function, you must have a multivariate time series dataset with R format, xts is most encourgaed; and the file is saved in .RData or .rda.
  3. If the loaded data is price, then you have to pull down the menu and choose Transform Price Data, else, Load Returns Data.
  4. The Next-Month Advice is the output bottom is the assets weights suggestion computed by backtesting for the next period from the end of data. The rolling length is 1 month and estimation is 1 year, which are not allowed to change so far.
  5. Download the dataset DJ30.RData to practice, which is close price of Dow Jones 30 component Stocks.
While data inputting is done, click Backtesting button, and access the pane below. First of all, you have to "Pick 1 bench asset", if you choose "None", JFE will compute cross-section average as Bench. Secondly, you may pick asset(s) you do not need. The following 4 blocks are its specification, we offer 3 multivariate covariance estimators: sample covariance, Ledoit-Wolf Baysian Shrinkage and the one based on Student t distribution.


Clicking OK, we give out an output in R console, "Next-Month Advice" is the diversified portfolio suggested by backtesting.  For our dataset, it suggests more weights on DJI (Dow Jones Index) components. 


Whether the backtesting strategy is good enough to follow, we can check the graph below: the middle right one shows our optimized portfolio (red line) outperforms the bench one where we pick Russia (RTS), although drawdown is not satisfactory.

Clicking "Backtesting All in One" pop out the pane below. Users have only to pick assets and portfolio risk, including risk free rate and smooth lambda, it will give a comprehensive computation including two strategies (Tangency & GMVP) and 6 multivariate covariance estimators.  If dataset is not large, it may take roughly 3 minutes.  If the dataset is somewhat large, for example, 50-year daily with 100 assets, it is time-consuming.  In our experiment with parallel computation(Clusters), it takes 10 minutes.




JFE 1.2: Assets Selection

Assets Selection

  1. Assets Selection here is basically designed for International Assets Selection, which is based on, inequality of specific performance index, for example, Sharpe ratio.  Interested readers please refer to Bekaert and Hodrick(2009, International Financial Management, PP.466-468).  We provide more performance indices based on the R package PerformanceAnalytics.
  2. To use this function, you must have a multivariate time series dataset with R format, xts is most encourgaed; and the file is saved in .RData or .rda.
  3. If the loaded data is price, then you have to pull down the menu and choose Transform Price Data, else, Load Returns Data
  4. Download the dataset world20.RData to practice, which is 20 country price indices of MSCI world index.

JFE 1.2: Returns Analytics

Returns Analytics: Use IBM.RData to practice, if your dataset is price, choose "Transform Price Data" which calculates rate of change, so far, this version does not have long-horizon returns.



The functions listed in the menu are easy to handle, just as the same as Price Analytics.  We briefly explain the GARCH


Load IBM.RData and transform to daily returns.

GARCH specifies most rugarch's estimation options. The estimation outputs will be automatically saved as the circle in the graph. The features in rugarch are
(1) It offers 8 distribution (bottom left square), and 5 variance models specifications.
(2) whether fractional difference (arfima) is necessary. External regressors as the mean-equation or variance equation are also supported.
We also offer frequency conversion to assist more comparisons.

This plot is automatically generated

The estimation outputs will be automatically saved as the name: sGARCH_norm_11.RData. Users can load this file with object named by myFit. Hence, subsequent analysis can be flexible, for example
load("sGARCH_norm_11.RData")
library(rugarch)
library(xts)
round(slot(myFit,"fit")$matcoef,4) 
nyblom(myFit)
signbias(myFit)

plot(myFit,which="all") 

Check rugarch.pdf for more details of the functions.

JFE 1.2 Introduced and Price Analytics


New features of version 1.2 focus on the Returns Analytics, we add iClick visualization and univariate GARCH. 

JFE goes with "Just Finance and Econometrics" specializes the data-based analytics of financial decision. Installation is simple install.packages("JFE")   
It offers four Analytics Menus: Price, Returns, Assets Selection, and Portfolio Backtesting.  In the future, it will include highFreq (high frequency) and big data (bigData). 


At R console, typing two command lines execute JFE

JFE is menu-driven and designed as Analytics MENU, there are two main points while using this package: 
     (1) JFE requires all imported data be xts time series object and saved as .RData.  This restriction aims to make loading time series data simple.
     (2) Except File, each Analytics menu is independent and requires importing its own data. For illustration, IBM.RData for Price Analytics, world20.RData for Global Assets Selection, and DJ30.RData for Portfolio Backtesting
download links:
http://www.iclick-r.idv.tw/R_PkgDev/JFE/IBM.RData
http://www.iclick-r.idv.tw/R_PkgDev/JFE/world20.RData
http://www.iclick-r.idv.tw/R_PkgDev/JFE/DJ30.RData


======================================================================
======================================================================

Price Analytics: Download the dataset IBM.RData to practice.  It is very easy to implement, as long as data is successfully loaded. Each individual menu item ask choosing variable in the dataset.
 Select <Load Price Data> and choose IBM.RData, the following screen appears in R console


Select <Time series plot>




<Descriptive Stat> This function calls fBasics::basicStats to compute summary statistics





















Select <technical charting> This selection call package quantmod to draw technical charting for OHLC data.



Select <iClick Charting>  This selection calls package iClick to visualize asset price.
iClick menu
Calendar Heat Map


Calendar Plot 







2018年3月9日 星期五

Testing seasonal stochastic trend in panel data

Stochastic trend describes the randomness of  trend over time, from hypothesis testing, is also known as test for the presence of unit root. In R, the previous package for testing seasonal unit root is urca, however, the function hegy does not exist anymore.  The package pdR offers several functions to test seasonal unit in univariate time series and panel data, so far, the version of HEGY is offered.

To implement the simple seasonal unit root,
library(pdR)
data(inf_Q)
y<-inf_Q[,1]
hegy.ou t<- HEGY.test(wts=y, itsd=c(1,0,c(1:3)),regvar=0, selectlags=list(mode="aic", Pmax=12))

hegy.out$stats   #HEGY test statistics
names(hegy.out)  # HEGY objects, which can be called by using $, see below.
hegy.out$hegycoefs
hegy.out$regvarcoefs 

In panel data, we may
dataz<-inf_Q
itsd<-c(1,0,c(1:3))#itsd: i=intercept; t=trend; sd=seasonal dummy
Sel<-"bic" # "aic","bic", "signf".
pmax<-12 #Maximum lag length

## ipsHEGY is the main function calculating seasonal unit root in panel data.
OUT<-ipsHEGY(dataz,itsd,Sel,pmax,CIPS=FALSE)
OUT$P_HEGY
OUT$U_HEGY

# Simulation of critical values

Note.
1. HEGY goes with the paper, Hylleberg, S., Engle, R.F., Granger, C.W.J., and Yoo, B.S.(1990) Seasonal integration and cointegration. Journal of Econometrics,44, 215-238.
2. The original code is from, Javier Lopez-de-Lacalle (https://github.com/cran/uroot/blob/master/R/hegy.R), the theory of the panel version refers to
Otero, J., Smith, J., and Giulietti, M. (2005) Testing for seasonal unit roots in heterogeneous panels. Economics Letters,  86, 229-235.
Otero, J., Smith, J., and Giulietti, M. (2007) Testing for seasonal unit roots in heterogeneous panels in the presence of cross section dependence. Economics Letters, 86, 179-184.
Pesaran M. Hashem (2007) A simple panel unit root test in the presence of cross-section dependence.  Journal of Applied Econometrics, 22, 265-312.