{"id":905,"date":"2020-10-17T19:51:06","date_gmt":"2020-10-17T19:51:06","guid":{"rendered":"https:\/\/ricovictor.com\/?page_id=905"},"modified":"2026-01-25T16:26:30","modified_gmt":"2026-01-25T16:26:30","slug":"carteras-con-copulas-matematicas","status":"publish","type":"page","link":"https:\/\/ricovictor.com\/index.php\/carteras-con-copulas-matematicas\/","title":{"rendered":"Modelo de carteras con c\u00f3pulas matem\u00e1ticas"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-page\" data-elementor-id=\"905\" class=\"elementor elementor-905\">\n\t\t\t\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-48858ef2 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"48858ef2\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-781488e0\" data-id=\"781488e0\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-68a608a elementor-widget elementor-widget-heading\" data-id=\"68a608a\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-large\">WEBINAR GRATIS - CARTERAS DE INVERSI\u00d3N <br><br>DCC-GARCH COPULAS<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-17137eb elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"17137eb\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-237f61b\" data-id=\"237f61b\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-2d36e01 elementor-widget elementor-widget-spacer\" data-id=\"2d36e01\" data-element_type=\"widget\" data-widget_type=\"spacer.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-spacer\">\n\t\t\t<div class=\"elementor-spacer-inner\"><\/div>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1e4a805 elementor-widget elementor-widget-text-editor\" data-id=\"1e4a805\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>\ud83d\udc68\u200d\ud83d\udcbb Los <strong>Modelos DCC-GARCH-C\u00f3pulas<\/strong> pueden ser usados para crear carteras de inversi\u00f3n en diferentes activos financieros o tambi\u00e9n para hacer simulaciones a partir de ellos.<\/p>\n<p>La idea con estos modelos es conjuntar los modelos de <strong>volatilidad condicional<\/strong> por un lado con las c\u00f3pulas por otro,todo ello permitiendo crear una estructura que nos permita medir y simular el riesgo de manera<strong> multidimensional<\/strong>.<\/p>\n<p>Aqu\u00ed tienes el Webinar Completo donde explico u m\u00e9todo para crear carteras usando estos modelos \ud83d\udc47\ud83d\udc47<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ee46fad elementor-widget elementor-widget-spacer\" data-id=\"ee46fad\" data-element_type=\"widget\" data-widget_type=\"spacer.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-spacer\">\n\t\t\t<div class=\"elementor-spacer-inner\"><\/div>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-1e361ef elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"1e361ef\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-096a4fe\" data-id=\"096a4fe\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-2e2ecc7 elementor-widget elementor-widget-video\" data-id=\"2e2ecc7\" data-element_type=\"widget\" data-settings=\"{&quot;youtube_url&quot;:&quot;https:\\\/\\\/www.youtube.com\\\/watch?v=OMjnDnGJOqY&amp;t=22s&quot;,&quot;video_type&quot;:&quot;youtube&quot;,&quot;controls&quot;:&quot;yes&quot;}\" data-widget_type=\"video.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-wrapper elementor-open-inline\">\n\t\t\t<div class=\"elementor-video\"><\/div>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-bf3d871 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"bf3d871\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-6ba05f0\" data-id=\"6ba05f0\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-19f0c61 elementor-widget elementor-widget-text-editor\" data-id=\"19f0c61\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<h4>\u00a0<\/h4><h4><strong>CODIGO R DEL WEBINAR<\/strong><\/h4><p>### CLASE CARTERAS VIDEO DCC-GARCH- COPULAS<\/p><p>## INDICES- 10<\/p><p>#### CODIGO CARTERA INDICES #######<br \/>#install.packages(\u00abquantmod\u00bb)<br \/>library(quantmod)<br \/>#install.packages(\u00abtseries\u00bb)<br \/>library(tseries)<br \/>#install.packages(\u00abfImport\u00bb)<br \/>library(fImport)<br \/>#install.packages(\u00abrugarch\u00bb) #para ugarchspec<br \/>library(rugarch) #rugarch: a package for univariate GARCH fitting, simulation and forecast<br \/>#install.packages(\u00abrmgarch\u00bb)<br \/>library(rmgarch) #dccspec<br \/>#install.packages(\u00abccgarch\u00bb)<br \/>library(ccgarch)<br \/>#install.packages(\u00abHAC\u00bb)<br \/>library(HAC)#<br \/>#install.packages(\u00abexpm\u00bb)<br \/>library(expm)<br \/>#install.packages(\u00abfPortfolio\u00bb)<br \/>library(fPortfolio)<br \/>#install.packages(\u00abgtools)<br \/>library(gtools)<\/p><p>#?get.hist.quote<\/p><p>CAC40=get.hist.quote(\u00ab^FCHI\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-06-04&#8243;,end=\u00bb2017-06-04\u00bb)<br \/>DAX=get.hist.quote(\u00ab^GDAXI\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-06-04&#8243;,end=\u00bb2017-06-04\u00bb)<br \/>#FTSEMIB=get.hist.quote(\u00abFTSEMIB.MI\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-03-13&#8243;,end=\u00bb2017-03-13\u00bb)<br \/>FTSE=get.hist.quote(\u00ab^FTSE\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-06-04&#8243;,end=\u00bb2017-06-04\u00bb)<br \/>SWISS=get.hist.quote(\u00ab^SSMI\u00bb,quote=\u00bbClose\u00bb,start =\u00bb2016-06-04&#8243;,end=\u00bb2017-06-04&#8243;)<br \/>IBEX=get.hist.quote(\u00ab^IBEX\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-06-04&#8243;,end=\u00bb2017-06-04\u00bb)<br \/>BELG=get.hist.quote(\u00ab^BFX\u00bb,quote=\u00bbClose\u00bb,start =\u00bb2016-06-04&#8243;,end=\u00bb2017-06-04&#8243;)<br \/>DOW=get.hist.quote(\u00ab^DJI\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-06-04&#8243;,end=\u00bb2017-06-04\u00bb)<br \/>NASDAQ=get.hist.quote(\u00ab^NDX\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-06-04&#8243;,end=\u00bb2017-06-04\u00bb)<br \/>NIKKEI=get.hist.quote(\u00ab^N225&#8243;,quote=\u00bbClose\u00bb,start =\u00bb2016-06-04&#8243;,end=\u00bb2017-06-04&#8243;)<br \/>SINGAPUR=get.hist.quote(\u00ab^STI\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-06-04&#8243;,end=\u00bb2017-06-04\u00bb)<br \/>HONG=get.hist.quote(\u00ab^HSI\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-06-04&#8243;,end=\u00bb2017-06-04\u00bb)<br \/>HONG1=get.hist.quote(\u00ab^HSI\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-06-04&#8243;,end=\u00bb2017-06-04\u00bb)<br \/>SP500=get.hist.quote(\u00ab^GSPC\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-06-04&#8243;,end=\u00bb2017-06-04\u00bb)<br \/>STOXX50=get.hist.quote(\u00ab^STOXX50E\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-06-04&#8243;,end=\u00bb2017-06-04\u00bb)<br \/>#HOLANDA=get.hist.quote(\u00ab^STOXX50E\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-03-28&#8243;,end=\u00bb2017-03-28\u00bb)<br \/>HOLANDA&lt;- get.hist.quote(\u00ab^AEX\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-06-04&#8243;,end=\u00bb2017-06-04\u00bb)<br \/>#getSymbols(\u00abEURUSD=X\u00bb,src=\u00bbyahoo\u00bb,from = \u00ab2016-06-04\u00bb)<br \/>#getSymbols(\u00abCADCHF=X\u00bb,src=\u00bbyahoo\u00bb,from = \u00ab2016-06-04\u00bb)<\/p><p>CAC40=getSymbols(\u00ab^FCHI\u00bb,quote=\u00bbClose\u00bb,from = \u00ab2019-10-06\u00bb)<br \/>CAC40= FCHI[,4]<br \/>getSymbols(\u00ab^GDAXI\u00bb,quote=\u00bbClose\u00bb,from = \u00ab2019-10-06\u00bb)<br \/>head(GDAXI)<br \/>DAX= GDAXI[,4]<\/p><p>#FTSEMIB=get.hist.quote(\u00abFTSEMIB.MI\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-03-13&#8243;,end=\u00bb2017-03-13\u00bb)<br \/>#FTSE=getSymbols(\u00ab^FTSE\u00bb,quote=\u00bbClose\u00bb,from = \u00ab2016-06-04&#8243;,end=\u00bb2017-06-04\u00bb)<\/p><p>getSymbols(\u00ab^SSMI\u00bb,quote=\u00bbClose\u00bb,from =\u00bb2019-10-06&#8243;)<br \/>SWISS = SSMI[,4]<\/p><p>getSymbols(\u00ab^IBEX\u00bb,quote=\u00bbClose\u00bb,from = \u00ab2019-10-06\u00bb)<br \/>IBEX= IBEX[,4]<br \/>#BELG=get.hist.quote(\u00ab^BFX\u00bb,quote=\u00bbClose\u00bb,start =\u00bb2016-06-04&#8243;,end=\u00bb2017-06-04&#8243;)<\/p><p>getSymbols(\u00ab^DJI\u00bb,quote=\u00bbClose\u00bb,from =\u00bb2019-10-06&#8243;)<br \/>DOW= DJI[,4]<br \/>getSymbols(\u00ab^NDX\u00bb,quote=\u00bbClose\u00bb,from = \u00ab2019-10-06\u00bb)<br \/>NASDAQ=NDX[,4]<br \/>getSymbols(\u00ab^N225&#8243;,quote=\u00bbClose\u00bb,from =\u00bb2019-10-06&#8243;)<br \/>NIKKEI=N225[,4]<br \/>getSymbols(\u00ab^STI\u00bb,quote=\u00bbClose\u00bb,from = \u00ab2019-03-04\u00bb)<br \/>SINGAPUR=STI[,4]<br \/>getSymbols(\u00ab^HSI\u00bb,quote=\u00bbClose\u00bb,from = \u00ab2019-10-06\u00bb)<br \/>HONG=HSI[,4]<br \/>plot(HONG,type=\u00bbl\u00bb)<br \/>HONG1=getSymbols(\u00ab^HSI\u00bb,quote=\u00bbClose\u00bb,from =\u00bb2019-10-06&#8243;)<\/p><p>getSymbols(\u00ab^AEX\u00bb,quote=\u00bbClose\u00bb,from =\u00bb2019-10-06&#8243;)<br \/>HOLANDA=AEX[,4]<\/p><p>#SP500=get.hist.quote(\u00ab^GSPC\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-06-04&#8243;,end=\u00bb2017-06-04\u00bb)<br \/>#STOXX50=get.hist.quote(\u00ab^STOXX50E\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-06-04&#8243;,end=\u00bb2017-06-04\u00bb)<br \/>#HOLANDA=get.hist.quote(\u00ab^STOXX50E\u00bb,quote=\u00bbClose\u00bb,start = \u00ab2016-03-28&#8243;,end=\u00bb2017-03-28\u00bb)<\/p><p>#X&lt;-timeSequence(from=\u00bb2017-04-18&#8243;,to =\u00bb2017-04-18&#8243;,by=\u00bbday\u00bb)<br \/>#X<br \/>#X2&lt;-23924.54<br \/>#P&lt;-timeSeries(X2,X)<br \/>#P<br \/>#cHONG&lt;-rbind(HONG,P,HONG1)<br \/>#plot(cHONG,type=\u00bbl\u00bb)<\/p><p>#1. Elegir 10 indicies por independecia lineal<\/p><p>FX1=na.omit(cbind(CAC40,DAX,SWISS,IBEX,DOW,NASDAQ,NIKKEI,SINGAPUR,HONG,HOLANDA))<br \/>head(FX1)<\/p><p>FX1=returns(FX1)<br \/>FX1=100*FX1[,1:ncol(FX1)]<br \/>FX&lt;-as.timeSeries(FX1)<br \/>FX&lt;-na.omit(FX)<br \/>head(FX)<\/p><p>apply(FX,2,mean)<br \/>mu&lt;-matrix(apply(FX,2,mean))<br \/>mu1&lt;-t(mu) #media simple Esta media podr\u00eda calcularse por el metodo de rendimiento simple<br \/>mu1<br \/>plot(FX)<br \/>head(FX)<\/p><p>plot(FX[,9],xlab=\u00bbRetornos HONG KONG\u00bb)<\/p><p>cor(FX)<\/p><p>#Asumimos una distribuci\u00f3n t-student multivariada\/ Ver Normal multivariada<\/p><p>#install.packages(\u00abrugarch\u00bb) #para ugarchspec<br \/>#library(rugarch) #rugarch: a package for univariate GARCH fitting, simulation and forecast<\/p><p>#install.packages(\u00abrmgarch\u00bb)<br \/>#library(rmgarch) #dccspec<\/p><p>#install.packages(\u00abccgarch\u00bb)<br \/>#library(ccgarch)<\/p><p>garch11.spec&lt;-ugarchspec(mean.model = list(armaOrder = c(0,0), include.mean=T),<br \/>variance.model = list(garchOrder = c(1,1),model = \u00absGARCH\u00bb))<\/p><p>#DCC-GARCH &#8212; VARIAS DISTRIBUIONES<br \/>dcc.garch11.spec&lt;-dccspec(uspec = multispec(replicate(10, garch11.spec)), <br \/>dccOrder = c(1,1),distribution = \u00abmvt\u00bb)<\/p><p># APLICAMOS MODELO A NUESTRA TABLA<\/p><p>garch11.dcc.fit&lt;-dccfit(dcc.garch11.spec, data = FX)<br \/>garch11.dcc.fit<\/p><p>#max&lt;-garch11.dcc.fit@mfit$log.likelihoods<\/p><p>AICdcc&lt;-infocriteria(garch11.dcc.fit)[1]<br \/>AICdcc<\/p><p>#???plot(garch11.dcc.fit)<\/p><p>#?dccfit<br \/>#fcst.h&lt;-(rcov(garch11.dcc.fit))<br \/>#last(fcst.h)<\/p><p>#Predicci\u00f3n con dcc. Est\u00e1 por defecto 1 pero se puede poner las que se desee<\/p><p>fcst&lt;-(dccforecast(garch11.dcc.fit))<br \/>fcst<\/p><p>fcst.h&lt;-matrix(fcst@mforecast$H[[1]],nrow=10)#Matriz covarianzas pred<br \/>fcst.h<br \/>fcst.mu&lt;-matrix(fcst@mforecast$mu,nrow=1) #medias arma prediccion<br \/>fcst.mu<\/p><p>#######3<\/p><p>#1. activos<br \/># DCC-GARCH &#8212; Predecir y varianzas y media predichas( Modelizaci\u00f3n <br \/>#volatilidad)<\/p><p>#Sacamos los residuos y modelizar con Las copulas<\/p><p>garch11.dcc.res&lt;-(garch11.dcc.fit@mfit$stdresid)<\/p><p>#garch11.dcc.fit@mfit$stdresid<\/p><p>res1&lt;-garch11.dcc.res[,1]<br \/>res2&lt;-garch11.dcc.res[,2]<br \/>res3&lt;-garch11.dcc.res[,3]<br \/>res4&lt;-garch11.dcc.res[,4]<br \/>res5&lt;-garch11.dcc.res[,5]<br \/>res6&lt;-garch11.dcc.res[,6]<br \/>res7&lt;-garch11.dcc.res[,7]<br \/>res8&lt;-garch11.dcc.res[,8]<br \/>res9&lt;-garch11.dcc.res[,9]<br \/>res10&lt;-garch11.dcc.res[,10]<\/p><p>plot(res10,type=\u00bbl\u00bb)<\/p><p>######################## Copula Fitting and Simulation ##########################<\/p><p>#Aplicaci\u00f3n de copulas<br \/>#aqu\u00ed fija una copula arquimediana de la forma Hierarquical<\/p><p>#install.packages(\u00abHAC\u00bb)<br \/>library(HAC)#HAC: a package for hierarchical Archimedean copula<\/p><p>results&lt;-estimate.copula(cbind(res1,res2,res3,res4,res5,res6,res7,res8,res9,res10),type=3,margins=&#8217;t&#8217;)<br \/>results<br \/>#?estimate.copula#The function estimates the parameters and determines the structure of Hierarchical Archimedean Copulae.<br \/>plot(results)<\/p><p>##SIMULAMOS COPULA<br \/>#??hac2nacopula<br \/>na.cop&lt;-hac2nacopula(results)<br \/>na.cop<\/p><p>boo&lt;-length(res1)<\/p><p>###<\/p><p>set.seed(2)<\/p><p>cop.sim=rnacopula(boo,na.cop)<br \/>head(cop.sim)<\/p><p>##simulate residuals using the simulated copula distribution<br \/>#Simulaci\u00f3n de nuevos resiudos(serie) con los par\u00e1metros de la c\u00f3pula<\/p><p>res.sim= cbind(qt(cop.sim[,1],df=length(res1)-1),qt(cop.sim[,2],df=length(res2)-1),<br \/>qt(cop.sim[,3],df=length(res3)-1),qt(cop.sim[,4],df=length(res4)-1),<br \/>qt(cop.sim[,5],df=length(res5)-1),qt(cop.sim[,6],df=length(res6)-1),<br \/>qt(cop.sim[,7],df=length(res7)-1),qt(cop.sim[,8],df=length(res8)-1),<br \/>qt(cop.sim[,9],df=length(res9)-1), qt(cop.sim[,10],df=length(res10)-1))<\/p><p>res.sim<\/p><p>plot(res.sim[,3],type=\u00bbl\u00bb)<\/p><p>######### SIMULACION DE RETORNOS DCC-GARCH-COPULA ##########<\/p><p>#simulamos los nuevos retornos con los que calcularemos var y la cartera<\/p><p>#install.packages(\u00abexpm\u00bb)<br \/>library(expm)<\/p><p>logret&lt;-matrix(,nrow=boo,ncol=10)<br \/>logret<br \/>sqrt.h&lt;-sqrtm(fcst.h)<br \/>sqrt.h<\/p><p>#logret&lt;-matrix(rep(mu1,each=boo),ncol=10)+t(sqrt.h%*%t(res.sim))<\/p><p>logret&lt;-matrix(rep(fcst.mu,each=boo),ncol=10)+t(sqrt.h%*%t(res.sim))<br \/>medias&lt;-rbind(mu1,fcst.mu)<br \/>medias<br \/>plot(logret[,1],type=\u00bbl\u00bb)<br \/>plot(logret[,2],type=\u00bbl\u00bb)<\/p><p>#FX1&lt;-logret<\/p><p>acum&lt;- apply(logret,2,cumsum)<br \/>acum<br \/>plot(acum[,10],type=\u00bbl\u00bb)<\/p><p>FX1&lt;-rbind(FX,logret)<\/p><p>colnames(FX1)&lt;-c(\u00abCAC40&#8243;,\u00bbDAX\u00bb,\u00bbSWISS\u00bb,\u00bbIBEX\u00bb,\u00bbDOW\u00bb,\u00bbNASDAQ\u00bb,\u00bbNIKKEI\u00bb,\u00bbSINGAPUR\u00bb,\u00bbHONG\u00bb,\u00bbHOLANDA\u00bb)<br \/>plot(FX1)<\/p><p>##########################<\/p><p>apply(FX1,2,mean)<\/p><p>A&lt;-matrix(apply(FX1,2,mean))<br \/>A1&lt;-t(A) #media simple Esta media podr\u00eda calcularse por el metodo de rendimiento simple<br \/>A1<\/p><p>reb3&lt;-A1&lt;0<br \/>reb3<br \/>rebb&lt;-replace(reb3,reb3==TRUE,-1)<br \/>rebb<br \/>REBfinal&lt;-replace(rebb,rebb==0,1)<br \/>REBfinal<br \/>REBfinal&lt;-t(matrix(REBfinal))<br \/>REBfinal<br \/>########################################<\/p><p>V1&lt;-as.timeSeries(rep(REBfinal[1,1],nrow(FX1)))<br \/>V2&lt;-as.timeSeries(rep(REBfinal[1,2],nrow(FX1)))<br \/>V3&lt;-as.timeSeries(rep(REBfinal[1,3],nrow(FX1)))<br \/>V4&lt;-as.timeSeries(rep(REBfinal[1,4],nrow(FX1)))<br \/>V5&lt;-as.timeSeries(rep(REBfinal[1,5],nrow(FX1)))<br \/>V6&lt;-as.timeSeries(rep(REBfinal[1,6],nrow(FX1)))<br \/>V7&lt;-as.timeSeries(rep(REBfinal[1,7],nrow(FX1)))<br \/>V8&lt;-as.timeSeries(rep(REBfinal[1,8],nrow(FX1)))<br \/>V9&lt;-as.timeSeries(rep(REBfinal[1,9],nrow(FX1)))<br \/>V10&lt;-as.timeSeries(rep(REBfinal[1,10],nrow(FX1)))<\/p><p>buena&lt;- cbind(V1,V2,V3,V4,V5,V6,V7,V8,V9,V10)<br \/>buena<\/p><p>FXX&lt;- FX1*buena<\/p><p>colnames(FXX)&lt;-c(\u00abCAC40&#8243;,\u00bbDAX\u00bb,\u00bbSWISS\u00bb,\u00bbIBEX\u00bb,\u00bbDOW\u00bb,\u00bbNASDAQ\u00bb,\u00bbNIKKEI\u00bb,\u00bbSINGAPUR\u00bb,\u00bbHONG\u00bb,\u00bbHOLANDA\u00bb)<br \/>apply(FXX,2,mean)<\/p><p>#install.packages(\u00abfPortfolio\u00bb)<br \/>library(fPortfolio)<\/p><p>x=portfolioSpec()<br \/>#setOptimize(x)=\u00bbmaxReturn\u00bb<br \/>setType(x)=\u00bbCVAR\u00bb<br \/>setAlpha(x)=0.05<br \/>setSolver(x)=\u00bbsolveRglpk.CVAR\u00bb<br \/>#setSolver(x)=\u00bb solveRquadprog\u00bb<\/p><p>rest=c(\u00abminW[1:10]=-0.25&#8243;,\u00bbmaxW[1:10]=0.25\u00bb)<\/p><p>y=tangencyPortfolio(data=FXX,spec=x,constraints=rest)<br \/>print(y)<\/p><p>pesos&lt;- y@portfolio@portfolio$weights<br \/>pesos<\/p><p>Apalancamiento&lt;-sum(abs(pesos))<\/p><p>posicionAy&lt;- (pesos\/Apalancamiento)*2<br \/>AYONDOWEIGHT&lt;-posicionAy*REBfinal<br \/>colnames(AYONDOWEIGHT)&lt;-c(\u00abCAC40&#8243;,\u00bbDAX\u00bb,\u00bbSWISS\u00bb,\u00bbIBEX\u00bb,\u00bbDOW\u00bb,\u00bbNASDAQ\u00bb,\u00bbNIKKEI\u00bb,\u00bbSINGAPUR\u00bb,\u00bbHONG\u00bb,\u00bbHOLANDA\u00bb)<br \/>AYONDOWEIGHT<\/p><p>##########################<\/p><p># Transformamos<br \/>a = apply(FX1,2,mean)<br \/>a<br \/>negativos = c()<br \/>positivos = c()<br \/>for (i in 1:length(a))<br \/>{<br \/>if (a[i] &lt; 0)<br \/>{<br \/>negativos = c(negativos,i)<br \/>}<br \/>else<br \/>{<br \/>positivos = c(positivos,i)<br \/>}<br \/>}<br \/>positivar = function(x)<br \/>{<br \/>x*-1<br \/>}<\/p><p># Positivemos y cbindemos<br \/>apply(FX1[,negativos],2,mean)<br \/>FXc = positivar(FX1[,negativos])<br \/>apply(FXc,2,mean)<br \/>FXc1 = cbind(FXc,FX1[,positivos])<br \/>apply(FXc1,2,mean)<br \/>FXX&lt;-as.timeSeries(FXc1)<br \/>head(FXX)<br \/>FXX&lt;-FX1<\/p><p>#FECHA &lt;-timeSequence(from=\u00bb2012-01-02&#8243;,to=\u00bb2016-12-31&#8243;,by= \u00abday\u00bb)<br \/>#fxx&lt;-as.xts(FXc1,FECHA)<\/p><p>#FXX&lt;-as.timeSeries(fxx[\u00ab2012-01-02::2012-12-31\u00bb])<\/p><p>#colnames(FXX)&lt;-c(\u00abCADCHF\u00bb,\u00bbAUDNZD\u00bb,\u00bbAUDUSD\u00bb,\u00bbEURCHF\u00bb,\u00bbEURGBP\u00bb,\u00bbEURJPY\u00bb,\u00bbEURNZD\u00bb,\u00bbEURUSD\u00bb,\u00bbGBPCHF\u00bb,\u00bbNZDCAD\u00bb)<\/p><p>#CREaMOS LA CARTERA<\/p><p>#install.packages(\u00abfPortfolio\u00bb)<br \/>library(fPortfolio)<\/p><p>x=portfolioSpec()<br \/>setType(x)=\u00bbCVAR\u00bb<br \/>setAlpha(x)=0.05<br \/>setSolver(x)=\u00bbsolveRglpk.CVAR\u00bb<br \/>rest=c(\u00abminW[1:10]=-0.25&#8243;,\u00bbmaxW[1:10]=0.25\u00bb)<br \/>y=tangencyPortfolio(data=FXX,spec=x,constraints=rest)<br \/>print(y)<br \/>a<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-b6b8d10 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"b6b8d10\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-aeef8b1\" data-id=\"aeef8b1\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-86ee0f3 elementor-widget elementor-widget-heading\" data-id=\"86ee0f3\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-large\">OTROS CURSOS QUE TE AYUDAR\u00c1N<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-b8d7139 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"b8d7139\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-top-column elementor-element elementor-element-9941db7\" data-id=\"9941db7\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-a7d42f7 elementor-align-center elementor-widget elementor-widget-button\" data-id=\"a7d42f7\" data-element_type=\"widget\" data-widget_type=\"button.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-button-wrapper\">\n\t\t\t<a class=\"elementor-button elementor-button-link elementor-size-xl\" href=\"https:\/\/ricovictor.com\/index.php\/carteras-de-inversion\/\">\n\t\t\t\t\t\t<span class=\"elementor-button-content-wrapper\">\n\t\t\t\t\t\t<span class=\"elementor-button-text\">CARTERAS DE INVERSI\u00d3N <br>EN R<\/span>\n\t\t<\/span>\n\t\t\t\t\t<\/a>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-50 elementor-top-column elementor-element elementor-element-8794694\" data-id=\"8794694\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap\">\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>WEBINAR GRATIS &#8211; CARTERAS DE INVERSI\u00d3N DCC-GARCH COPULAS \ud83d\udc68\u200d\ud83d\udcbb Los Modelos DCC-GARCH-C\u00f3pulas pueden ser usados para crear carteras de inversi\u00f3n en diferentes activos financieros o tambi\u00e9n para hacer simulaciones a partir de ellos. La idea con estos modelos es conjuntar los modelos de volatilidad condicional por un lado con las c\u00f3pulas por otro,todo ello permitiendo &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/ricovictor.com\/index.php\/carteras-con-copulas-matematicas\/\"> <span class=\"screen-reader-text\">Modelo de carteras con c\u00f3pulas matem\u00e1ticas<\/span> Leer m\u00e1s &raquo;<\/a><\/p>\n","protected":false},"author":19,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Modelo de carteras con c\u00f3pulas matem\u00e1ticas - V\u00edctor A. Rico \u2014 Econometr\u00eda y Finanzas Cuantitativas<\/title>\n<meta name=\"robots\" content=\"noindex, follow\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Modelo de carteras con c\u00f3pulas matem\u00e1ticas - V\u00edctor A. Rico \u2014 Econometr\u00eda y Finanzas Cuantitativas\" \/>\n<meta property=\"og:description\" content=\"WEBINAR GRATIS &#8211; CARTERAS DE INVERSI\u00d3N DCC-GARCH COPULAS \ud83d\udc68\u200d\ud83d\udcbb Los Modelos DCC-GARCH-C\u00f3pulas pueden ser usados para crear carteras de inversi\u00f3n en diferentes activos financieros o tambi\u00e9n para hacer simulaciones a partir de ellos. La idea con estos modelos es conjuntar los modelos de volatilidad condicional por un lado con las c\u00f3pulas por otro,todo ello permitiendo &hellip; Modelo de carteras con c\u00f3pulas matem\u00e1ticas Leer m\u00e1s &raquo;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ricovictor.com\/index.php\/carteras-con-copulas-matematicas\/\" \/>\n<meta property=\"og:site_name\" content=\"V\u00edctor A. Rico \u2014 Econometr\u00eda y Finanzas Cuantitativas\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-25T16:26:30+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ricovictor.com\/index.php\/carteras-con-copulas-matematicas\/\",\"url\":\"https:\/\/ricovictor.com\/index.php\/carteras-con-copulas-matematicas\/\",\"name\":\"Modelo de carteras con c\u00f3pulas matem\u00e1ticas - V\u00edctor A. Rico \u2014 Econometr\u00eda y Finanzas Cuantitativas\",\"isPartOf\":{\"@id\":\"https:\/\/ricovictor.com\/#website\"},\"datePublished\":\"2020-10-17T19:51:06+00:00\",\"dateModified\":\"2026-01-25T16:26:30+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/ricovictor.com\/index.php\/carteras-con-copulas-matematicas\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ricovictor.com\/index.php\/carteras-con-copulas-matematicas\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ricovictor.com\/index.php\/carteras-con-copulas-matematicas\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Portada\",\"item\":\"https:\/\/ricovictor.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Modelo de carteras con c\u00f3pulas matem\u00e1ticas\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ricovictor.com\/#website\",\"url\":\"https:\/\/ricovictor.com\/\",\"name\":\"V\u00edctor A. Rico \u2014 Econometr\u00eda y Finanzas Cuantitativas\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/ricovictor.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ricovictor.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"es\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/ricovictor.com\/#organization\",\"name\":\"V\u00edctor A. Rico \u2014 Econometr\u00eda y Finanzas Cuantitativas\",\"url\":\"https:\/\/ricovictor.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/ricovictor.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/ricovictor.com\/wp-content\/uploads\/2026\/02\/cropped-ChatGPT-Image-4-feb-2026-12_41_28.png\",\"contentUrl\":\"https:\/\/ricovictor.com\/wp-content\/uploads\/2026\/02\/cropped-ChatGPT-Image-4-feb-2026-12_41_28.png\",\"width\":1402,\"height\":474,\"caption\":\"V\u00edctor A. Rico \u2014 Econometr\u00eda y Finanzas Cuantitativas\"},\"image\":{\"@id\":\"https:\/\/ricovictor.com\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Modelo de carteras con c\u00f3pulas matem\u00e1ticas - V\u00edctor A. Rico \u2014 Econometr\u00eda y Finanzas Cuantitativas","robots":{"index":"noindex","follow":"follow"},"og_locale":"es_ES","og_type":"article","og_title":"Modelo de carteras con c\u00f3pulas matem\u00e1ticas - V\u00edctor A. Rico \u2014 Econometr\u00eda y Finanzas Cuantitativas","og_description":"WEBINAR GRATIS &#8211; CARTERAS DE INVERSI\u00d3N DCC-GARCH COPULAS \ud83d\udc68\u200d\ud83d\udcbb Los Modelos DCC-GARCH-C\u00f3pulas pueden ser usados para crear carteras de inversi\u00f3n en diferentes activos financieros o tambi\u00e9n para hacer simulaciones a partir de ellos. La idea con estos modelos es conjuntar los modelos de volatilidad condicional por un lado con las c\u00f3pulas por otro,todo ello permitiendo &hellip; Modelo de carteras con c\u00f3pulas matem\u00e1ticas Leer m\u00e1s &raquo;","og_url":"https:\/\/ricovictor.com\/index.php\/carteras-con-copulas-matematicas\/","og_site_name":"V\u00edctor A. Rico \u2014 Econometr\u00eda y Finanzas Cuantitativas","article_modified_time":"2026-01-25T16:26:30+00:00","twitter_card":"summary_large_image","twitter_misc":{"Tiempo de lectura":"4 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/ricovictor.com\/index.php\/carteras-con-copulas-matematicas\/","url":"https:\/\/ricovictor.com\/index.php\/carteras-con-copulas-matematicas\/","name":"Modelo de carteras con c\u00f3pulas matem\u00e1ticas - V\u00edctor A. Rico \u2014 Econometr\u00eda y Finanzas Cuantitativas","isPartOf":{"@id":"https:\/\/ricovictor.com\/#website"},"datePublished":"2020-10-17T19:51:06+00:00","dateModified":"2026-01-25T16:26:30+00:00","breadcrumb":{"@id":"https:\/\/ricovictor.com\/index.php\/carteras-con-copulas-matematicas\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ricovictor.com\/index.php\/carteras-con-copulas-matematicas\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/ricovictor.com\/index.php\/carteras-con-copulas-matematicas\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Portada","item":"https:\/\/ricovictor.com\/"},{"@type":"ListItem","position":2,"name":"Modelo de carteras con c\u00f3pulas matem\u00e1ticas"}]},{"@type":"WebSite","@id":"https:\/\/ricovictor.com\/#website","url":"https:\/\/ricovictor.com\/","name":"V\u00edctor A. Rico \u2014 Econometr\u00eda y Finanzas Cuantitativas","description":"","publisher":{"@id":"https:\/\/ricovictor.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ricovictor.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"es"},{"@type":"Organization","@id":"https:\/\/ricovictor.com\/#organization","name":"V\u00edctor A. Rico \u2014 Econometr\u00eda y Finanzas Cuantitativas","url":"https:\/\/ricovictor.com\/","logo":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/ricovictor.com\/#\/schema\/logo\/image\/","url":"https:\/\/ricovictor.com\/wp-content\/uploads\/2026\/02\/cropped-ChatGPT-Image-4-feb-2026-12_41_28.png","contentUrl":"https:\/\/ricovictor.com\/wp-content\/uploads\/2026\/02\/cropped-ChatGPT-Image-4-feb-2026-12_41_28.png","width":1402,"height":474,"caption":"V\u00edctor A. Rico \u2014 Econometr\u00eda y Finanzas Cuantitativas"},"image":{"@id":"https:\/\/ricovictor.com\/#\/schema\/logo\/image\/"}}]}},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/ricovictor.com\/index.php\/wp-json\/wp\/v2\/pages\/905"}],"collection":[{"href":"https:\/\/ricovictor.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ricovictor.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ricovictor.com\/index.php\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/ricovictor.com\/index.php\/wp-json\/wp\/v2\/comments?post=905"}],"version-history":[{"count":9,"href":"https:\/\/ricovictor.com\/index.php\/wp-json\/wp\/v2\/pages\/905\/revisions"}],"predecessor-version":[{"id":4028,"href":"https:\/\/ricovictor.com\/index.php\/wp-json\/wp\/v2\/pages\/905\/revisions\/4028"}],"wp:attachment":[{"href":"https:\/\/ricovictor.com\/index.php\/wp-json\/wp\/v2\/media?parent=905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}