Search code examples
rstatisticsdistributionquantitative-finance

fBasics::fitStable working suspiciously


I've been working with the fBasics package respectively a fitStable function to fit some series to a more general, stable distributions.

There are two approaches - a quantile method, proposed by McCulloh and then there is the MLE approach.

The function offers both, but the MLE approach is really, really slow and sometimes it even does not compute - and yields NA.

It uses nlminb to maximise the likelihood function ( think it minimises the -likelihood fun ).

But even if it has finished after a long time, the estimate for 1000 observations from standard normal ( for which it should have given the values of (2,0,1,0) ) it gives:

Estimated Parameter(s):
     alpha       beta      gamma      delta 
1.99990000 0.22448469 0.71247528 0.02995476

where I would have expected, at least for the beta to be closer to zero.

Does anyone have any experience to share?

Any idea, how to speed this up?


Solution

  • I tried this with 20 runs of 100 (instead of 1000). Got a lot of betas close to zero (as expected), but some close to -1. Also the gammas are fairly consistent. Time elapsed was 10 minutes.

    library(fBasics)
    set.seed(100)
    x <- rnorm(1000)
    a <- vector(,20)
    b <- vector(,20)
    c <- vector(,20)
    d <- vector(,20)
    
    system.time(
    for(i in 1:20){
        samp <- sample(x, size = 100, replace = T)
        v <- stableFit(samp, type='mle')
        a[i] <- (v@fit)$estimate[1]
        b[i] <- (v@fit)$estimate[2]
        c[i] <- (v@fit)$estimate[3]
        d[i] <- (v@fit)$estimate[4]
    }
    )
    

    System Time:
    user system elapsed
    598.67 1.49 602.80

    a
    

    1.8070, 1.9999, 1.9999, 1.9140, 1.9999, 1.9999, 1.9999, 1.9999, 1.9999, 1.8967, 1.9999, 1.9999, 1.9999, 1.9999, 1.9999, 1.9999, 1.9999, 1.9999, 1.9999, 1.8166

    b
    

    -0.9999, 0.1247, 0.0070, -0.9999, 0.0026, 0.0177, 0.0083 0.0409, 0.0179, 0.3062, 0.8251, -0.0769, 0.0071, -0.7928, -0.9225, -0.0147, -0.7459, -0.0191, 0.0016, -0.9999

    c
    

    0.7121, 0.7337, 0.7654, 0.7287, 0.8393, 0.6441, 0.7475, 0.7113, 0.7204, 0.6475, 0.7065, 0.7408, 0.7269, 0.7191, 0.6453, 0.6824, 0.6815, 0.7642, 0.7970, 0.6347

    d
    

    0.1576, 0.1092, -0.0115, 0.0196, 0.2325, 0.1222, 0.2546, -0.0610, 0.0873, 0.0438 -0.0120, -0.1266, 0.1631, 0.1443, -0.0793, -0.1651, 0.1649, 0.0891, -0.0043, 0.1259