Sep 22

#### R Code For Statistics and Finance: An Introduction

Posted by abiao at 19:28 | Code » Code site | Comments(6) | Reads(11156)
Statistics and Finance: An Introduction is a useful book emphasizing the applications of statistics and probability to finance, such as regression, ARMA and GARCH models, the bootstrapping, and nonparametric regression using splines. For an easier learning and application, the author also public the R codes and examples at http://www.stat.tamu.edu/~ljin/Finance/stat689-R.htm.

Possible interesting sections:
Fig 2.11 & R Code: Comparison on normal and heavy-tailed distributions.
Fig 2.12 & R Code: Survival function of a Pareto distribution with c=0.25 and a=1.1 and of normal and exp distribution on being greater than 0.25.
Fig4.1  &  R Code: Autocorrelation functions of AR(1) processes with r equal to 0.95 , 0.75,0.2 and -0.9
Fig4.2  &  R Code: Simulations of 200 Observations from AR(1) processes with various parameters. The white noise process is the same for all four AR(1) Processes.
Fig4.7  &  R Code: Time series plot of the 3 month Treasury bill rates, plot of first differences, and ACFs.  The data set contains monthly values of the 3 month rates from Jan 1950 until Mar 1996.
Model Fit Examples R Codes: Fit GE Daily log return using AR(1),AR(6), MA(2), ARMA(2,1) and log price using ARIMA(2,1,0) Model
Fig4.9  &  R Code: Time series plot of the daily GE log Prices with forecasts from an ARIMA(1,1,0) Model.
Fig5.3  &  R Code: Expected frontier and tangency portfolio with different r.
Fig5.4 : Efficient frontier (solid) plotted for N=3 assets.
Tangency portfolio with the constraints R Code:
R Code  Volatility smiles and polynomial regressionpage 283-284
Fig 8.15: Ratio of Log Return on a call to log return on the underlying stock. Page 291.
Fig 9.4 : Polynomial and spline estimates of forward rates of U.S. Treasury bonds.
Fig 10.5 : Actual efficient frontier for the sample (optimal) and bootstrap efficient frontier (achieved) for each of six bootstrap resamples.
Fig 10.6:  Results from 400 bootstrap resamples. For each resample, the efficient portfolio with a mean return of 0.012 is estimated. In the upper subplot, the actual mean return and standard deviation of the return are plotted as a small dot. The large dot is the point on the efficient frontier with mean return of 0.012.
Model Fit:
** R Code:  GARCH Model Fit, Page 373.
Tags:
Jul 7

#### Necessity to Explain CDS with A Regime Switching Model

Posted by abiao at 09:56 | Code » R/Splus | Comments(6) | Reads(12203)
Examining the determinants of credit default swap (CDS) spreads is a hot topic, CDS spread has displayed siginificant regime switching behaviour since the break of credit crisis, which can be seen from the old graph in the post Credit Default Spread and Historical Volatility

There are sound reasons to believe that CDS spreads keep high in the period of turbulence while stay stably low during most of quiet periods. To investigate if there is possible regime switch phenomenon, I run a three year rolling panel regression using CDSs of over 250 reference entities on several widely accepted explanatory variables including: leverage, volatility, treasury yield and the spread of three month Libor and repo rates, where the last variable is used to proxy liquidity risk. The coefficients for each variable is plotted below

the coefficients of leverage and treasury yields are changing but without clear regime pattern, on the contrary, the volatility, especially the liquidity effects are suggesting there may exist regime switching and the necessity to employ a Markov regime switch model to explain CDS spreads.

PS: a matlab markov regime switching package can be found here; the panel regression is done with the R package PLM at http://cran.r-project.org/web/packages/plm/vignettes/plm.pdf
Tags: ,
Jun 1

#### Using R in Excel

Posted by abiao at 08:20 | Code » R/Splus | Comments(1) | Reads(16933)
Got to know a very cool tool to use R in Excel named RExcel, basically it provides an integration solution such that users can get data, run command in Excel the same way as in R, which is presumably good and convenient to present results to your colleagues.

Check yourself a demo video at http://rcom.univie.ac.at/RExcelDemo/

Tags: ,
Apr 15

Posted by abiao at 09:10 | Code » R/Splus | Comments(1) | Reads(13089)
Some of you may hear that the new release of R 2.13.0 is out, with some Windows-specific changes to R 2.13.0:
file.exists() and unlink() have more support for files > 2GB;
A few more file operations will now work with >2GB files.
which could help us to relieve the worry of handling large datasets in R. An exciting post shows us how to speed up R code up to 4 times by using the new R compiler package.

http://cran.r-project.org/bin/windows/base/rw-FAQ.html#Does-R-run-under-Windows-Vista_003f
http://stackoverflow.com/questions/1401904/painless-way-to-install-a-new-version-of-r
Tags:
Apr 6

#### Implied Binomial Tree

Posted by abiao at 21:44 | Code » VBA/Excel | Comments(1) | Reads(18565)
Black Scholes model assumes stock price follows GBM with constant volatility, however, the market implied volatilities of stock options often show "the volatility smile", which decreases with the strike level, and increases with the time to maturity. There are various proposed extensions of this GBM model to account for "the volatility smile". One approach is the implied binomial tree technique proposed by Rubinstein (1994), in which the author assumes the stock prices are generated by a modified random walk where the underlying assets volatility depends on both stock price and time, therefore it is an modification of basic Binomial tree method.

Implied binomial tree uses the observable market option prices in order to estimate the implied distribution, to construct such a tree, optimization routine generally applies and technically it is more difficult than a basic Binomial tree. Here is a good paper implementing the implied binomial tree using an Excel spreadsheet without VBA. It demonstrates both the optimization needed to generate implied ending risk-neutral probabilities from a set of actual option prices and the backwards recursion needed to solve for the entire implied tree.