require("readxl")
## Loading required package: readxl
## Warning: package 'readxl' was built under R version 3.5.3
require(RCurl)
## Loading required package: RCurl
## Warning: package 'RCurl' was built under R version 3.5.2
## Loading required package: bitops
url<-"http://mickael-clevenot.fr/wp-content/uploads/2019/11/CC_041119_data_fin_2019_cc12.xlsx"
download.file(url, destfile = "./Fin.xlsx",mode = 'wb')
getwd()
## [1] "C:/Users/Mickael/Documents/l3 info/R 2019"
setwd("C:/Users/Mickael/Documents/l3 info/R 2019")
CAC<- read_excel("./Fin2.xlsx")#
class(CAC)
## [1] "tbl_df"     "tbl"        "data.frame"
CAC1<-as.data.frame(CAC)#
head(CAC1)
##         date  CAC 40     GLE   SAN
## 1 2007-12-31 5614.08 88.3873 62.98
## 2 2008-01-02 5550.36 87.3420 62.28
## 3 2008-01-03 5546.08 87.3241 61.54
## 4 2008-01-04 5446.79 86.3949 61.10
## 5 2008-01-07 5452.83 86.5468 62.89
## 6 2008-01-08 5495.67 85.0905 65.45
tail(CAC1)
##            date  CAC 40    GLE   SAN
## 3009 2019-10-11 5665.48 25.255 82.05
## 3010 2019-10-14 5643.08 25.215 81.41
## 3011 2019-10-15 5702.05 25.750 82.45
## 3012 2019-10-16 5696.90 25.980 82.68
## 3013 2019-10-17 5673.07 26.030 83.72
## 3014 2019-10-18 5636.25 26.030 82.80
summary(CAC1)
##      date               CAC 40          GLE             SAN        
##  Length:3014        Min.   :2519   Min.   :15.00   Min.   : 37.92  
##  Class :character   1st Qu.:3712   1st Qu.:30.15   1st Qu.: 51.40  
##  Mode  :character   Median :4296   Median :38.91   Median : 71.64  
##                     Mean   :4293   Mean   :38.17   Mean   : 66.78  
##                     3rd Qu.:4968   3rd Qu.:45.12   3rd Qu.: 77.67  
##                     Max.   :5702   Max.   :88.39   Max.   :100.65
class(CAC1)
## [1] "data.frame"
R_CAC<-NULL# ON cr攼㸹e la variable R1
R_GLE<-NULL# ON cr攼㸹e la variable R1
R_SAN<-NULL# ON cr攼㸹e la variable R1
cac40<-CAC1[,2]
GLE<-CAC1[,3]
SAN<-CAC1[,4]
plot.ts(cac40)

plot.ts(GLE)

plot.ts(SAN)

n1<-length(cac40)-1
n2<-length(GLE)-1
n3<-length(SAN)-1
for(i in 2:length(cac40)-1) R_CAC[i-1] <- (cac40[i]-cac40[i-1])/cac40[i-1]*100 #
for(i in 2:length(GLE)-1) R_GLE[i-1] <- (GLE[i]-GLE[i-1])/GLE[i-1]*100 #
for(i in 2:length(SAN)-1) R_SAN[i-1] <- (SAN[i]-SAN[i-1])/SAN[i-1]*100 #


lm1<-lm(R_GLE~R_CAC)# Regression lin攼㸹aire
lm2<-lm(R_SAN~R_CAC)# Regression lin攼㸹aire
summary(lm1)
## 
## Call:
## lm(formula = R_GLE ~ R_CAC)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -18.7559  -0.9524  -0.0485   0.8737  13.1355 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.01450    0.03541   -0.41    0.682    
## R_CAC        1.50055    0.02479   60.53   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.943 on 3010 degrees of freedom
## Multiple R-squared:  0.549,  Adjusted R-squared:  0.5488 
## F-statistic:  3664 on 1 and 3010 DF,  p-value: < 2.2e-16
summary(lm2)
## 
## Call:
## lm(formula = R_SAN ~ R_CAC)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -10.9393  -0.5432  -0.0084   0.5741   7.8686 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.01390    0.02099   0.663    0.508    
## R_CAC        0.74568    0.01469  50.752   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.152 on 3010 degrees of freedom
## Multiple R-squared:  0.4611, Adjusted R-squared:  0.4609 
## F-statistic:  2576 on 1 and 3010 DF,  p-value: < 2.2e-16
rend<-cbind(R_CAC,R_GLE,R_SAN)
head(rend)
##            R_CAC       R_GLE     R_SAN
## [1,] -1.13500723 -1.18263145 -1.111466
## [2,] -0.07710824 -0.02050102 -1.188179
## [3,] -1.79027417 -1.06408200 -0.714987
## [4,]  0.11089172  0.17582288  2.929625
## [5,]  0.78564421 -1.68267228  4.070596
## [6,] -1.09631766 -0.26242295  1.680682
library("xlsx")
## Warning: package 'xlsx' was built under R version 3.5.3
write.xlsx(rend,"./rend2.xlsx")#sauvegarder les donn攼㸹es sous XLSX

plot(R_SAN, R_CAC, main="Sensibilit攼㸹 au CAC 40",
     xlab="rdt CAC40 ", ylab="rdt Sanofi", pch=20,cex=0.1,)
abline(lm1,col="green")

text(-5,11, paste("R_san2 =", round(lm1$coefficients[1],3),"+ R_cac2 *",round(lm1$coefficients[2],3)),col="blue",cex=0.6)
text(-5,10,paste("R戼㸲 ajust攼㸹",round(summary(lm1)$adj.r.squared,3)),col="blue",cex=0.6)
grid(NULL,NULL)

require(moments)
## Loading required package: moments
kurtosis(R_CAC)
## [1] 9.979685
kurtosis(R_GLE)
## [1] 9.36449
kurtosis(R_SAN)
## [1] 9.191892
skewness(R_CAC)
## [1] 0.168645
skewness(R_GLE)
## [1] 0.1242909
skewness(R_SAN)
## [1] -0.01467038
plot(R_GLE,type = "l",col="red",xlab="temps",ylab="rentabilit攼㸹",main="Rentabilit攼㸹s des diff攼㸹rents actifs")
lines(R_SAN)
lines(R_CAC,col="blue")

grid(NULL,NULL)

hist(R_CAC,150,main="Histogramme avec 50 classes")
skewness(R_CAC,na.rm = TRUE)
## [1] 0.168645
curve(dnorm(x,mean(R_CAC),sd(R_CAC)),add=T,col="red")

plot(density(R_CAC),ylim = c(-0.05,0.5))
curve(dnorm(x,mean(R_CAC),sd(R_CAC)),add=T,col="red")
legend(-10,0.52, legend=c("Loi normale", "Distribution emprique"),col=c("red", "black"), lty=1:1, cex=0.8)