[R-SIG-Finance] Speed up for loop

Eivind K. Dovik hello @ending from eivinddovik@com
Sun May 6 18:14:17 CEST 2018


On Sun, 6 May 2018, Andreas Bregiannis wrote:

> Hello everyone,
>
> I would like to ask you how I can speed up this for loop.  In the following code I generate a sample of 200 of the NIG distribution and then I fit to them the NIG distribution. My aim is to estimate 1mln times the mean parameter of this NIG distribution.
> Any ideas?
>
> library(GeneralizedHyperbolic)
> mu=0;delta = 1;alpha = 1;beta = 0
> m=numeric(1000000)
> for(i in 1:1000000){
> m[i]=coef(nigFit(rnig(200, param = c(mu, delta, alpha, beta))
> ))[1]
> }
>
> Thank you in advance.
> Best,
> Andreas

Hi, Andreas.

How about this?

library(GeneralizedHyperbolic)
mu = 0; delta = 1; alpha = 1; beta = 0

func <- function(){
     random_numbers <- rnig(200, param = c(mu, delta, alpha, beta))
     fit <- nigFit(d)
     return(coef(fit)[1])
}

m <- as.numeric(rep(func(), 1000000)



Eivind K. Dovik
Bergen, NO



>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
>



More information about the R-SIG-Finance mailing list