# Fit a copula model in R

I want to accomplish the task of creating an optimal portfolio of stocks, the yield between which is modeled using kopulas.

And I have data: return of 4 stocks:

s1 <- read.csv('s1.csv',header=F)$$V2 s2 <- read.csv('s2.csv',header=F)$$V2
s3 <- read.csv('s3.csv',header=F)$$V2 s4 <- read.csv('s4.csv',header=F)$$V2


Then I tried to fit t-copula and plot the density

t.cop <- tCopula(dim=4)
set.seed(500)
m <- pobs(as.matrix(cbind(s1,s2,s3,s4)))
fit <- fitCopula(t.cop,m,method='ml')
coef(fit)
rho <- coef(fit)[1]
df <- coef(fit)[2]
persp(tCopula(dim=2,rho,df=df),dCopula)


But I cant understand how to build other types of copulas(vine copulas for example). And how can I find an optimal portfolio?