2014년 1월 24일 금요일
css table
.td1_th {border-width:1px;border-color:#e1e1e1;border-style:solid;background-color:#ffffff;}
2014년 1월 23일 목요일
javascript
var div = document.getElementById("container");
var rect = div.getBoundingClientRect();
document.getElementById("banner").innerHTML = ("<div style='position:absolute;top: "+rect.left+"px'> <img src='http://hmwatch.woobi.co.kr/sci/images/icm.png' />");
var rect = div.getBoundingClientRect();
document.getElementById("banner").innerHTML = ("<div style='position:absolute;top: "+rect.left+"px'> <img src='http://hmwatch.woobi.co.kr/sci/images/icm.png' />");
2014년 1월 14일 화요일
2014년 1월 12일 일요일
ar1 of kospi
with prediction
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()
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]
for (j in 2:20) {
ye[j] <- exp(sim[j-1])*ye[j-1]
}
ye
points(t, ye, col='red', pch=20, type='b')
##########################################################
library(forecast)
fit <- auto.arima(x$Close)
plot(forecast(fit, h=20))
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()
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]
for (j in 2:20) {
ye[j] <- exp(sim[j-1])*ye[j-1]
}
ye
points(t, ye, col='red', pch=20, type='b')
##########################################################
library(forecast)
fit <- auto.arima(x$Close)
plot(forecast(fit, h=20))
2014년 1월 5일 일요일
arch(1) model
require(tseries)
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),]
price <- x[[2]]
ret <- 0
for (i in 1:length(price)) {
ret[i] <- (price[i]-price[1])/price[1]
}
par(mfrow=c(3,1))
par(mar=c(3,3,1,2))
x=c(1:length(ret))
plot(price, type='l', xaxt='n')
y<-diff(price)
plot(x = y, ylab = expression(y[t]), xlab = "t", type = "l", col = "red",
panel.first=grid(col = "gray", lty = "dotted"))
points(x = y, pch = 20, col = "blue")
x.arch <- garch(ret-mean(ret), order = c(0,1), trace=TRUE) # Fit ARCH(1)
#summary(x.arch) # Diagnostic tests
vol <- x.arch$fitted.values[,1]
plot(x, ret, type='l', col='lightgray', ylim=c(-0.01,0.08), xaxt='n')
points(x=x, y=vol, col='red', type='l')
abline(h=0, col="lightgray")
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),]
price <- x[[2]]
ret <- 0
for (i in 1:length(price)) {
ret[i] <- (price[i]-price[1])/price[1]
}
par(mfrow=c(3,1))
par(mar=c(3,3,1,2))
x=c(1:length(ret))
plot(price, type='l', xaxt='n')
y<-diff(price)
plot(x = y, ylab = expression(y[t]), xlab = "t", type = "l", col = "red",
panel.first=grid(col = "gray", lty = "dotted"))
points(x = y, pch = 20, col = "blue")
x.arch <- garch(ret-mean(ret), order = c(0,1), trace=TRUE) # Fit ARCH(1)
#summary(x.arch) # Diagnostic tests
vol <- x.arch$fitted.values[,1]
plot(x, ret, type='l', col='lightgray', ylim=c(-0.01,0.08), xaxt='n')
points(x=x, y=vol, col='red', type='l')
abline(h=0, col="lightgray")
파이를 무한자리수까지 계산하는 파이썬 코드
교양수학책을 읽다보면 파이나 e 같은 무한소수의 자리수를 10조자리까지 계산했다느니 뭐니 하는 얘기를 자주 접하게 된다. 그래서 지금 펜티엄코어2로 돌리면 시간이 어느 정도 걸리나 한번 테스트해보려고 했다.
그런데 막상 c로 알고리즘을 만드려니까 자리수 계산하려면 배열에 동적메모리 할당해서 넣어야 하는데 막상 구현하려니 머리가 멍해짐. 웹페이지 검색해보니 코드와 함께 우리말로 설명이 된 웹페이지는 찾을 수가 없었다.
구글에서 infinite precision pi로 검색하다가 c#으로 된 페이지를 겨우 찾았는데 읽다가 졸려서 아침에 보려고 나뒀는데 실수로 검색창을 닫아버려서 다시 검색하다가 발견한 페이지.
http://rosettacode.org/wiki/Pi
c로 하려니까 gmp.h 헤더파일 인클루드하라고 에러 나와서 귀찾아서 파이선으로 돌림.
파이선 코드
------------
def calcPi():
q, r, t, k, n, l = 1, 0, 1, 1, 3, 3
while True:
if 4*q+r-t < n*t:
yield n
nr = 10*(r-n*t)
n = ((10*(3*q+r))//t)-10*n
q *= 10
r = nr
else:
nr = (2*q+r)*l
nn = (q*(7*k)+2+(r*l))//(t*l)
q *= k
t *= l
l += 2
k += 1
n = nn
r = nr
import sys
pi_digits = calcPi()
i = 0
for d in pi_digits:
sys.stdout.write(str(d))
i += 1
if i == 40: print(""); i = 0
그런데 막상 c로 알고리즘을 만드려니까 자리수 계산하려면 배열에 동적메모리 할당해서 넣어야 하는데 막상 구현하려니 머리가 멍해짐. 웹페이지 검색해보니 코드와 함께 우리말로 설명이 된 웹페이지는 찾을 수가 없었다.
구글에서 infinite precision pi로 검색하다가 c#으로 된 페이지를 겨우 찾았는데 읽다가 졸려서 아침에 보려고 나뒀는데 실수로 검색창을 닫아버려서 다시 검색하다가 발견한 페이지.
http://rosettacode.org/wiki/Pi
c로 하려니까 gmp.h 헤더파일 인클루드하라고 에러 나와서 귀찾아서 파이선으로 돌림.
파이선 코드
------------
def calcPi():
q, r, t, k, n, l = 1, 0, 1, 1, 3, 3
while True:
if 4*q+r-t < n*t:
yield n
nr = 10*(r-n*t)
n = ((10*(3*q+r))//t)-10*n
q *= 10
r = nr
else:
nr = (2*q+r)*l
nn = (q*(7*k)+2+(r*l))//(t*l)
q *= k
t *= l
l += 2
k += 1
n = nn
r = nr
import sys
pi_digits = calcPi()
i = 0
for d in pi_digits:
sys.stdout.write(str(d))
i += 1
if i == 40: print(""); i = 0
피드 구독하기:
글 (Atom)



