Showing posts with label Stock-price-tcs. Show all posts
Showing posts with label Stock-price-tcs. Show all posts

Tuesday, October 8, 2019

Stock price TCS-R

Stock price TCS -R

getSymbols("TCS.NS", from="2004-01-01", to="2019-19-04")
> chartSeries(Cl(TCS.NS))
> addRSI()
> addMACD()
> addBBands()

tcs stock charts

> ret <- dailyReturn(Cl(TCS.NS), type='log')
Warning message:
In to_period(xx, period = on.opts[[period]], ...) :
  missing values removed from data
> par(mfrow=c(2,2))
> acf(ret, main="Return ACF");
> pacf(ret, main="Return PACF");
> acf(ret^2, main="Squared return ACF");
> pacf(ret^2, main="Squared return PACF")
tcs acf

> par(mfrow=c(1,1))
> m=mean(ret);s=sd(ret);
> par(mfrow=c(1,2))
> hist(ret, nclass=40, freq=FALSE, main='Return histogram');curve(dnorm(x,
+ mean=m,sd=s), from = -0.3, to = 0.2, add=TRUE, col="red")
tcs hist

> plot(density(ret), main='Return empirical distribution');curve(dnorm(x,mean=m,sd=s), from = -0.3, to = 0.2, add=TRUE, col="red")
tcs density

> par(mfrow=c(1,1))
> kurtosis(ret)
daily.returns 
     279.2544 
> plot(density(ret), main='Return EDF - upper tail', xlim = c(0.1, 0.2),
+      ylim=c(0,2));
> curve(dnorm(x, mean=m,sd=s), from = -0.3, to = 0.2, add=TRUE, col="red")
> plot(density(ret), xlim=c(-5*s,5*s),log='y', main='Density on log-scale')
Warning message:
In xy.coords(x, y, xlabel, ylabel, log) :
  101 y values <= 0 omitted from logarithmic plot
> curve(dnorm(x, mean=m,sd=s), from=-5*s, to=5*s, log="y", add=TRUE,
+       col="red")
> qqnorm(ret);qqline(ret);
Conclusion
> chartSeries(ret)

Black-Scholes formula-R

 Black-Scholes formula-R > BlackScholes <- function(TypeFlag = c("c", "p"), S, X, Time, r, b, sigma) { TypeFla...