2014년 3월 22일 토요일

css 서서히 나타나는 효과

<!DOCTYPE html>
<html>
<title>Web Page Design</title>
<head>
<style type="text/css">
body{
opacity:0;
-moz-transition: opacity 2s;
-webkit-transition: opacity 2s; /* Safari */
}

</style>
</head>
<body onload="document.body.style.opacity='1'">
this string is to test
</body>
</html>


-------------------
 div id를 이용


<!DOCTYPE html>
<html>
<title>Web Page Design</title>
<head>
<style type="text/css">

#box {   
    height: 300px;   
    position: absolute;
    top: 0;
    left: 0;   
    width: 500px;
    opacity: 0;   
    transition: opacity 3s ease;
}
</style>
<body onload="document.getElementById('box').style.opacity='1'">
<div id="box">
       This is test</div>
</body>
</html>

2014년 3월 16일 일요일

prediction of kospi with arma(2,2)

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),]

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

sim <- diff(log(abs(x$Close)))[99]
sim <- c(sim, diff(log(abs(x$Close)))[98])
err <- rnorm(30, 0, sd(diff(log(x$Close[length(x$Close)-10:length(x$Close)]))))

upcount = 1
downcount = 1

ye <-x$Close[100]

td<-x$Date[100]
group<-rep(i, length(ye))

pred<-data.frame(td, ye, group)

// 시뮬레이션 회수
n<-100

for (i in 1:n){

for (t in 3:100) {

    sim[t] <- fit$coef[1]*sim[t-1] + fit$coef[2]*sim[t-2]
        +fit$coef[3]*err[t-1]
        +fit$coef[4]*err[t-2]

}


err <- rnorm(100, 0, 15)

// 20일간 주가를 예측함
for (j in 2:20) {

td[j] <- x$Date[length(x$Date)] + j

ye[j] <- exp(sim[j-1])*ye[j-1]+err[j-1]

pred<- rbind(pred, data.frame(td=td[j], ye=ye[j], group=i))

}


if (ye[20] > x$Close[100]){
        upcount = upcount+1}
else downcount = downcount +1

}

// 상승확률과 하락확률
cat("Probabilty of upward is", upcount/n)
cat("Probabilty of downward is", downcount/n)


library(ggplot2)
ggplot(pred, aes(x=td, y=ye, colour=group, group=group))+geom_line()




2014년 3월 13일 목요일

arma(2,2)

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),]

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

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

sim <- diff(log(abs(x$Close)))[99]
sim <- c(sim, diff(log(abs(x$Close)))[98])
err <- rnorm(30, 0, sd(diff(log(x$Close[length(x$Close)-10:length(x$Close)]))))


for (t in 3:30) {

    sim[t] <- fit$coef[1]*sim[t-1] + fit$coef[2]*sim[t-2]
        +fit$coef[3]*err[t-1]
        +fit$coef[4]*err[t-2]

}

dev.new()

par(mfrow=c(3,1))

par(mar=c(3,3,1,2))

x$newday <- as.Date(x$Date, "%m/%d/%Y")

plot(x$newday, x$Close, type='l', col='red', xlim=c(x$newday[1],x$newday[length(x$newday)]+20),

    panel.first=grid(col = "gray", lty = "dotted"), pch=20)

points(x$newday, x$Close, pch = 20, col = "red")

ye <- x$Close[100]

td<-x$newday[length(x$newday)]+1

err <- rnorm(30, 0, sd(diff(x$Close[length(x$Close)-50:length(x$Close)])))

for (j in 2:30) {

td[j] <- x$newday[length(x$newday)] + j

ye[j] <- exp(sim[j])*ye[j-1]+err[j-1]

}

td<-as.Date(td)

ye

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

##########################################################

library(forecast)

afit <- auto.arima(x$Close)

fore <- forecast(afit, h=15)

plot(fore)





2014년 3월 12일 수요일

ar2kospi

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),]

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

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

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

for (t in 3:20) {

    sim[t] <- fit$coef[2]*sim[t-2]+ fit$coef[1]*sim[t-1]

}


dev.new()

par(mfrow=c(3,1))

par(mar=c(3,3,1,2))

plot(x$Close, type='l', xlim=c(0, 120), xaxt='n',

    panel.first=grid(col = "gray", lty = "dotted"), pch=20)

t <- c(101:120)

points(x$Close, pch = 20, col = "red")

ye <- x$Close[100]

err <- rnorm(20, 0, sqrt(sd(x$Close[length(x$Close)-50:length(x$Close)])))

for (j in 2:20) {

ye[j] <- exp(sim[j-1])*ye[j-1]+err[j]

}

ye

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

##########################################################

library(forecast)

fit <- auto.arima(x$Close[1:80])
#library(dataframes2xls)
#write.xls(forecast(fit, h=20), "c:/mydata.xls")

write.table(x, "c:/kospi.txt")

plot(forecast(fit, h=20))




2014년 3월 7일 금요일

[perl] 이미지가로 500px 작으면 삭제

use strict;
#use warnings;
use Cwd;

use File::Find;
use Image::Size;

if (@ARGV <1){
print "Useage: $0 [string to search] [file type]\n";
exit 1;
}
 opendir (DIR, $ARGV[0]) or die $!;
   
    my @list;
chdir($ARGV[0]);   
  while (my $file = readdir(DIR)) {

   my ($width, $height ) = imgsize($file);
       
   #print $width;
    if ($width < 500) {
    push(@list,$file);
    }

    }
   
unlink @list;

2014년 3월 4일 화요일

arma(1,1) kospi

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),]

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

err <- rnorm(30, 0, sd(diff(x$Close)))

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

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

par(mfrow=c(3,1))
par(mar=c(3,3,1,2))

x$newday <- as.Date(x$Date, "%m/%d/%Y")
plot(x$newday, x$Close, type='l', col='red',
    panel.first=grid(col = "gray", lty = "dotted"), pch=20)
points(x$newday, x$Close, pch = 20, col = "red")

ye <- x$Close[100]
td<-x$newday[length(x$newday)]+1
for (j in 2:30) {
td[j] <- x$newday[length(x$newday)] + j

ye[j] <- sim[j-1]+ye[j-1]
}

td<-as.Date(td)
points(td, ye, col='red', pch=20, type='b')

plot(diff(x$Close), type='l', col=heat.colors(32)[15],panel.first=grid(col = "gray", lty = "dotted"))
##########################################################

library(forecast)

fit <- auto.arima(x$Close)
fore <- forecast(fit, h=10)
plot(fore)

ye