2013년 12월 28일 토요일

neural network

R script
--------------

library(datasets)

names(infert)

#  *------------------------------------------------------------------*
#  | train the network
#  *------------------------------------------------------------------*

library(neuralnet)

#input is age, parity, induced ...

nn <- neuralnet(
 case~age+parity+induced+spontaneous,
 data=infert, hidden=5, err.fct="ce",
 linear.output=FALSE)

#  *------------------------------------------------------------------*
#  | output training results
#  *------------------------------------------------------------------* 

# basic
nn

# reults options
names(nn)


# result matrix contains weights

nn$result.matrix

# The given data is saved in nn$covariate and
# nn$response as well as in nn$data for the whole data
# set inclusive non-used variables. The output of the
# neural network, i.e. the fitted values o(x), is provided
# by nn$net.result:

out <- cbind(nn$covariate,nn$net.result[[1]])

dimnames(out) <- list(NULL, c("age", "parity","induced","spontaneous","nn-output"))

head(out)


# visualization
plot(nn)


ar(1) model with prediction

R script
----------------------
library(quantmod)
library(fGarch)

URL <- "http://ichart.finance.yahoo.com/table.csv?s=^KS11"
dat <- read.csv(URL)
dat$Date <- as.Date(dat$Date, "%Y-%m-%d")

odat<-dat[c(1:100),]

attach(odat)

x<-odat[order(Date),]

#kospiGarch <- garchFit(~arma(1, 2) + garch(1, 1), data=as.ts(x$Close))

fit <- arima(diff(log(x$Close)), order=c(1,0,0))

#fore <- predict(fit, n.ahead=10, doplot=F)

err <- rnorm(20, 0, .002)

sim <- diff(log(abs(x$Close)))[99]

for (t in 2:20) {
    sim[t] <- fit$coef[2]+ fit$coef[1]*sim[t-1] + err[t]
}

dev.new()
plot(x$Close, type='l', xlim=c(0, 120),
    panel.first=grid(col = "gray", lty = "dotted"), pch=20)
t <- c(101:120)
points(x$Close, pch = 20, col = "red")
for (j in 2:20) {
ye[j] <- exp(sim[j-1])*ye[j-1]
}

points(t, ye, col='red', pch=20, type='b')

지수가중이동평균법

코스피 분석

R 스크립트
-----------------
require(TTR)

URL <- "http://ichart.finance.yahoo.com/table.csv?s=^KS11"
dat <- read.csv(URL)
dat$Date <- as.Date(dat$Date, "%Y-%m-%d")

odat<-dat[c(1:100),]

#N<-99

attach(odat)

x<-odat[order(Date),]

par(mfrow=c(2,1), mar=c(2,3,3,2))
plot(x$Close,type="l", xaxt='n', xlab=NA,
panel.first=grid(col = "gray", lty = "dotted"))
  points(x$Close, pch = 20, col = "red")

price<-x$Close

row<-diff(log(price),1,1)*100

x<-c(1:99)

plot(x, row, type="l", ylim=c(-0.8,0.8), col='lightgray', xaxt='n', xlab=NA)

ema<-EMA(row,n=10)

points(x=x, y=ema, col='green', type='l', xlab=NA)

wma<-WMA(row, n=5, wts=1:5)

points(x=x, y=wma, col='red', type='l')

abline(h=0, col="lightgray")

2013년 12월 1일 일요일

vmware tools download

wget -r -np http://packages.vmware.com/tools/esx/latest/rhel6/i386/index.html

2013년 11월 23일 토요일

gcc -o arraytest.exe arraytest.c arrayinc.obj

// File: arraytest.c
//
// C program to test arrayinc.asm
//

#include <stdio.h>

void arrayinc(int A[], int n) ;

main() {

int A[7] = {2, 7, 19, 45, 3, 42, 9} ;
int i ;

   printf ("sizeof(int) = %d\n", sizeof(int)) ;

   printf("\nOriginal array:\n") ;
   for (i = 0 ; i < 7 ; i++) {
      printf("A[%d] = %d  ", i, A[i]) ;
   }
   printf("\n") ;

   arrayinc(A,7) ;

   printf("\nModified array:\n") ;
   for (i = 0 ; i < 7 ; i++) {
      printf("A[%d] = %d  ", i, A[i]) ;
   }
   printf("\n") ;
   
}


-----------------------------------

; File: arrayinc.asm
;
; A subroutine to be called from C programs.
; Parameters: int A[], int n
; Result: A[0], ... A[n-1] are each incremented by 1


        SECTION .text
        global _arrayinc

_arrayinc:
        push    ebp                     ; set up stack frame
        mov     ebp, esp

        ; registers ebx, esi and edi must be saved, if used
        push    ebx
        push    edi

        mov     edi, [ebp+8]            ; get address of A
        mov     ecx, [ebp+12]           ; get num of elts
        mov     ebx, 0                  ; initialize count

for_loop:
        mov     eax, [edi+4*ebx]        ; get array element
        inc     eax                     ; add 1
        mov     [edi+4*ebx], eax        ; put it back
        inc     ebx                     ; update counter
        loop    for_loop

        pop     edi                     ; restore registers
        pop     ebx
       
        mov     esp, ebp                ; take down stack frame
        pop     ebp

        ret
----------------------------------------

nasm -f obj arrayinc.asm