Plusieurs courbes dans un même espace

Postez ici vos questions, réponses, commentaires ou suggestions - Les sujets seront ultérieurement répartis dans les archives par les modérateurs

Modérateur : Groupe des modérateurs

Alhonita Yatié
Messages : 8
Enregistré le : 09 Mar 2021, 06:46

Plusieurs courbes dans un même espace

Messagepar Alhonita Yatié » 12 Mar 2021, 13:35

Bonjour,

Je travaille sur des corrélations entre des couples de variables et je souhaiterais regrouper tous les graphiques des différentes corrélations dans le même espace orthonormé. Les codes que j'ai testés jusqu'à présent, superposaient les graphiques. Par conséquent, chaque graphique avait son propre niveau zéro. Pour le moment voici les codes qui ont fonctionné mais n'ont pas abouti au résultat que je recherche.

Merci pour votre aide.

par(mfrow=c(2,3))
matplot(Period, Corr_BTC_CAC,main="BTC_CAC40", type="l",col="black",lty=c(1,1))
matplot(Period, Corr_BTC_DAX,main="BTC_DAX",type="l",col="green",lty=c(1,1))
matplot(Period, Corr_BTC_BEL20,main="BTC_BEL20",type="l",col="black",lty=c(1,1))


matplot(Period, cbind(Corr_BTC_BEL20,Corr_BTC_DAX, Corr_BTC_CAC),type="l",
col=c("red","green","dark"),lty=c(1,1))

Mickael Canouil
Messages : 1315
Enregistré le : 04 Avr 2011, 08:53
Contact :

Re: Plusieurs courbes dans un même espace

Messagepar Mickael Canouil » 13 Mar 2021, 12:11

Bonjour,

matplot dispose des arguments xlim/ylim.

Si vous voulez une réponse plus détaillée :

Cordialement,
Mickaël
mickael.canouil.fr | rlille.fr

Alhonita Yatié
Messages : 8
Enregistré le : 09 Mar 2021, 06:46

Re: Plusieurs courbes dans un même espace

Messagepar Alhonita Yatié » 16 Mar 2021, 08:21

Bonjour,
Voici les lignes de codes utilisés. Je fais un DCC GARCH sur plusieurs variables et je souhaiterais représenter les corrélations de chaque groupe dans le même espace orthonormé.
[data <- read.csv("All_data_crypto_euro.csv",
header = TRUE,
row.names = 1,
sep = ";",
dec = ".",
na.strings = "")

library(corrplot)
library(dplyr)
library(psych)
library(lattice)
library(plotly)
library(rgl)
library(scatterplot3d)
library(rmgarch)
library(rugarch)
library(tseries)
library(zoo)
library(FinTS)
library(ggplot2)


Period<-seq(as.Date("2020/3/11"), by="days", length.out = 365 )
BTC_CAC40= data.frame(data$BTC, data$CAC40)
BTC_DAX= data.frame(data$BTC, data$DAX)
BTC_FTSE= data.frame(data$BTC, data$FTSE)
BTC_IBEX= data.frame(data$BTC, data$IBEX)
BTC_BEL20= data.frame(data$BTC, data$BEL20)][/code]

Alhonita Yatié
Messages : 8
Enregistré le : 09 Mar 2021, 06:46

Re: Plusieurs courbes dans un même espace

Messagepar Alhonita Yatié » 16 Mar 2021, 08:23

Code : Tout sélectionner

 #GARCH
garch11.spec = ugarchspec(variance.model=list(model="sGARCH", garchOrder=c(1,1)),
                          mean.model=list(armaOrder=c(0,0), include.mean=TRUE), 
                          distribution.model="norm")

dcc.garch11.spec = dccspec(uspec= multispec( replicate(2, garch11.spec)),
                           dccOrder= c(1,1),
                           distribution = "mvnorm") 
                           
                           
                           
                           #1. BTC_CAC40
dcc.fit = dccfit(dcc.garch11.spec, data = BTC_CAC40)
rcorr = rcor(dcc.fit)

rho.est.line <- list()
rho.est.line = rcor(dcc.fit, type="R") # plot(rho.est.line[1,2,])
outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_CAC40)[1], byrow = TRUE)
rho.est = data.frame((outputcorr))
Corr_BTC_CAC = zoo(rho.est, order.by=index(BTC_CAC40[,1]))

#2.BTC_FTSE
dcc.fit_FTSE = dccfit(dcc.garch11.spec, data = BTC_FTSE)
rcorr1=rcor(dcc.fit_FTSE)
rho.est.line <- list()
rho.est.line = rcor(dcc.fit_FTSE, type="R") # plot(rho.est.line[1,2,])
outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_FTSE)[1], byrow = TRUE)
rho.est = data.frame((outputcorr))
Corr_BTC_FTSE = zoo(rho.est, order.by=index(BTC_FTSE[,1]))

#3. BTC_DAX

dcc.fit_DAX = dccfit(dcc.garch11.spec, data = BTC_DAX )
rcorr = rcor(dcc.fit_DAX)

rho.est.line <- list()
rho.est.line = rcor(dcc.fit_DAX, type="R") # plot(rho.est.line[1,2,])
outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_DAX)[1], byrow = TRUE)
rho.est = data.frame((outputcorr))
Corr_BTC_DAX = zoo(rho.est, order.by=index(BTC_DAX[,1]))

#4. BTC_IBEX

dcc.fit_IBEX = dccfit(dcc.garch11.spec, data = BTC_IBEX)
dcc.fit_IBEX               
rcorr = rcor(dcc.fit_IBEX)

rho.est.line <- list()
rho.est.line = rcor(dcc.fit_IBEX, type="R") # plot(rho.est.line[1,2,])
outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_IBEX)[1], byrow = TRUE)
rho.est = data.frame((outputcorr))
Corr_BTC_IBEX = zoo(rho.est, order.by=index(BTC_IBEX[,1]))     

Alhonita Yatié
Messages : 8
Enregistré le : 09 Mar 2021, 06:46

Re: Plusieurs courbes dans un même espace

Messagepar Alhonita Yatié » 16 Mar 2021, 08:28

Code : Tout sélectionner

  #5. BTC_BEL20

dcc.fit_BEL20 = dccfit(dcc.garch11.spec, data = BTC_BEL20)
rcorr = rcor(dcc.fit_BEL20)

rho.est.line <- list()
rho.est.line = rcor(dcc.fit_BEL20, type="R") # plot(rho.est.line[1,2,])
outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_BEL20)[1], byrow = TRUE)
rho.est = data.frame((outputcorr))
Corr_BTC_BEL20 = zoo(rho.est, order.by=index(BTC_BEL20[,1]))


matplot(Period, cbind(Corr_BTC_BEL20,Corr_BTC_DAX, Corr_BTC_DAX, Corr_BTC_IBEX, Corr_BTC_FTSE, Corr_BTC_CAC),type="l",
        lty=c(1,1), main= "BTC correlations")


Avec le dernier code mes graphiques n'apparaissent pas complètement.

Merci pour votre aide.

Alhonita Yatié
Messages : 8
Enregistré le : 09 Mar 2021, 06:46

Re: Plusieurs courbes dans un même espace

Messagepar Alhonita Yatié » 16 Mar 2021, 08:29

Code : Tout sélectionner

  data <- read.csv("All_data_crypto_euro.csv",
header = TRUE,
row.names = 1,
sep = ";",
dec = ".",
na.strings = "")

library(corrplot)
library(dplyr)
library(psych)
library(lattice)
library(plotly)
library(rgl)
library(scatterplot3d)
library(rmgarch)
library(rugarch)
library(tseries)
library(zoo)
library(FinTS)
library(ggplot2)


Period<-seq(as.Date("2020/3/11"), by="days", length.out = 365 )
BTC_CAC40= data.frame(data$BTC, data$CAC40)
BTC_DAX= data.frame(data$BTC, data$DAX)
BTC_FTSE= data.frame(data$BTC, data$FTSE)
BTC_IBEX= data.frame(data$BTC, data$IBEX)
BTC_BEL20= data.frame(data$BTC, data$BEL20)   

Mickael Canouil
Messages : 1315
Enregistré le : 04 Avr 2011, 08:53
Contact :

Re: Plusieurs courbes dans un même espace

Messagepar Mickael Canouil » 16 Mar 2021, 09:06

Votre code n'est pas reproductible (voir les liens que j'ai donné plus haut).
Donner l'ensemble de votre code ne va pa nous aider à vous aider, en d'autres mots, nous (les intervenants) de ce forum n'avons pas un temps illimité pour lire et décortiquer le code.

Je vous invite donc à réaliser un exemple minimal et reproductible comme indiqué dans ma première réponse.
Mickael Canouil a écrit :Bonjour,

matplot dispose des arguments xlim/ylim.

Si vous voulez une réponse plus détaillée :


PS : Il est possible d'éditer vos messages, plutôt qu'écrire un nouveau message à chaque fois, ce qui là encore nuit à la lisibilité de votre demande.

Cordialement,
Mickaël
mickael.canouil.fr | rlille.fr

Alhonita Yatié
Messages : 8
Enregistré le : 09 Mar 2021, 06:46

Re: Plusieurs courbes dans un même espace

Messagepar Alhonita Yatié » 23 Mar 2021, 08:20

Bonjour,

Le problème est que je ne sais pas comment ajouter dans les codes une base de données de minimum 100 données pour 5 variables.
J'ai testé la fonction "dput", mais j'avoue ne pas complètement la comprendre. Je n'arrive donc pas à organiser les données pour les partager sur le forum.

Eric Casellas
Messages : 767
Enregistré le : 06 Jan 2009, 14:59

Re: Plusieurs courbes dans un même espace

Messagepar Eric Casellas » 23 Mar 2021, 08:35

Alhonita Yatié a écrit :Bonjour,

Le problème est que je ne sais pas comment ajouter dans les codes une base de données de minimum 100 données pour 5 variables.
J'ai testé la fonction "dput", mais j'avoue ne pas complètement la comprendre. Je n'arrive donc pas à organiser les données pour les partager sur le forum.



Bonjour,

pour generer des données aléatoires s'il n'y a pas d'enjeu particulier sur certaines caracteristiques tu peut utiliser des loi de distribution comme par exemple la loi normale avec la fonction rnorm

Code : Tout sélectionner

data.frame(A=rnorm(100), B=rnorm(100), C=rnorm(100), D=rnorm(100), E=rnorm(100))


Eric
Eric

Alhonita Yatié
Messages : 8
Enregistré le : 09 Mar 2021, 06:46

Re: Plusieurs courbes dans un même espace

Messagepar Alhonita Yatié » 24 Mar 2021, 20:28

Bonsoir,

Voici une partie de ma base de données et les codes associés:


Code : Tout sélectionner

 
 
structure(list(BTC = c(0, -44.86993926, 10.88277915, -6.935222393,
3.402914147, -7.436806103, 5.719725952, 0.849832538, 19.34905098,
-0.723263127, -0.347602366, -5.245008509, 9.217751099, 4.264634695,
-1.772992076, -0.788549046, -4.902155125, -3.50099839, -5.018896904,
9.198316307, 0.12385161, 3.270256891, 3.837112467, -0.501665602,
1.81957533, -1.104335614, 6.958424524, -2.176019975, 2.501572385,
-1.056355934, -6.261650558, -0.127381243, 1.596272872, -1.685336089,
-0.54249978, -2.310477319, 8.397227958, -1.528358966, 2.336034924,
-0.938867291, -4.358529822, 0.07070082, 3.912375701, 4.596270579,
1.116585786, 0.259984977, 1.446663783, 1.484835439, 0.047439447,
11.54618581, -2.046921418, 0.880210575, 1.274388463, 0.250466991,
0.689491752, 1.668575105, 3.138767794, 6.686354058, -2.17693067,
-2.588703587, -7.909850339, -1.387255991, 1.887906415, 5.386722732,
5.004851503, -4.341897651, 0.445695052, 3.182677909, -0.34708704,
-0.130862461, -2.591210337, -4.480516755, 1.594447415, 0.295916623,
-4.805397306, 1.459828284, -1.526672488, 3.518786014, 3.116203081,
-1.191117126, 2.729577548, -2.579891076, 7.057809686, -6.932119008,
0.83633725, 0.546126344, -0.952393613, -0.128075249, 0.855279502,
0.281212724, -0.054079698, 0.483148681, -5.042942853, 1.981293572,
-0.018032513, -0.932623727, -0.039738674, 1.46953922, -0.344148782,
-0.441351593, -1.023478998, 0.448467125, -0.314435034, 2.714586447,
-0.421830588, -2.809592214, -0.297044161, -1.000724985, -1.30828876,
0.953815692, 0.294006718, -0.322402355, 0.772943073, -1.039769901,
-0.524735232, 0.480403365, -0.608716426, 2.424743892), FTSE = c(0,
-11.51242833, 0, 0, 2.426278461, -4.089684981, 2.753769171, -4.131866483,
1.388385888, 0, 0, 0.757468772, -3.866880972, 8.666806528, 4.351062317,
2.217246187, 0, 0, -5.394180302, 0.964603152, 1.926419302, -3.908094761,
0.469145673, 0, 0, -1.188003385, 3.035178781, 2.16295719, -0.469506704,
0, 0, 0, 0, 2.863466763, -0.882765444, -3.401165134, 0.548367322,
0, 0, 2.777657049, 0.446043297, -3.000087055, 2.271458705, 0.965409611,
0, 0, -1.28477504, 1.630518698, 1.892597885, 2.596687983, -3.562823675,
0, 0, -2.368883099, -0.161155352, 1.64854809, 0.074167879, 0.786816109,
0, 0, 0.607978568, 0.063154121, 0.922374464, -1.524886634, -2.791108907,
0, 0, 1.009079456, 4.200692544, -0.769412019, 1.075955395, -0.859270947,
0, 0, -0.253844209, -0.112062767, 1.23506674, 1.252717616, 1.205866894, 0, 0, -2.313002503, 1.467311358, 0.867397192, 2.575335444, -0.643989698,
0, 0, 2.227799854, -0.180753301, -2.137287591, -0.104067566,
-4.070100048, 0, 0, 0.467580569, -0.665251412, 2.894212081, 0.167413076,
-0.4677295, 0, 0, 1.095030624, -0.765404679, 1.201790227, -3.157333932,
0.3822077, 0, 0, 0.197620172, 1.073399476, -0.904043184, -0.191114378,
1.329231916, 0, 0, -1.339950325, 2.067702354), CAC40 = c(0, 0.774648018,
0, 0, -11.35672623, 2.01019453, -3.364346288, 0.011000439, 4.988650099,
0, 0, -0.275133506, 3.474473404, 4.838041298, 2.013497556, -1.602039821,
0, 0, -2.084020773, 2.020261598, -4.621890661, -0.026487738,
-1.202115854, 0, 0, 3.236118892, 3.927849378, -1.891844369, 2.246590318,
0, 0, 0, 0, 0.74878139, -1.149920287, -2.389384871, 2.946442727,
0, 0, -0.428094535, -1.199528183, -1.343264851, 1.75760992, -1.054720816,
0, 0, 1.262694086, 2.123235067, 1.659149759, 0.868426202, -6.386441747,
0, 0, 1.452449566, -0.186260453, 0.440138226, 1.241172007, 0.209639779,
0, 0, -1.551885508, -1.71824185, -2.506541481, 0.520521974, 3.916509199,
0, 0, 0.599668796, -0.803026938, -0.038008996, -0.50660781, 1.432262711,
0, 0, 1.745288439, 1.975025165, 1.518550507, -0.319064349, 0.275995686,
0, 0, 2.031081456, 2.953801244, 0.521867999, 2.86586661, 0.269270674,
0, 0, -0.196792066, -0.9843772, -3.881283509, -0.313425718, -2.029445097,
0, 0, 3.356420471, 0.399656489, -0.19235332, 0.463130883, -0.678223777,
0, 0, 0.79401892, -0.841169695, -1.248357253, 1.463750889, -0.744564839,
0, 0, -0.206737543, -0.08015532, 2.179024606, -0.201278383, 1.16279124,
0, 0, -1.281182048, -0.316924829), IBEX = c(0, -4.015166595,
0, 0, -6.611190487, 1.77688523, -1.154909442, -0.036107373, 4.260798554,
0, 0, -6.556025471, 3.312297904, 8.240622234, -2.859016259, 1.863515015,
0, 0, -2.460371498, -0.026680099, -1.787083749, 0.09652953, -1.062349946,
0, 0, 3.654444032, 2.595326498, -0.81482522, 1.70395925, 0, 0,
0, 0, 2.249907515, -2.018941651, -1.926273357, 0.168672168, 0,
0, -0.144144169, -2.796774277, -0.837157177, 1.094940876, -1.752289462,
0, 0, 2.080212396, -0.833736331, 1.546434891, 3.671480892, -4.102900439,
0, 0, -0.476128829, 0.066470211, -0.776766283, -0.072943993,
1.122513452, 0, 0, 0.590236439, -2.343181731, 0.318699795, -1.874340375,
0.375259012, 0, 0, -0.171501526, 4.18137538, -4.025039386, 0.292293813, 0.083138716, 0, 0, 2.217530048, 2.538948064, 1.336729382, 2.849264767,
-1.013784957, 0, 0, 0.894890847, 0.487140068, 3.027758456, 1.068099028,
1.368812144, 0, 0, 1.822448708, 0.829765148, -1.256887028, -3.842920726,
-3.455809406, 0, 0, -1.607108095, 4.181461822, 0.501386143, -0.291385563,
0.104838429, 0, 0, -0.980043962, 0.503366428, -0.066158138, -3.120902426,
2.042704228, 0, 0, -2.270093215, 1.531487153, -0.344443096, 0.647947296,
2.940151119, 0, 0, 0.745522339, -0.996156464), FTSE.MIB = c(0,
6.478657414, 0, 0, -8.713967258, 2.971710281, -0.818558459, 2.281982761,
1.025718331, 0, 0, -1.059197858, 8.673787768, 2.180535239, 0.33589283,
-3.361251643, 0, 0, 1.2737458, 1.426644321, -3.433813758, 1.915412281,
-2.327990225, 0, 0, 3.725764425, 2.279198953, -0.248065806, 1.537498745,
0, 0, 0, 0, -0.355861881, -5.089043376, 0.331512367, 1.785870217,
0, 0, 0.084251073, -3.794626094, 1.967398275, 1.35692246, -1.069398938,
0, 0, 3.144894356, 1.812632119, 2.019921934, -2.136255126, 0.005819875,
0, 0, -3.765527437, 1.950872714, -1.330370106, 0.515156285, 1.075630635,
0, 0, -0.278197226, 0.996734978, -2.117328453, -1.985657588,
-0.061162081, 0, 0, 3.935012568, -2.00814733, 0.937796199, -0.787875629,
1.339265873, 0, 0, 1.67686856, 1.425915342, 0.309048492, 2.399550556,
-0.834715359, 0, 0, 1.800745523, 2.466700783, 3.511548403, -0.026026078,
2.736942679, 0, 0, 0.18724228, -1.523247058, -0.778173939, -4.990828088,
0.407045147, 0, 0, -0.238598888, 3.357936865, -0.168137913, -0.553696671,
0.732333823, 0, 0, -0.447192643, 1.849389247, -3.502846731, 0.37989291,
-0.605299542, 0, 0, 1.746955378, -0.375572395, -0.297224358,
2.897083096, -0.902542565, 0, 0, 1.730459772, -0.148622705),
    DAX = c(0, -3.962416071, 0, 0, -8.267534893, 4.619714359,
    -5.94750608, -1.37249229, 6.653975359, 0, 0, -6.179698287,
    7.943363148, 7.755649021, -3.734814024, 1.774574581, 0, 0,
    -0.692852647, 2.486944471, -3.678587895, -0.241898804, -0.545739618,
    0, 0, 3.642850658, 5.652524493, -1.565596681, 1.818904419,
    0, 0, 0, 0, 2.292909463, -0.521013538, -2.445135548, 1.779516903,
    0, 0, 0.910304385, -1.742522695, -1.4283844, 0.645246315,
    -1.33166904, 0, 0, 2.415037388, 1.012760465, 1.437018731,
    3.476093971, -3.593987412, 0, 0, -2.404985624, 0.790824147,
    0.838102357, -0.709269322, 2.245763127, 0, 0, 0.602823176,
    -1.569581674, -1.00477679, -2.389620928, 0.50562871, 0, 0,  2.013898553, 4.726172633, -1.543782979, 0.531617691, -1.745281832,
    0, 0, 2.624512571, 2.672261318, 0.358049471, 1.86094803,
    -0.832705918, 0, 0, 0.433674051, 1.667220893, 2.083105392,
    1.980001229, 1.403578775, 0, 0, 1.245832284, 1.072227189,
    -1.099976766, -3.975494813, -2.880559799, 0, 0, -1.826737346,
    4.255914992, 1.177017127, 0.284267016, 0.224005025, 0, 0,
    -1.470946347, 1.348934322, 0.803553089, -2.911687872, 1.689707,
    0, 0, -1.787587935, 1.62057172, 0.841021406, -0.104317561,
    2.124491454, 0, 0, 1.024188545, -0.901760632), BEL20 = c(0,
    -7.721073209, 0, 0, -6.395446119, 0.475891576, -4.577953185,
    4.432877014, 4.820017918, 0, 0, -3.140294237, 4.351636127,
    6.441842354, -4.376561949, 2.734014577, 0, 0, -2.694416237,
    0.3294942, -0.95085433, 1.460094533, 0.109728329, 0, 0, 2.858031344,
    2.358508703, -0.21962883, 2.501899079, 0, 0, 0, 0, 0.794376545,
    -2.780286932, -2.681516656, 1.704588628, 0, 0, 0.683862224,
    -1.7374406, -1.364711341, 0.943518078, -0.079129512, 0, 0,
    1.231671711, 1.154540957, 2.774338317, 2.283180373, -3.437015815,
    0, 0, -2.331831465, -0.207583846, 0.03551213, -0.020243688,
    2.888853174, 0, 0, -0.703467155, -0.961238403, -0.849143863,
    -3.611025624, 0.769050678, 0, 0, 1.054780357, 2.594691666,
    -3.484956931, -0.359291603, -0.981335253, 0, 0, 2.540437345,
    2.060545311, 4.524955144, 2.498384707, -0.607669174, 0, 0,
    0.305371947, 1.081587359, 1.579211194, 2.113864216, 1.99659662,
    0, 0, 0.975296787, 0.460889161, -0.974793044, -4.149842246,
    -3.480407742, 0, 0, -0.457448708, 5.409397919, 1.031936981,
    -0.307997996, 0.22570579, 0, 0, -2.601062527, 1.639376123,
    0.068412409, -3.648701409, 2.898014373, 0, 0, -2.921457641,
    1.473797426, 0.059090222, 0.857813088, 1.259427888, 0, 0,
    1.115232574, 0.416038333), PSI.20 = c(0, -3.626605842, -3.626605842,
    -3.626605842, -6.924465435, 4.688159085, -0.087190375, -2.990869661,
    0.142023383, 0.142023383, 0.142023383, -3.984590855, 4.501741805,
    7.718751795, -2.62428232, 1.419320217, 1.419320217, 1.419320217,
    -0.925998172, 2.238949227, -0.465881735, 0.454441425, -0.866541613,
    -0.866541613, -0.866541613, 1.063579647, 1.619650027, -0.910503506,
    1.281789402, 0, 0, 0, 0, 3.973925419, -0.978774568, -1.618398677, 0.484358682, 0.484358682, 0.484358682, -0.680155716, -1.470942501,
    -1.496122939, 2.312029411, -0.302059371, -0.302059371, -0.302059371,
    0.686915429, -0.616773796, 2.694536955, 2.530617658, 0, 0,
    0, -3.18909545, 0.681619709, -0.435634648, -0.795936685,
    1.943279594, 1.943279594, 1.943279594, -0.55575812, -1.748406044,
    -2.01791088, -0.941493608, -1.226987904, -1.226987904, -1.226987904,
    1.658007111, 3.750163308, -1.504545394, 0.358308841, 0.249958829,
    0.249958829, 0.249958829, 1.786942546, 1.678683926, -0.307676179,
    0.340469955, 1.032565123, 1.032565123, 1.032565123, 0.006627216,
    2.009141329, 3.118714163, -0.002388067, 0.836019886, 0.836019886,
    0.836019886, -1.976409073, 1.231746391, -1.41835195, -3.120253847,
    -2.190496685, -2.190496685, -2.190496685, -0.362109554, 2.323555834,
    1.000497272, -0.118991293, 0.478933182, 0.478933182, 0.478933182,
    -0.612290454, 0.226218671, -0.110226132, -1.874060306, 0.176103072,
    0.176103072, 0.176103072, -0.411697746, 1.187030939, -0.585114063,
    0.124706413, 1.255071177, 1.255071177, 1.255071177, 0.362917894,
    -1.622562706), BIST.100 = c(0, -4.98786403, -4.98786403,
    -4.98786403, -1.499581677, -3.688320621, -4.774654712, 0.192084529,
    2.645414116, 2.645414116, 2.645414116, -4.902867823, 5.307930509,
    3.310988052, -1.737294292, 3.179576892, 3.179576892, 3.179576892,
    -4.336195042, 1.514564885, -1.118475321, 1.642419835, -0.149418522,
    -0.149418522, -0.149418522, 1.522706231, 2.373009273, -0.745468183,
    1.920201216, 2.022370948, 2.022370948, 2.022370948, -0.770101477,
    2.102132819, 1.480407415, -2.28886921, 1.621632208, 1.621632208,
    1.621632208, 0.380809705, -0.298431932, -0.243260831, 0.174108755,
    0.151462044, 0.151462044, 0.151462044, 1.649116881, 1.445253769,
    -0.326502719, 0.771626993, 0, 0, 0, -1.722663119, -0.620349384,
    -0.753580032, -0.30992702, 0.327117056, 0.327117056, 0.327117056,
    -0.48955364, -0.503194404, 1.800373477, 0.303435663, -0.330519216,
    -0.330519216, -0.330519216, 1.215520388, 0, 1.568455224,
    -0.261826289, 0.22474335, 0.22474335, 0.22474335, 0, 0, 1.303278536,
    1.679491505, -0.353992749, -0.353992749, -0.353992749, 1.226487519,
    1.219976955, 1.050241757, 0.419587442, 0.691489452, 0.691489452,
    0.691489452, 0.171448052, -0.351376129, -0.314286624, -0.206417274,
    -0.81612872, -0.81612872, -0.81612872, 0.833498799, 1.291524165, 0.484358682, 0.484358682, 0.484358682, -0.680155716, -1.470942501,
    -1.496122939, 2.312029411, -0.302059371, -0.302059371, -0.302059371,
    0.686915429, -0.616773796, 2.694536955, 2.530617658, 0, 0,
    0, -3.18909545, 0.681619709, -0.435634648, -0.795936685,
    1.943279594, 1.943279594, 1.943279594, -0.55575812, -1.748406044,
    -2.01791088, -0.941493608, -1.226987904, -1.226987904, -1.226987904,
    1.658007111, 3.750163308, -1.504545394, 0.358308841, 0.249958829,
    0.249958829, 0.249958829, 1.786942546, 1.678683926, -0.307676179,
    0.340469955, 1.032565123, 1.032565123, 1.032565123, 0.006627216,
    2.009141329, 3.118714163, -0.002388067, 0.836019886, 0.836019886,
    0.836019886, -1.976409073, 1.231746391, -1.41835195, -3.120253847,
    -2.190496685, -2.190496685, -2.190496685, -0.362109554, 2.323555834,
    1.000497272, -0.118991293, 0.478933182, 0.478933182, 0.478933182,
    -0.612290454, 0.226218671, -0.110226132, -1.874060306, 0.176103072,
    0.176103072, 0.176103072, -0.411697746, 1.187030939, -0.585114063,
    0.124706413, 1.255071177, 1.255071177, 1.255071177, 0.362917894,
    -1.622562706), BIST.100 = c(0, -4.98786403, -4.98786403,
    -4.98786403, -1.499581677, -3.688320621, -4.774654712, 0.192084529,
    2.645414116, 2.645414116, 2.645414116, -4.902867823, 5.307930509,
    3.310988052, -1.737294292, 3.179576892, 3.179576892, 3.179576892,
    -4.336195042, 1.514564885, -1.118475321, 1.642419835, -0.149418522,
    -0.149418522, -0.149418522, 1.522706231, 2.373009273, -0.745468183,
    1.920201216, 2.022370948, 2.022370948, 2.022370948, -0.770101477,
    2.102132819, 1.480407415, -2.28886921, 1.621632208, 1.621632208,
    1.621632208, 0.380809705, -0.298431932, -0.243260831, 0.174108755,
    0.151462044, 0.151462044, 0.151462044, 1.649116881, 1.445253769,
    -0.326502719, 0.771626993, 0, 0, 0, -1.722663119, -0.620349384,
    -0.753580032, -0.30992702, 0.327117056, 0.327117056, 0.327117056,
    -0.48955364, -0.503194404, 1.800373477, 0.303435663, -0.330519216,
    -0.330519216, -0.330519216, 1.215520388, 0, 1.568455224,
    -0.261826289, 0.22474335, 0.22474335, 0.22474335, 0, 0, 1.303278536,
    1.679491505, -0.353992749, -0.353992749, -0.353992749, 1.226487519,
    1.219976955, 1.050241757, 0.419587442, 0.691489452, 0.691489452,
    0.691489452, 0.171448052, -0.351376129, -0.314286624, -0.206417274,
    -0.81612872, -0.81612872, -0.81612872, 0.833498799, 1.291524165, 0.41963897, -0.147483367, 2.175643724, 2.175643724, 2.175643724,
    0.998860501, 0.795426176, -0.214731711, -0.850454071, 0.631785605,
    0.631785605, 0.631785605, -0.296659968, 1.427347526, 0.635292427,
    -1.136434389, 1.262669032, 1.262669032, 1.262669032, -0.548742776,
    1.799034361), EUROSTOXX = c(0, -10.9440235, -10.9440235,
    -10.9440235, -1.036556819, -3.279920626, 1.29053213, -4.836868903,
    3.544720716, 3.544720716, 3.544720716, 1.81523995, -0.511925129,
    9.480939662, 0.321211245, 1.337076277, 1.337076277, 1.337076277,
    -2.462019513, 1.66364711, -0.731234332, -2.47222268, -0.262492715,
    -0.262492715, -0.262492715, 0.586126591, 4.262977967, 0.9432134,
    0.637402127, 0.000349107, 0.000349107, 0.000349107, 0.000349105,
    1.618202554, 0.106428643, -3.051970022, 0.543326203, 0.543326203,
    0.543326203, 1.841080691, -0.184632033, -3.119904107, 1.295128361,
    0.000352445, 0.000352445, 0.000352445, 0.05743188, 1.532772499,
    1.776816036, 2.314804335, -2.538602792, -2.538602792, -2.538602792,
    -0.996778361, -2.393459247, 1.61635823, -1.176037767, 1.748022548,
    1.748022548, 1.748022548, 0.784004484, -1.280924884, -0.229540568,
    -2.665064962, -0.683544376, -0.683544376, -0.683544376, 0.811837717,
    4.575724386, -1.224039942, 1.103879212, -1.31581072, -1.31581072,
    -1.31581072, 1.023340336, 2.187203364, 0.682731027, 1.803164227,
    0.750101636, 0.750101636, 0.750101636, 0.000324487, 1.34595785,
    1.467623525, 2.841508456, 0.636712167, 0.636712167, 0.636712167,
    2.239566229, 0.365810544, -1.231821498, -1.933022506, -4.013459761,
    -4.013459761, -4.013459761, -0.120957783, 0.782513941, 2.628619855,
    0.633158854, -0.112616944, -0.112616944, -0.112616944, 0.074580717,
    -0.18732463, 1.090448004, -2.860531958, 1.147555362, 1.147555362,
    1.147555362, -1.148806836, 1.233209246, 0.123229366, -0.01172959,
    2.510301279, 2.510301279, 2.510301279, -0.223922411, 0.731088822
    ), OMXS30 = c(0, -3.834017397, -3.834017397, -3.834017397,
    -5.487939817, 4.557978301, -2.617362534, 1.060084558, 5.576946907,  5.576946907, 5.576946907, -9.767793582, 4.620189418, 5.422726809,
    -1.074593455, 2.971293007, 2.971293007, 2.971293007, -1.744024558,
    2.985172819, -2.268343866, -0.166197897, -0.763599808, -0.763599808,
    -0.763599808, 1.215650949, 3.433609125, 0.040827664, 1.620903668,
    0.000658408, 0.000658408, 0.000658408, 0.000658404, 0.722938977,
    0.105836708, -2.311905713, 1.906244223, 1.906244223, 1.906244223,
    1.523151163, -1.51135067, -1.112726625, 1.798038921, -1.330477946,
    -1.330477946, -1.330477946, 1.388406136, 0.374745115, 1.531707232,
    2.289085116, -1.381576743, -1.381576743, -1.381576743, -3.129391669,
    -0.429120635, 0.669043037, -0.410434337, 1.275359267, 1.275359267,
    1.275359267, 1.245272601, -1.346032833, 0.201419039, -2.826946309,
    -1.091281333, -1.091281333, -1.091281333, 1.975672964, 3.625115274,
    -1.931811682, -0.258300218, -0.190754316, -0.190754316, -0.190754316,
    1.961439833, 2.186357863, 0.12951192, 1.84770878, 0.310444661,
    0.310444661, 0.310444661, 0.538092835, 0.404995899, 1.591310581,
    1.10532289, 0.407272864, 0.407272864, 0.407272864, 0.767827418,
    -0.198091762, -1.106275827, -2.721917301, -4.000089573, -4.000089573,
    -4.000089573, -0.777113581, 4.516461011, 1.439773727, -0.462627142,
    -0.666269893, -0.666269893, -0.666269893, 0.000603877, 0.803540847,
    0.429190339, -2.527942006, 2.581014391, 2.581014391, 2.581014391,
    -1.295466049, 1.128998726, -0.559903495, 1.565217742, 0.78788786,
    0.78788786, 0.78788786, 1.004957335, 0.014515853)), class = "data.frame", row.names = c("12/03/2020",
"13/03/2020", "14/03/2020", "15/03/2020", "16/03/2020", "17/03/2020",
"18/03/2020", "19/03/2020", "20/03/2020", "21/03/2020", "22/03/2020",
"23/03/2020", "24/03/2020", "25/03/2020", "26/03/2020", "27/03/2020",
"28/03/2020", "29/03/2020", "30/03/2020", "31/03/2020", "01/04/2020",
"02/04/2020", "03/04/2020", "04/04/2020", "05/04/2020", "06/04/2020",
"07/04/2020", "08/04/2020", "09/04/2020", "10/04/2020", "11/04/2020",
"12/04/2020", "13/04/2020", "14/04/2020", "15/04/2020", "16/04/2020",
"17/04/2020", "18/04/2020", "19/04/2020", "20/04/2020", "21/04/2020",
"22/04/2020", "23/04/2020", "24/04/2020", "25/04/2020", "26/04/2020",
"27/04/2020", "28/04/2020", "29/04/2020", "30/04/2020", "01/05/2020", "02/05/2020", "03/05/2020", "04/05/2020", "05/05/2020", "06/05/2020",
"07/05/2020", "08/05/2020", "09/05/2020", "10/05/2020", "11/05/2020",
"12/05/2020", "13/05/2020", "14/05/2020", "15/05/2020", "16/05/2020",
"17/05/2020", "18/05/2020", "19/05/2020", "20/05/2020", "21/05/2020",
"22/05/2020", "23/05/2020", "24/05/2020", "25/05/2020", "26/05/2020",
"27/05/2020", "28/05/2020", "29/05/2020", "30/05/2020", "31/05/2020",
"01/06/2020", "02/06/2020", "03/06/2020", "04/06/2020", "05/06/2020",
"06/06/2020", "07/06/2020", "08/06/2020", "09/06/2020", "10/06/2020",
"11/06/2020", "12/06/2020", "13/06/2020", "14/06/2020", "15/06/2020",
"16/06/2020", "17/06/2020", "18/06/2020", "19/06/2020", "20/06/2020",
"21/06/2020", "22/06/2020", "23/06/2020", "24/06/2020", "25/06/2020",
"26/06/2020", "27/06/2020", "28/06/2020", "29/06/2020", "30/06/2020",
"01/07/2020", "02/07/2020", "03/07/2020", "04/07/2020", "05/07/2020",
"06/07/2020", "07/07/2020"))


#LES LIBRAIRIES ET LA PERIODE D'ETUDE

library(corrplot)
library(dplyr)
library(psych)
library(lattice)
library(plotly)
library(rgl)
library(scatterplot3d)
library(rmgarch)
library(rugarch)
library(tseries)
library(zoo)
library(FinTS)
library(ggplot2)
library(reprex)


Period<-seq(as.Date("2020/3/11"), by="days", length.out = 118 )

#LES COUPLES
BTC_CAC40= data.frame(data$BTC, data$CAC40)
BTC_DAX= data.frame(data$BTC, data$DAX)
BTC_FTSE= data.frame(data$BTC, data$FTSE)
BTC_IBEX= data.frame(data$BTC, data$IBEX)
BTC_FTSEMIB= data.frame(data$BTC, data$FTSE.MIB)
BTC_BEL20= data.frame(data$BTC, data$BEL20)
BTC_EUROSTOXX= data.frame(data$BTC, data$EUROSTOXX)
BTC_BIST.100= data.frame(data$BTC, data$BIST.100)
BTC_OMXS30= data.frame(data$BTC, data$OMXS30)
BTC_PSI.20= data.frame(data$BTC, data$PSI.20)


#GARCH
garch11.spec = ugarchspec(variance.model=list(model="sGARCH", garchOrder=c(1,1)),
                          mean.model=list(armaOrder=c(0,0), include.mean=TRUE), 
                          distribution.model="norm")

dcc.garch11.spec = dccspec(uspec= multispec( replicate(2, garch11.spec)),
                           dccOrder= c(1,1),
                           distribution = "mvnorm")


#LES DCC

#1. BTC_CAC40
dcc.fit = dccfit(dcc.garch11.spec, data = BTC_CAC40)
rcorr = rcor(dcc.fit)

rho.est.line <- list()
rho.est.line = rcor(dcc.fit, type="R") # plot(rho.est.line[1,2,])
outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_CAC40)[1], byrow = TRUE)
rho.est = data.frame((outputcorr))
Corr_BTC_CAC = zoo(rho.est, order.by=index(BTC_CAC40[,1]))

#2.BTC_FTSE
dcc.fit_FTSE = dccfit(dcc.garch11.spec, data = BTC_FTSE)
rcorr1=rcor(dcc.fit_FTSE)
rho.est.line <- list()
rho.est.line = rcor(dcc.fit_FTSE, type="R") # plot(rho.est.line[1,2,])
outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_FTSE)[1], byrow = TRUE)
rho.est = data.frame((outputcorr))
Corr_BTC_FTSE = zoo(rho.est, order.by=index(BTC_FTSE[,1]))

#3. BTC_DAX

dcc.fit_DAX = dccfit(dcc.garch11.spec, data = BTC_DAX )
rcorr = rcor(dcc.fit_DAX)

rho.est.line <- list()
rho.est.line = rcor(dcc.fit_DAX, type="R") # plot(rho.est.line[1,2,])
outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_DAX)[1], byrow = TRUE)
rho.est = data.frame((outputcorr))
Corr_BTC_DAX = zoo(rho.est, order.by=index(BTC_DAX[,1]))

#4. BTC_IBEX

dcc.fit_IBEX = dccfit(dcc.garch11.spec, data = BTC_IBEX)
dcc.fit_IBEX               
rcorr = rcor(dcc.fit_IBEX)

rho.est.line <- list()
rho.est.line = rcor(dcc.fit_IBEX, type="R") # plot(rho.est.line[1,2,])
outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_IBEX)[1], byrow = TRUE)
rho.est = data.frame((outputcorr))
Corr_BTC_IBEX = zoo(rho.est, order.by=index(BTC_IBEX[,1]))


#5. BTC_BEL20

dcc.fit_BEL20 = dccfit(dcc.garch11.spec, data = BTC_BEL20)
rcorr = rcor(dcc.fit_BEL20)

rho.est.line <- list()
rho.est.line = rcor(dcc.fit_BEL20, type="R") # plot(rho.est.line[1,2,])
outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_BEL20)[1], byrow = TRUE)
rho.est = data.frame((outputcorr))
Corr_BTC_BEL20 = zoo(rho.est, order.by=index(BTC_BEL20[,1]))


# 6. BTC_FTSE.MIB

dcc.fit_FTSE.MIB = dccfit(dcc.garch11.spec, data = BTC_FTSEMIB)
rcorr = rcor(dcc.fit_FTSE.MIB)

rho.est.line <- list()
rho.est.line = rcor(dcc.fit_FTSE.MIB, type="R") # plot(rho.est.line[1,2,])
outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_FTSEMIB)[1], byrow = TRUE)
rho.est = data.frame((outputcorr))
Corr_BTC_FTSEMIB = zoo(rho.est, order.by=index(BTC_FTSEMIB[,1]))

#7. BTC_BIST
dcc.fit_BIST.100 = dccfit(dcc.garch11.spec, data = BTC_BIST.100)
rcorr = rcor(dcc.fit_BIST.100)
rho.est.line <- list()
rho.est.line = rcor(dcc.fit_BIST.100, type="R") # plot(rho.est.line[1,2,])
outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_BIST.100)[1], byrow = TRUE)
rho.est = data.frame((outputcorr))
Corr_BTC_BIST.100 = zoo(rho.est, order.by=index(BTC_BIST.100[,1]))



# 9.BTC_PSI
dcc.fit_PSI.20 = dccfit(dcc.garch11.spec, data = BTC_PSI.20)
rcorr = rcor(dcc.fit_PSI.20)
rho.est.line <- list()
rho.est.line = rcor(dcc.fit_PSI.20, type="R") # plot(rho.est.line[1,2,])
outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_PSI.20)[1], byrow = TRUE)
rho.est = data.frame((outputcorr))
Corr_BTC_PSI.20 = zoo(rho.est, order.by=index(BTC_PSI.20[,1]))


#10. BTC_EUROSTOXX
dcc.fit_EUROSTOXX = dccfit(dcc.garch11.spec, data = BTC_EUROSTOXX)
rcorr = rcor(dcc.fit_EUROSTOXX)
rho.est.line <- list()
rho.est.line = rcor(dcc.fit_EUROSTOXX, type="R") # plot(rho.est.line[1,2,])
outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_EUROSTOXX)[1], byrow = TRUE)
rho.est = data.frame((outputcorr))
Corr_BTC_EUROSTOXX = zoo(rho.est, order.by=index(BTC_EUROSTOXX[,1]))


#11.BTC_OMXS30
dcc.fit_OMXS30 = dccfit(dcc.garch11.spec, data = BTC_OMXS30)
rcorr = rcor(dcc.fit_OMXS30)
rho.est.line <- list()
rho.est.line = rcor(dcc.fit_OMXS30, type="R") # plot(rho.est.line[1,2,])
outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_OMXS30)[1], byrow = TRUE)
rho.est = data.frame((outputcorr))
Corr_BTC_OMXS30 = zoo(rho.est, order.by=index(BTC_OMXS30[,1]))


#Enfin le code qui pose problème malgré l'utilisation de xlim= c(-10,10)

matplot(Period, cbind(Corr_BTC_BEL20,Corr_BTC_DAX, Corr_BTC_CAC,
                      Corr_BTC_OMXS30, Corr_BTC_EUROSTOXX, Corr_BTC_PSI.20,
                      Corr_BTC_FTSEMIB, Corr_BTC_FTSE), type="l",
        lty=c(1,1), main= "Bitcoin correlations")

 


J'ai envoyé le code complet avec les données numériques.
Le volet économétrique ne pose aucun problème, c'est la représentation graphique des corrélations qui me donne du fil à retordre. J'espère que ces informations seront suffisantes pour que vous puissiez me donner les conseils appropriés.

Merci.

Fred Santos
Messages : 233
Enregistré le : 11 Avr 2009, 10:00
Contact :

Re: Plusieurs courbes dans un même espace

Messagepar Fred Santos » 25 Mar 2021, 09:55

Re-bonjour,

Je ne suis toujours pas trop sûr de bien comprendre. De mon côté, en l'état le code provoque un certain nombre d'erreurs (découlant toutes de la première d'entre elles) :

Code : Tout sélectionner

> BTC_BIST.100= data.frame(data$BTC, data$BIST.100)
Error in data.frame(data$BTC, data$BIST.100) :

> #7. BTC_BIST
> dcc.fit_BIST.100 = dccfit(dcc.garch11.spec, data = BTC_BIST.100)
Error in .dccfit(spec = spec, data = data, out.sample = out.sample, solver = solver,  :
  objet 'BTC_BIST.100' introuvable
> rcorr = rcor(dcc.fit_BIST.100)
Error in h(simpleError(msg, call)) :
  erreur d'évaluation de l'argument 'object' lors de la sélection d'une méthode pour la fonction 'rcor' : objet 'dcc.fit_BIST.100' introuvable
> rho.est.line <- list()
> rho.est.line = rcor(dcc.fit_BIST.100, type="R") # plot(rho.est.line[1,2,])
Error in h(simpleError(msg, call)) :
  erreur d'évaluation de l'argument 'object' lors de la sélection d'une méthode pour la fonction 'rcor' : objet 'dcc.fit_BIST.100' introuvable
> outputcorr <- matrix((rho.est.line[1,2,]), nrow = dim(BTC_BIST.100)[1], byrow = TRUE)
Error in rho.est.line[1, 2, ] : nombre de dimensions incorrect
> rho.est = data.frame((outputcorr))
> Corr_BTC_BIST.100 = zoo(rho.est, order.by=index(BTC_BIST.100[,1]))
Error in index(BTC_BIST.100[, 1]) : objet 'BTC_BIST.100' introuvable


À la fin, j'obtiens toutefois un graphique où beaucoup de profils sont constants (est-ce normal ?), mais je ne comprends pas bien quel est le problème sur ce graphique, ou ce qu'il faudrait y afficher en plus :

Image

Alhonita Yatié
Messages : 8
Enregistré le : 09 Mar 2021, 06:46

Re: Plusieurs courbes dans un même espace

Messagepar Alhonita Yatié » 30 Mar 2021, 10:24

Bonjour,

J'ai fait tous les graphiques séparément et il y a des variables qui varient de quelques millièmes. A côté de celles qui ont des grosses variations elles apparaissent donc comme des constantes.

Je vous remercie pour votre aide.


Retourner vers « Questions en cours »

Qui est en ligne

Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 1 invité