(This article was first published on

Yesterday, I wrote a post (in French) about short-selling in financial market since some journalists claimed that it was well-known that short -selling does increase volatility on financial market. Not only in French speaking journals actually, since we can read on http://www.forbes.com that « in a market with restrictions on short-selling, volatility is reduced ». But things are not that simple. For instance http://www.optionsatoz.com/ explains it from a theoretical point of view. But we can also look at the data. For instance, we can compare the stock price of **Freakonometrics - Tag - R-english**, and kindly contributed to R-bloggers)*Air China*, exchanged in Shanghai in blue (where short-selling is forbidden) and in Hong Kong in rouge (where short-selling is allowed), since @Igor gave me the tickers of those stocks

library(tseries)X<-get.hist.quote("0753.HK")Y<-get.hist.quote("601111.SS")plot(Y[,4],col="blue",ylim=c(0,30))lines(X[,4],col="red")

Z=read.table("http://freakonometrics.blog.free.fr/public/data/change-cny-hkd.csv",header=TRUE,sep=";",dec=",")D=as.Date(as.character(Z$date),"%d/%m/%y")z=as.numeric(Z$CNY.HKD)plot(D,z,type="l")X2=X[,4]for(t in 1:length(X2)){ X2[t]=X2[t]*z[D==time(X2[t])]} X2=X[,4]plot(Y[,4],col="blue",ylim=c(0,30))lines(X2,col="red")

RX=diff(log(X2))RY=diff(log(Y[,4]))Xgarch = garch(as.numeric(RX))SIGMAX=predict(Xgarch)Ygarch = garch(as.numeric(RY))SIGMAY=predict(Ygarch)plot(time(Y)[-1],SIGMAY[,1],col="blue",type="l")lines(time(X2)[-1],SIGMAX[,1],col="red")

moy.ew=function(x,r){ m=rep(NA,length(x)) for(i in 1:length(x)){ m[i]=weighted.mean(x[1:i], rev(r^(0:(i-1))))} return(m)} sd.ew=function(x,r,m){ sd=rep(NA,length(x)) for(i in 1:length(x)){ sd[i]=weighted.mean((x[1:i]-m[i])^2, rev(r^(0:(i-1))))} return(sd)} q=.97MX=moy.ew(RX,q)SX=sd.ew(RX,q,MX)MY=moy.ew(RY,q)SY=sd.ew(RY,q,MY)plot(time(Y)[-1],SY,col="blue",type="l")lines(time(X2)[-1],SX,col="red")

a=time(X2)[which(time(X2)%in%time(Y))]b=SY[which(time(Y)%in%time(X2))]- SX[which(time(X2)%in%time(Y))]n=length(a)a=a[-n];b=b[-n]plot(a,b,col="black",type="l")polygon(c(a,rev(a)),c(pmax(b,0),rep(0,length(a))), col="blue",border=NA)polygon(c(a,rev(a)),c(pmin(b,0),rep(0,length(a))), col="red",border=NA)

*price*, instead of looking at

*volatility*,

a=time(X2)[which(time(X2)%in%time(Y))]b=as.numeric(Y[which(time(Y)%in%time(X2)),4])- as.numeric(X2[which(time(X2)%in%time(Y))])n=length(a)a=a[-n];b=b[-n]plot(a,b,col="black",type="l")polygon(c(a,rev(a)),c(pmax(b,0),rep(0,length(a))), col="blue",border=NA)polygon(c(a,rev(a)),c(pmin(b,0),rep(0,length(a))), col="red",border=NA)

*good*thing.

To

**leave a comment**for the author, please follow the link and comment on his blog:**Freakonometrics - Tag - R-english**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...