Skip to content

Instantly share code, notes, and snippets.

@ac00std
ac00std / stock price
Last active August 15, 2017 11:04
stock price
##########stock price##########
code=8604 ##野村HDの株価を指定
year=2016 #2016年を指定
#http://k-db.com/からスクレイピングを行います。
url=paste("http://k-db.com/stocks/",code,"-T/1d/",year,"?download=csv",sep="")
stock_data=read.table(url,sep=",", skip=1)
@ac00std
ac00std / leaf2
Last active April 2, 2017 10:12
leaf2
#データの読み込み
leaf=read.csv("leaf.csv",header = F,
colClasses=c("factor",rep("numeric",15)),
col.names=c("Class","Specimen Number","Eccentricity","Aspect Ratio","Elongation","Solidity","Stochastic Convexity","Isoperimetric Factor","Maximal Indentation Depth","Lobedness","Average Intensity","Average Contrast","Smoothness","Third moment","Uniformity","Entropy"))
leaf=leaf[,-2]
y=leaf$Class
x=leaf[,-1]
train <- seq.int(1, 340, by=2)
@ac00std
ac00std / leaf.R
Last active March 6, 2017 01:38
leaf.R
#データの読み込み
#事前にデータの二行目(id)を削除しておいた
leaf=read.csv("leaf_mod.csv")
#散布図を描く
y=leaf$Class
x=leaf[,-1]
pairs(x,main="leaf",pch = 21, bg=y+2)
plot(x[1:7],pch=21,bg=y+2)
@ac00std
ac00std / claim_model_2.R
Last active March 6, 2017 01:38
claim_model_2.R
##actuarパッケージの読み込み
library(actuar)
##パンジャーの再帰式でクレーム総額分布を求める
#まずクレーム額分布(平均10の指数分布)を離散化
fx=discretize(pgamma(x,1,0.1),from=0, to=500,step=0.25,method="unbiased",lev=levgamma(x,1,0.1))
fx0=fx[1]
fs=rep(0,2001)
@ac00std
ac00std / claim_model_3.R
Created March 6, 2017 01:38
claim_model_3.R
###########高速フーリエ変換によるクレーム総額の導出##########
library(actuar)
##FFTと一様分布畳み込み
#一様分布二つの和
x=discretize(punif(x),from=0, to=2,step=2^(-8),method="unbiased",lev=levunif(x))
y=fft(x) #密度関数ベクトルをフーリエ変換
z=y^2             #畳み込むため2乗する
fu=fft(z,inverse=TRUE)/length(z)  #逆変換
fu=as.numeric(fu)         #虚数をとる
################クレームモデル###########################
##各分布の密度関数
layout(matrix(1:6,nrow=2,byrow=FALSE))
plot(dpois(0:20,5))
plot(dnbinom(0:20,5,1/2))
curve(dgamma(x,2,0.01),0,500)
curve(dnorm(x,200,50),0,500)