Closed stucash closed 3 years ago
Hi can you take a look if it was the function needs some tuning or it was me did something fundamentally wrong?
I am currently digging into it. It may take some time this seems really weird :)
I am currently digging into it. It may take some time this seems really weird :)
thanks for getting back :) sorry I got stuck for some days lol I was so obsessed
I was unable to replicate the negative variance with other data.
Changing the kernel tuning parameter, kernelParam
seems to fix the problem.
I am tempted to just call it numerical instability, which is not really that surprising since the kernel covariance estimator is not guaranteed to be positive semi definite, therefore we can also in the multivariate case get covariance estimates that would theoretically allow for construction of portfolios with negative variance. - Not good.
We automatically map covariance matrices to a positive semi definite matrix, but in the univariate case we can't really do that in a nice way IMO.
I have added a warning when the estimated variance is negative which hints that changing the kernel parameter may help.
Thanks a lot for reporting this.
Thanks for digging into it, I was guessing the same; One interesting thing was, I initially ran the function against few stock symbols (multivariate input) and I remember that's when I first witnessed a negative variance value I then was trying to single out the error. I'll see if I can reproduce it.
Please do, that sounds very weird.
I understand the package is mainly for tick data but I believe minute interval falls into high frequency category as well, therefore I was feeding 15 minute interval intraday demeaned log return data (open-close return) to
rKernelCov
function, withalignBy='minutes'
,alignPeriod=15
. However, I was getting negative variance result.Demeaned Log Return: (testv)
Demeaned Log Return for Beta calculation (testgs):
Original OHLCV (a
tibble
,data.frame
, ordata.table
normally, called v):The function I used to obtain the demeaned log return from original open-close prices is here:
Then I run
rKernelCov
andrBeta
on the return series:The most baffling to me is that the variance was negative in
rKernelCov
and I guessed that it had an impact onrBeta
calculation as well. I can't really see if I have fed into the functions some unstable numeric values but the results from them don't seem right. I hope it was my demeaned log return calculation being wrong that way it's easy to fix (but I can't see that my calculation for return was wrong...)I am running MX Linux 19, R version is 4.0.4 (2021-02-15) -- "Lost Library Book"