Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- simuFunctionParNBM<-function(theta, phi, stdEps, stdEta, N, K){
- print(paste("Parallel Processing with N = ",N," and K = ",K))
- library("sandwich")#Lade Paket für Sandwich Schätzer
- library("doMC")
- registerDoMC()
- #Generiere Trade-Indikator
- trade<-matrix(sample(c(1,-1), (N+1)*K, replace=TRUE),ncol=K)
- #Manipuliere `trade` matrix
- tradedelta<-diff(trade)
- tradedelta<-tradedelta[nrow(tradedelta):1,]
- tradelag<-trade[2:nrow(trade),]
- #Generiere Störterme Epsilon und Eta
- epsilon<-matrix(rnorm(N*K), ncol=K)
- eta<-matrix(rnorm((N+1)*K)*0.02, ncol=K)
- etadelta<-diff(eta)
- etadelta<-etadelta[nrow(etadelta):1,]
- #Generiere Midquotedifferenzen als Pointer
- mdelta=theta*tradelag+epsilon
- #Generiere Preisdifferenzen als Pointer
- pricedelta=theta*tradelag+(theta+phi)*tradedelta+epsilon+etadelta
- #Fasse Input Parameter zusammen
- inputParameters<-matrix(c(theta,phi,N,stdEps,stdEta),ncol=5,nrow=1)
- #Beginne Schleife für Schätzung der K Schätzer
- data<-foreach(i=1:K,.combine=rbind) %dopar% {
- #Generiere Zeilen Container
- rowData<-matrix(nrow=1,ncol=40) #Wird auf NULL gesetzt
- nWest<-matrix(nrow=2,ncol=2)
- #Schätzung der Koeffizienten
- tryCatch({
- rowData[1] = regression$coefficients[1] #Schaetzung Theta
- rowData[8] = regression$coefficients[2] #Schaetzung Theta+Phi
- #Schätzung der robusten Standardfehler
- try({
- nWest<-NeweyWest(regression)
- rowData[2] = nWest[1,1]
- rowData[9] = nWest[2,2]
- })
- #print(.Last.value)
- options(show.error.messages = TRUE)
- },
- interrupt = function(ex) {
- cat("An interrupt was detected.\n");
- print(ex)
- },
- error = function(ex) {
- cat("An error was detected.\n")
- print(ex)
- },
- finally = {
- gc()
- })
- return(rowData)
- }
- #Ausgabe der Daten
- return(data)
- gc()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement