This is the R-bloggers article in which a t-distribution copula (?) is fitted to explain the dependency between fluctuations in two stocks tickers. I don't understand what they are trying to achieve, but it seems that the idea is to get parameters of a joint distribution that allow generating samples to test different scenarios.
I figured reproducing the example with two similar stocks would be the best way to get a sense for it, but I got an error:
library('copula')
library('evir')
library('quantmod')
library('VineCopula')
getSymbols("MS", from="2010-01-02", to="2021-01-06", src="yahoo", auto.assign = getOption('loadSymbols.auto.assign',TRUE))
ms.rtn=diff(log(`MS`))
ms <- as.vector(-ms.rtn)
ms <- na.omit(ms)
getSymbols("GOOGL", from="2010-01-02", to="2021-01-06", src="yahoo", auto.assign = getOption('loadSymbols.auto.assign',TRUE))
google.rtn=diff(log(`GOOGL`))
google <- as.vector(-google.rtn)
google <- na.omit(google)
plot(ms, google,pch='.')
abline(lm(google ~ ms), col='red', lwd=1)
cor(ms, google, method='spearman')
u <- pobs(as.matrix(cbind(ms,google)))[,1]
v <- pobs(as.matrix(cbind(ms,google)))[,2]
selectedCopula <- BiCopSelect(u,v,familyset=NA)
selectedCopula
t.cop <- tCopula(dim=2)
set.seed(500)
m <- pobs(as.matrix(cbind(ms,google)))
fit <- fitCopula(t.cop, m, method='ml')
I see another question online on the same topic (different site) that went unanswered.
What is fn
, and why am I running into problems reproducing this example?
fn
is the second argument foroptim
, which here islogL
. $\endgroup$fitCopula()
there are values too close to zero, and yield - infinity values when log transformed? Do you address that by placing a floor on the values? $\endgroup$logL
will refer to log-likelihoods, so the copula fitting is running into the data having a very small likelihood. Simple examples where that can happen are there being no data (i.e.cree
aregoogle
is zero-length), or the data being so large that the likelihood has to be so small that R treats it as zero. I can't say anything more specific without knowing more about howfitCopula
works, I'm afraid. $\endgroup$> length(GOOGL) [1] 16626
Is that too long? $\endgroup$start = c(4, 0.35)
), you'll get somewhere. $\endgroup$