顯示具有 R 標籤的文章。 顯示所有文章
顯示具有 R 標籤的文章。 顯示所有文章

2016年11月5日 星期六

R語言:t檢定檢驗樣本平均數

RStudio執行結果:
> #檢驗樣本平均數
> x <- c="" span="">> x
 [1]  1  2  3  4  5  6  7  8  9 10
> t.test(x)

 One Sample t-test

data:  x
t = 5.7446, df = 9, p-value = 0.0002782
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
 3.334149 7.665851
sample estimates:
mean of x 
      5.5 


>


T檢定:t.test => 檢定平均數是否相等
F檢定:var.test
=> 檢定平均數是否相等

ref:
https://sites.google.com/site/rlearningsite/inference/ttest 

http://ccckmit.wikidot.com/st:test1
http://ccckmit.github.io/stbook/htm/test1.html

2016年9月25日 星期日

利用R語言分析期交所歷史年度行情近月合約資料

在RStudio的執行結果如下:
第三個星期三已經結算,所以結算日之後會沒有資料,我沒有特別再處理這部分


2016年8月28日 星期日

從OANDA取得外匯匯率

> setSymbolLookup(EURUSD=list(name="EUR/USD",src="oanda"))
> getSymbols("EURUSD")
>
> # 查看前30筆
> head(EURUSD,30)
            EURUSD
2015-04-17 1.07838
2015-04-18 1.08067
2015-04-19 1.08067
2015-04-20 1.07684
2015-04-21 1.07210
2015-04-22 1.07404
2015-04-23 1.07481
2015-04-24 1.08391
2015-04-25 1.08749
2015-04-26 1.08749
2015-04-27 1.08654
2015-04-28 1.09168
2015-04-29 1.10292
2015-04-30 1.11577
2015-05-01 1.12224
2015-05-02 1.11975
2015-05-03 1.11975
2015-05-04 1.11681
2015-05-05 1.11470
2015-05-06 1.12569
2015-05-07 1.13194
2015-05-08 1.12262
2015-05-09 1.12035
2015-05-10 1.12035
2015-05-11 1.11623
2015-05-12 1.12042
2015-05-13 1.12725
2015-05-14 1.13834
2015-05-15 1.14010
2015-05-16 1.14480
>
> # 查看後30筆
> tail(EURUSD,30)
            EURUSD
2016-07-29 1.11173
2016-07-30 1.11746
2016-07-31 1.11746
2016-08-01 1.11695
2016-08-02 1.11945
2016-08-03 1.11940
2016-08-04 1.11392
2016-08-05 1.11183
2016-08-06 1.10873
2016-08-07 1.10873
2016-08-08 1.10870
2016-08-09 1.10912
2016-08-10 1.11572
2016-08-11 1.11624
2016-08-12 1.11544
2016-08-13 1.11621
2016-08-14 1.11621
2016-08-15 1.11725
2016-08-16 1.12393
2016-08-17 1.12734
2016-08-18 1.13188
2016-08-19 1.13298
2016-08-20 1.13253
2016-08-21 1.13253
2016-08-22 1.13020
2016-08-23 1.13265
2016-08-24 1.12822
2016-08-25 1.12777
2016-08-26 1.12724
2016-08-27 1.11966
>

2016年4月16日 星期六

R語言畫台積電的線圖




使用chartSeries函數繪圖結果:

R語言getSymbols台股資料

src要使用yahoo,不要用google
比如getSymbols(“2330.TW”,src=“yahoo”)
另外台股代號是數字,還需要TSMC←get(“2330.TW”)
再用barChart(TSMC)之類的Function繪圖

備註:
需要先安裝quantmod套件
> install.packages("quantmod")

引用quantmod套件
require("quantmod")或是library(quantmod)

參考資料:
第一次使用R語言做回測:六分鐘,就上手!
http://www.bituzi.com/2014/12/Rbacktest6mins.html

R安裝quantmod

> install.packages("quantmod")

引用quantmod套件
require("quantmod")或是library(quantmod)

ubuntu安裝R

apt-get install r-base