require("readxl")
## Loading required package: readxl
## Warning: package 'readxl' was built under R version 3.6.1
require(RCurl)
## Loading required package: RCurl
## Loading required package: bitops
# install.packages(c("readxl","Rcurl")) 
getwd()
## [1] "S:/"
#setwd(dir = "S:/")
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')
CAC<- read_excel("./Fin2.xlsx")#
class(CAC)
## [1] "tbl_df"     "tbl"        "data.frame"
CAC1<-as.data.frame(CAC)
class(CAC1)
## [1] "data.frame"
View(CAC1)
tail(CAC1)
##            date  CAC 40   VIV    ACA    BN     FP     RI     AI   FTI    AIR
## 2993 2019-10-11 5665.48 24.87 11.220 79.22 46.415 170.25 119.30 21.18 118.88
## 2994 2019-10-14 5643.08 24.91 11.245 79.52 45.840 168.65 118.50 21.09 118.30
## 2995 2019-10-15 5702.05 24.90 11.415 80.30 46.455 167.70 118.70 21.23 119.44
## 2996 2019-10-16 5696.90 24.91 11.640 79.08 46.405 166.60 118.50 21.09 119.32
## 2997 2019-10-17 5673.07 25.17 11.545 78.58 46.215 159.65 117.05 20.72 119.84
## 2998 2019-10-18 5636.25 25.42 11.545 71.96 46.335 161.00 117.50 20.74 120.40
##         LR    SGO    SW    AC    SU   BNP     CA
## 2993 67.66 36.895 99.48 38.14 80.76 45.75 15.240
## 2994 67.38 36.760 97.70 38.08 80.32 45.39 15.260
## 2995 69.08 37.910 97.42 37.56 81.36 47.04 15.525
## 2996 69.04 37.800 97.18 37.99 81.78 47.25 15.560
## 2997 69.36 37.800 97.22 38.30 82.20 46.98 15.510
## 2998 69.06 37.685 96.62 37.96 81.78 46.99 15.355
head(CAC1)
##         date  CAC 40     VIV     ACA      BN    FP      RI      AI    FTI   AIR
## 1 2007-12-31 5614.08 30.3677 20.4993 57.9376 56.83 74.5572 63.2431 27.250 21.83
## 2 2008-01-02 5550.36 30.1258 20.2683 57.7867 56.32 74.8779 63.6096 26.890 21.35
## 3 2008-01-03 5546.08 30.0677 20.2328 57.5979 57.65 74.5478 64.1750 27.510 21.27
## 4 2008-01-04 5446.79 29.4774 19.8418 56.5977 57.20 73.5716 64.2309 26.685 20.75
## 5 2008-01-07 5452.83 29.8064 19.6463 58.3151 58.40 73.4301 64.5540 27.335 19.20
## 6 2008-01-08 5495.67 30.2032 19.7441 60.1174 58.90 74.2554 64.1253 27.415 19.36
##      LR   SGO    SW      AC     SU   BNP    CA
## 1 23.35 64.49 42.00 38.5486 46.340 74.20 53.29
## 2 23.29 62.83 41.70 38.3513 45.555 73.49 52.52
## 3 23.19 62.09 40.38 38.0764 44.975 73.42 51.94
## 4 21.92 59.81 39.00 37.2025 42.920 72.40 50.93
## 5 21.42 58.83 37.14 36.4062 41.250 72.37 50.07
## 6 22.10 58.27 37.93 35.9622 41.600 71.82 50.37
summary(CAC1)
##      date               CAC 40          VIV             ACA        
##  Length:2998        Min.   :2519   Min.   :12.01   Min.   : 2.775  
##  Class :character   1st Qu.:3713   1st Qu.:17.31   1st Qu.: 8.448  
##  Mode  :character   Median :4296   Median :19.28   Median :10.516  
##                     Mean   :4294   Mean   :19.54   Mean   :10.225  
##                     3rd Qu.:4968   3rd Qu.:21.48   3rd Qu.:12.116  
##                     Max.   :5702   Max.   :30.37   Max.   :20.499  
##        BN              FP              RI               AI        
##  Min.   :31.77   Min.   :30.38   Min.   : 37.39   Min.   : 38.26  
##  1st Qu.:46.83   1st Qu.:39.60   1st Qu.: 66.14   1st Qu.: 65.62  
##  Median :54.00   Median :43.18   Median : 88.41   Median : 80.12  
##  Mean   :54.86   Mean   :43.67   Mean   : 91.80   Mean   : 79.14  
##  3rd Qu.:63.42   3rd Qu.:47.38   3rd Qu.:108.45   3rd Qu.: 95.44  
##  Max.   :82.00   Max.   :58.90   Max.   :177.25   Max.   :119.30  
##       FTI             AIR               LR             SGO       
##  Min.   : 8.57   Min.   :  8.47   Min.   :10.91   Min.   :17.48  
##  1st Qu.:23.49   1st Qu.: 19.13   1st Qu.:25.14   1st Qu.:32.29  
##  Median :27.33   Median : 45.47   Median :40.12   Median :36.95  
##  Mean   :28.90   Mean   : 47.99   Mean   :39.36   Mean   :37.30  
##  3rd Qu.:35.02   3rd Qu.: 63.96   3rd Qu.:52.93   3rd Qu.:41.72  
##  Max.   :46.14   Max.   :132.62   Max.   :69.36   Max.   :64.49  
##        SW               AC              SU             BNP       
##  Min.   : 32.32   Min.   :17.03   Min.   :20.15   Min.   :21.38  
##  1st Qu.: 49.26   1st Qu.:26.65   1st Qu.:43.55   1st Qu.:43.69  
##  Median : 72.76   Median :33.90   Median :57.55   Median :51.20  
##  Mean   : 71.62   Mean   :33.39   Mean   :54.91   Mean   :49.92  
##  3rd Qu.: 92.71   3rd Qu.:38.88   3rd Qu.:66.20   3rd Qu.:56.48  
##  Max.   :123.25   Max.   :51.34   Max.   :82.20   Max.   :74.20  
##        CA       
##  Min.   :13.06  
##  1st Qu.:18.12  
##  Median :24.26  
##  Mean   :25.33  
##  3rd Qu.:30.68  
##  Max.   :53.29
VIV<-CAC1[,3]
plot.ts(VIV)
VIV<-CAC1[,3]
plot.ts(VIV)

CAC40<-CAC1[,2]
plot.ts(CAC40)

ACA<-CAC1[,4]
plot.ts(ACA)

R_CAC<-NULL# ON cr攼㸹e la variable R1
R_VIV<-NULL# ON cr攼㸹e la variable R1
R_ACA<-NULL# ON cr攼㸹e la variable R1


n1<-length(CAC40)-1

n2<-length(VIV)-1

n3<-length(ACA)-1

#for(i in 2:n1) R_CAC[i-1] <- (CAC40[i]-CAC40[i-1])/CAC40[i-1]*100 #
for(i in 2:n1) R_CAC[i-1] <- (log(CAC40[i]/CAC40[i-1]))*100 #
for(i in 2:n1) R_VIV[i-1] <- (log(VIV[i]/VIV[i-1]))*100 #
for(i in 2:n1) R_ACA[i-1] <- (log(ACA[i]/ACA[i-1]))*100 #

plot.ts(R_CAC)

plot.ts(R_VIV)

plot.ts(R_ACA)

plot.ts(R_ACA,main="Rendements des titres",xlab="Temps",ylab="Rendements")
lines(R_VIV,col="red")
lines(R_CAC,col="blue")
grid(NULL,NULL)

lm1<-lm(R_VIV~R_CAC)
summary(lm1)
## 
## Call:
## lm(formula = R_VIV ~ R_CAC)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.6660  -0.5937  -0.0385   0.5901   8.8350 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.006543   0.021914  -0.299    0.765    
## R_CAC        0.795234   0.015324  51.894   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.2 on 2994 degrees of freedom
## Multiple R-squared:  0.4735, Adjusted R-squared:  0.4734 
## F-statistic:  2693 on 1 and 2994 DF,  p-value: < 2.2e-16
lm2<-lm(R_ACA~R_CAC)
summary(lm2)
## 
## Call:
## lm(formula = R_ACA ~ R_CAC)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -16.5546  -0.9048  -0.0339   0.9077  13.5144 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.01967    0.03455  -0.569    0.569    
## R_CAC        1.44654    0.02416  59.873   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.891 on 2994 degrees of freedom
## Multiple R-squared:  0.5449, Adjusted R-squared:  0.5447 
## F-statistic:  3585 on 1 and 2994 DF,  p-value: < 2.2e-16
plot(R_VIV, R_CAC, main="Sensibilit攼㸹 au CAC 40",
     xlab="rdt CAC40 ", ylab="rdt Sanofi", pch=20,cex=0.1,)
abline(lm1,col="cyan")

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

CAC_100<-NULL
VIV_100<-NULL
ACA_100<-NULL

#for(i in 2:n1) R_CAC[i-1] <- (CAC40[i]-CAC40[i-1])/CAC40[i-1]*100 #
for(i in 2:n1) CAC_100[i-1] <- (CAC40[i]/CAC40[1])*100 #
for(i in 2:n1) VIV_100[i-1] <- (VIV[i]/VIV[1])*100 #
for(i in 2:n1) ACA_100[i-1] <- (ACA[i]/ACA[1])*100 #

plot.ts(CAC_100,col="purple",ylim=c(10,110))
lines(VIV_100,col="red")
lines(ACA_100,col="orange")
grid(NULL,NULL)