# Maths & Statistics  Math can be beautiful....

x <- y <- seq(-4*pi, 4*pi, len = 27)

> r <- sqrt(outer(x^2, y^2, "+"))

> image(z = z <- cos(r^2)*exp(-r/6), col = gray((0:32)/32))

> image(z, axes = FALSE, main = "Math can be beautiful ...",

+ xlab = expression(cos(r^2) * e^{-r/6}))  par(mfrow = c(2, 1))

> x <- rchisq(1000, df = 4)

> hs <- hist(x, breaks = 15)

> hist3D(x = hs\$mids, y = 1, z = matrix(ncol = 1, data = hs\$density),

+ bty = "g", ylim = c(0., 2.0), scale = FALSE, expand = 20,

+ border = "black", col = "white", shade = 0.3, space = 0.1,

+ theta = 20, phi = 20, main = "3-D perspective")

> plotdev(xlim = c(-0.2, 1.2), ylim = c(-0.2, 1.2), theta = 45)

> ribbon3D(z = VV, scale = FALSE, expand = 0.01, bty = "g", phi = 20,

+ col = "lightblue", border = "black", shade = 0.2, ltheta = 90,

+ space = 0.3, ticktype = "detailed", d = 2, curtain = TRUE)

> pm <- par("mfrow")

>

> par(mfrow = c(2, 2))

> persp3D(z = volcano, main = "volcano", clab = c("height", "m"),

+ breaks = seq(80,200, by = 10))

> window()

Error in hasTsp(x) : argument "x" is missing, with no default

> persp3D(z = volcano, main = "volcano", clab = c("height", "m"),

+ breaks = seq(80,200, by = 10))

> persp3D(z = volcano, x = 1: nrow(volcano), y = 1:ncol(volcano),

+ expand = 0.3, main = "volcano", facets = FALSE, scale = FALSE,

+ clab = "height, m", colkey = list(side = 1, length = 0.5))

> V <- volcano[, seq(1, ncol(volcano), by = 3)] # lower resolution

> ribbon3D(z = V, colkey = list(width = 0.5, length = 0.5,

+ cex.axis = 0.8, side = 2), clab = "m")

> Vy <- volcano[seq(1, nrow(volcano), by = 3), ]

> ribbon3D(z = Vy, expand = 0.3, space = 0.3, along = "y",

+ colkey = list(width = 0.5, length = 0.5, cex.axis = 0.8))

>

> x <- seq(-pi, pi, by = 0.2)

> y <- seq(-pi, pi, by = 0.3)

> grid <- mesh(x, y)

> z <- with(grid, cos(x) * sin(y))

> par(mfrow = c(2,2))

> persp3D(z = z, x = x, y = y)

> persp3D(z = z, x = x, y = y, facets = FALSE, curtain = TRUE)

> ribbon3D(z = z, x = x, y = y, along = "xy", space = 0.3)

> hist3D(z = z, x = x, y = y, border = "black")

> par(mfrow = c(2, 2))

> x <- seq(1, nrow(volcano), by = 3)

> y <- seq(1, ncol(volcano), by = 3)

> Volcano <- volcano [x, y]

> ribbon3D(z = Volcano, contour = TRUE, zlim= c(-100, 200),

+ image = TRUE)

> persp3D(z = Volcano, contour = TRUE, zlim= c(-200, 200), image = FALSE)

> persp3D(z = Volcano, x = x, y = y, scale = FALSE,

+ contour = list(nlevels = 20, col = "red"),

+ zlim = c(-200, 200), expand = 0.2,

+ image = list(col = grey (seq(0, 1, length.out = 100))))

> persp3D(z = Volcano, contour = list(side = c("zmin", "z", "350")),

+ zlim = c(-100, 400), phi = 20, image = list(side = 350))

How to remove credit Risk -R

library(CreditRisk)

> mod <- at1p(V0 = 1, H0 = 0.7, B = 0.4, sigma = rep(0.1, 10), r = cdsdata\$ED.Zero.Curve,

+ t = cdsdata\$Maturity)

> mod

Maturity Vt Ht Survival

1 0.5 0.9986010 0.6976240 0.9999995

2 1.0 0.9976029 0.6955343 0.9996255

3 2.0 0.9966058 0.6920653 0.9879108

4 3.0 0.9976029 0.6899922 0.9591025

5 4.0 1.0008003 0.6894405 0.9227796

6 5.0 1.0070246 0.6909589 0.8853100

7 7.0 1.0276761 0.6995102 0.8159656

8 10.0 1.0789626 0.7256591 0.7312982

9 20.0 1.3152148 0.8498674 0.5596304

10 30.0 1.5496049 0.9620634 0.4666967

Default.Intensity

1 9.441670e-07

2 7.482850e-04

3 1.178826e-02

4 2.959447e-02

5 3.860755e-02

6 4.145252e-02

7 4.078282e-02

8 3.651696e-02

9 2.675447e-02

10 1.815970e-02

> plot(cdsdata\$Maturity, mod\$Ht, type = 'b', xlab = 'Maturity', ylab = 'Safety Level H(t)',

+ main = 'Safety level for different maturities', ylim = c(min(mod\$Ht), 1.5),

+ col = 'red')

> lines(cdsdata\$Maturity, mod\$Vt, xlab = 'Maturity', ylab = 'V(t)',

+ main = 'Value of the Firm \n at time t', type = 's')

> plot(cdsdata\$Maturity, mod\$Survival, type = 'b',

+ main = 'Survival Probability for different Maturity \n (AT1P model)',

+ xlab = 'Maturity', ylab = 'Survival Probability')

> matplot(cdsdata\$Maturity, mod\$Default.Intensity, type = 'l', xlab = 'Maturity',

+ ylab = 'Default Intensity')

> install.packages("devtools")   This is circle

library(gcookbook)

library(ggplot2)

library(igraph)

> par(mar=c(0,0,0,0))

> plot(g, layout=layout.fruchterman.reingold, vertex.size=8, edge.arrow.size=0.5,

+ vertex.label=NA)

>

> par(mar=c(0,0,0,0))

> plot(g, layout=layout.circle, vertex.size=8, vertex.label=NA > library(plot3D)

> D2_Wiener <- function() {

+ dev.new(width = 10, height = 4)

+ par(mfrow = c(1, 3), oma = c(0, 0, 2, 0))

+ for(i in 1:3) {

+ W1 <- cumsum(rnorm(100000))

+ W2 <- cumsum(rnorm(100000))

+ plot(W1,W2, type= "l", ylab = "", xlab = "")

+ }

+ mtext("2-dimensional Wiener-processes with no correlation",

+ outer = TRUE, cex = 1.5, line = -1)

+ }

> D2_Wiener() x <- timeCalendar()

> y <- rnorm(12)

> plot(x, y, type = "l")

> points(x, y, pch = 19, col = "red")

> plot(x, y, type = "l", xaxt = "n")

> axis.timeDate(1, at = x[c(1, 3, 5, 7, 9, 11)], format = "%b")

> axis.timeDate(1, at = x, format = "%Y")

> library("mgcv", lib.loc="C:/Program Files/R/R-3.5.0/library")

This is mgcv 1.8-23. For overview type 'help("mgcv-package")'.

Warning message:

package ‘nlme’ was built under R version 3.5.2

> library(mgcv)

> set.seed(0)

> f1 <- function(x) {exp(2 * x)}

> f2 <- function(x) {

+ 0.2*x^11*(10*(1-x))^6+10*(10*x)^3*(1-x)^10

+ }

> f3 <- function(x) {x*0}

> n<-200

> sig2<-4

> x0 <- rep(1:4,50)

> x1 <- runif(n, 0, 1)

> x2 <- runif(n, 0, 1)

> x3 <- runif(n, 0, 1)

> e <- rnorm(n, 0, sqrt(sig2))

> y <- 2*x0 + f1(x1) + f2(x2) + f3(x3) + e

> x0 <- factor(x0)

> b<-gam(y~x0+s(x1)+s(x2)+s(x3))

> plot(b,pages=1,seWithMean=TRUE)

> plot(b,pages=1,seWithMean=TRUE,clo=109)

There were 27 warnings (use warnings() to see them)

There were 50 or more warnings (use warnings() to see the first 50)

> termplot(b,terms="x0",se=TRUE)

> op <- par(mfrow=c(2,2),bg="blue")

> x <- 0:1000/1000

> for (i in 1:3) {

+ plot(b,select=i,rug=FALSE,col="green",

+ col.axis="white",col.lab="white",all.terms=TRUE)

+ for (j in 1:2) axis(j,col="white",labels=FALSE)

+ box(col="white")

+ eval(parse(text=paste("fx <- f",i,"(x)",sep="")))

+ fx <- fx-mean(fx)

+ lines(x,fx,col=2) ## overlay `truth' in red

+ }

> for (i in 1:3) {

+ plot(b,select=i,rug=FALSE,col="green",

+ col.axis="white",col.lab="white",all.terms=TRUE)

+ for (j in 1:2) axis(j,col="white",labels=FALSE)

+ box(col="white")

+ eval(parse(text=paste("fx <- f",i,"(x)",sep="")))

+ fx <- fx-mean(fx)

+ lines(x,fx,col=7) ## overlay `truth' in red

+ }

> for (i in 1:3) {

+ plot(b,select=i,rug=FALSE,col="green",

+ col.axis="white",col.lab="white",all.terms=TRUE)

+ for (j in 1:2) axis(j,col="white",labels=FALSE)

+ box(col="white")

+ eval(parse(text=paste("fx <- f",i,"(x)",sep="")))

+ fx <- fx-mean(fx)

+ lines(x,fx,col=9) ## overlay `truth' in red

+ }

> dat <- gamSim(1,n=400)

Gu & Wahba 4 term additive model

> b1 <- gam(y~te(x0,x1,x2,d=c(1,2),k=c(5,15))+s(x3),data=dat)

> plot(b1,pages=1)

> b1 <- gam(y~x0+s(x1,x2)+s(x3))

> op <- par(mfrow=c(2,2))

> plot(b1,all.terms=TRUE)

> par(op)

> op <- par(mfrow=c(2,2))

> plot(b1,all.terms=TRUE,scheme=1)

> par(op)

> op <- par(mfrow=c(2,2))

> plot(b1,all.terms=TRUE,scheme=c(2,1)) Mathematics is colours....... image2D (z = Oxsat\$val, margin = c(2, 3), x = Oxsat\$lat,

+ y = Oxsat\$depth, subset = (lon > 18 & lon < 23),

+ ylim = c(5500, 0), NAcol = "blue", zlim = c(0, 110),

+ xlab = "latitude", ylab = "depth, m")

> ImageOcean() + upper.panel=panel.pie, text.panel=panel.txt,

+ main="Correlogram of mtcars intercorrelations") > set.seed(1410)

> dsmall <- diamonds[sample(nrow(diamonds), 100), ]

> dsmall <- diamonds[sample(nrow(diamonds), 100), ]

> library("ggplot2", lib.loc="~/R/win-library/3.5")

Warning message:

package ‘ggplot2’ was built under R version 3.5.1

> library(ggplot2)

> dsmall <- diamonds[sample(nrow(diamonds), 100), ]

> qplot(carat, price, data = dsmall, shape = "apples")

> qplot(carat, price, data = diamonds, geom = c("point", "smooth"))

`geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'

> qplot(carat, price,col=303, data = diamonds, geom = c("point", "smooth"))

`geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'

> qplot(carat, price,col=411, data = diamonds, geom = c("point", "smooth"))

`geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'

> qplot(carat, price, data = dsmall, geom = c("point", "smooth"),

+ span = 1)

Warning: Ignoring unknown parameters: span

`geom_smooth()` using method = 'loess' and formula 'y ~ x'

> qplot(color, price / carat, data = diamonds, geom = "jitter",

+ alpha = I(1 / 5))

> qplot(carat, data = diamonds, geom = "density")

> qplot(carat, data = diamonds, geom = "density", colour = color)

> qplot(color, data = diamonds, geom = "bar", weight = carat) +

+ scale_y_continuous("carat")

> qplot(date, unemploy / pop, data = economics, geom = "line")

> year <- function(x) as.POSIXlt(x)\$year + 1900

> qplot(unemploy / pop, uempmed, data = economics,

+ geom = c("point", "path"))

> qplot(unemploy / pop, uempmed,col=78, data = economics,

+ geom = c("point", "path"))

> qplot(unemploy / pop, uempmed, data = economics,

+ geom = c("point", "path","green")) set.seed(1410)

> dsmall <- diamonds[sample(nrow(diamonds), 100), ]

>

> qplot(carat, price, data = diamonds)

>

> qplot(carat, price,col=101, data = diamonds)

>

> qplot(carat, price,col="red", data = diamonds)

>

> qplot(carat, price,col="green", data = diamonds)

> qplot(carat, price,col="yellow", data = diamonds)

> qplot(carat, price,col=125, data = diamonds)

> qplot(log(carat), log(price), data = diamonds)

>

> qplot(exp(carat), log(price), data = diamonds) library(nlme)

> p <- ggplot2(Oxboys, aes(age, height, group = Subject)) +

+ geom_line()

Error in ggplot2(Oxboys, aes(age, height, group = Subject)) :

could not find function "ggplot2"

> library(ggplot2)

> p <- ggplot(Oxboys, aes(age, height, group = Subject)) +

+ geom_line()

> p + geom_smooth(aes(group = Subject), method="lm", se = F)

>

> p + geom_smooth(aes(group = 1), method="lm", size = 2, se = F) Mathematics code

x <- runif(1000000)

> y <- runif(1000000)

> plot(x,y,pch=".",col="blue")

par(mfrow=c(2,2))

> x <- seq(0,2*pi,2*pi/100)

> y1 <- cos(x)

> y2 <- sin(x)

> y3 <- tan(x)

> plot(y1~x,type="l",main="cosine")

> plot(y2~x,type="l",main="sine")

> plot(y3~x,type="l",ylim=c(-3,3),main="tangent")

> x <- seq(0,1,0.01)

> y <- x^0.5

> plot(x,y,type="l",main="0<b<1")

> y <- x

> plot(x,y,type="l",main="b=1")

> y <- x^2

> plot(x,y,type="l",main="b>1")

> y <- 1/x

> plot(x,y,type="l",main="b<0") Repeat the following exercise six times and then discuss the results. Generate a random walk with drift, (1.4), of length n = 100 with δ = .01 and σw = 1. Call the data xt for t = 1, . . . , 100. Fit the regression xt = βt + wt using least squares. Plot the data, the mean function (i.e., µt = .01 t) and the fitted line, xbt = β t b , on the same graph. Discuss your results. The following R code may be useful:

> par(mfcol = c(3,2))

> for (i in 1:6){

+ x = ts(cumsum(rnorm(100,.01,1)))

+ reg = lm(x~0+time(x), na.action=NULL)

+ plot(x)

+ lines(.01*time(x), col="red", lty="dashed")

+ abline(reg, col="blue") }  CA Regression_notes.pdf CA ch_16_-_index_numbers.pdf Business Maths Test-1

Find the number of ways in which a selection and arrangement of 4 letters can be made from the word"MATHEMATICS"

As you'll be able to see there ar some letters(like M,T and A) during this word that is obtaining continual. So, whereas choosingthe letters for arrangement we must always take into account all the cases. At first, i'm Manibhushan make a case for a way tochoose letters for various cases and so later a way to prepare them.

We have eleven letters in "MATHEMATICS"

in which there ar

2 M's , 2 T's , two A's and alternative letters H,E,I,C,S ar single

Selection of the four letters(Combonation)

first case: 2 alike and alternative 2 alike

In this case we have a tendency to ar gonna choose the 2 letters that ar alike. we've got 3 selections M,T,A. Out of those, we've got to pick 2(Because we've got to pick four letters and choosing two alike letters means that choosing four letters). So, it will be wiped out 3C2 ways that

second case: 2 alike, 2 totally different

1 alike letter(which can mean 2 letters) will be chosen in 3C1 ways that and alternative two totally different letters will bechosen in 7C2 ways that.(as there'll be seven totally different letters).

So, 3C1*7C2 ways that

Third case: All ar totally different

This can be wiped out eightC4 ways that as there ar 8 totally different letters(M,T,A,H,E,I,C,S)

Arrangement:(permutation)

For the primary case, there'll be 2 alike letters. So, arrangement of those letters will be wiped out 4!/2!*2! ways that

For the second case, there'll be one alike letter and 2 totally different letters which might be organized in 4!/2! ways that

For the third case, all letters ar totally different thus it will be organized in 4! ways that

So, the ultimate answer are going to be

(3C2*4!/2!*2!) + (3C1*7C2*4!/2!) + (8C4*4!)

= 18+ 756 + 1680 ways that

=2454 ways CA_log_eqns_intro.pdf Untitled document C.A_maths LOGARITHM.pdf   Math classes introduces to the basic concepts of calculus,algebra,coordinate,statistics etc. knowledge.we organize and easy to understand a method more interactive than a Book& tutorial.

### Class Room Math Class Tutor    CA_log_eqns_intro.pdf     