2011-08-14
幾何ブラウン運動と見せかけの回帰
R | |
いつものようにメモがてら。
幾何ブラウン運動をモンテカルロシミュレーションしたかったら以下のように書く。
#Term(year) T <- 5 #Number of path N <- 10000 #Unit of time dt <- T / N #Start price of stock or something obeying to geometric brownian motion s0 <- 100 #montecarlo simulation(Average return 10%(per annual), Volatility 20%(per annual)) x <- s0 * exp(cumsum(0.1 * dt + 0.2 * rnorm(N) * sqrt(dt))) y <- s0 * exp(cumsum(0.1 * dt + 0.2 * rnorm(N) * sqrt(dt))) #plot matplot(cbind(x,y))
平均リターンとボラティリティ水準をチェック。
リターンは設定値(10%)との乖離がすごい一方Volatilityは比較的安定。
> #check average return and volatility > (y[length(y)] / y[1]) ^ (1 / T) - 1 [1] 0.1562153 > (x[length(x)] / x[1]) ^ (1 / T) - 1 [1] 0.3392794 > sd(y[-1]/y[-length(y)]-1) * sqrt(1 / dt) [1] 0.1998597 > sd(x[-1]/x[-length(x)]-1) * sqrt(1 / dt) [1] 0.2001122
このxとy(≒株価)をそのまま回帰分析してるような例をネット、場合によっては書物でも見かけるんだけど、
それをやると見せかけの回帰が起こるのでやってはいけない。
上で創ったxとyは全く別物の乱数から生成しているが回帰してみると・・・
> summary(lm(y~x)) Call: lm(formula = y ~ x) Residuals: Min 1Q Median 3Q Max -32.631 -10.776 -1.824 9.301 67.620 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.092e+02 4.272e-01 255.67 <2e-16 *** x 1.011e-01 1.595e-03 63.41 <2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 17.17 on 9998 degrees of freedom Multiple R-squared: 0.2868, Adjusted R-squared: 0.2867 F-statistic: 4020 on 1 and 9998 DF, p-value: < 2.2e-16
コメントを書く
トラックバック - http://d.hatena.ne.jp/teramonagi/20110814/1313282962
リンク元
- 7 http://www.google.co.jp/url?sa=t&source=web&cd=1&ved=0CBkQFjAA&url=http://d.hatena.ne.jp/teramonagi/20100612/1276293001&rct=j&q=ポートフォリオ 組み合わ??%
- 6 http://twitter.com/
- 5 http://www.google.co.jp/ig
- 3 http://d.hatena.ne.jp/dichika/20110209/1297264408
- 3 http://entre2formosas.blogspot.com/2011/03/rstudio9501.html
- 3 http://www.google.co.jp/url?sa=t&source=web&cd=2&ved=0CCAQFjAB&url=http://d.hatena.ne.jp/teramonagi/20101205/1291552649&rct=j&q=2010 vc dll呼び出し&ei=Un9HTuyfIqnImAWzyJ30Bg&usg=AFQjCNEZyRda1modAf7vALKf5RpJ734J_
- 2 http://ezsch.ezweb.ne.jp/search/?query=等質&start-index=6&adpage=3&ct=1301&sr=0104&t=20110816015930&filter=1
- 2 http://search.yahoo.co.jp/search?p=C++ 2010+dll+作成&aq=-1&oq=&ei=UTF-8&fr=sb-kingbrw1&x=wrt
- 2 http://www.bing.com/search?q=VBA 効率的フロンティア&mkt=ja-jp&FORM=DLRTBR&DI=2883&CE=14.0&CM=SearchWeb
- 2 http://www.google.co.jp/search?hl=ja&source=hp&biw=886&bih=766&q=VBA+クレイトンコピュラ&oq=VBA+クレイトンコピュラ&aq=f&aqi=&aql=&