導航:首頁 > 數據行情 > R語言美國股票數據

R語言美國股票數據

發布時間:2022-12-07 07:23:16

『壹』 R語言基本數據分析

R語言基本數據分析
本文基於R語言進行基本數據統計分析,包括基本作圖,線性擬合,邏輯回歸,bootstrap采樣和Anova方差分析的實現及應用。
不多說,直接上代碼,代碼中有注釋。
1. 基本作圖(盒圖,qq圖)
#basic plot
boxplot(x)
qqplot(x,y)
2. 線性擬合
#linear regression
n = 10
x1 = rnorm(n)#variable 1
x2 = rnorm(n)#variable 2
y = rnorm(n)*3
mod = lm(y~x1+x2)
model.matrix(mod) #erect the matrix of mod
plot(mod) #plot resial and fitted of the solution, Q-Q plot and cook distance
summary(mod) #get the statistic information of the model
hatvalues(mod) #very important, for abnormal sample detection
3. 邏輯回歸

#logistic regression
x <- c(0, 1, 2, 3, 4, 5)
y <- c(0, 9, 21, 47, 60, 63) # the number of successes
n <- 70 #the number of trails
z <- n - y #the number of failures
b <- cbind(y, z) # column bind
fitx <- glm(b~x,family = binomial) # a particular type of generalized linear model
print(fitx)

plot(x,y,xlim=c(0,5),ylim=c(0,65)) #plot the points (x,y)

beta0 <- fitx$coef[1]
beta1 <- fitx$coef[2]
fn <- function(x) n*exp(beta0+beta1*x)/(1+exp(beta0+beta1*x))
par(new=T)
curve(fn,0,5,ylim=c(0,60)) # plot the logistic regression curve
3. Bootstrap采樣

# bootstrap
# Application: 隨機采樣,獲取最大eigenvalue占所有eigenvalue和之比,並畫圖顯示distribution
dat = matrix(rnorm(100*5),100,5)
no.samples = 200 #sample 200 times
# theta = matrix(rep(0,no.samples*5),no.samples,5)
theta =rep(0,no.samples*5);
for (i in 1:no.samples)
{
j = sample(1:100,100,replace = TRUE)#get 100 samples each time
datrnd = dat[j,]; #select one row each time
lambda = princomp(datrnd)$sdev^2; #get eigenvalues
# theta[i,] = lambda;
theta[i] = lambda[1]/sum(lambda); #plot the ratio of the biggest eigenvalue
}

# hist(theta[1,]) #plot the histogram of the first(biggest) eigenvalue
hist(theta); #plot the percentage distribution of the biggest eigenvalue
sd(theta)#standard deviation of theta

#上面注釋掉的語句,可以全部去掉注釋並將其下一條語句注釋掉,完成畫最大eigenvalue分布的功能
4. ANOVA方差分析

#Application:判斷一個自變數是否有影響 (假設我們喂3種維他命給3頭豬,想看喂維他命有沒有用)
#
y = rnorm(9); #weight gain by pig(Yij, i is the treatment, j is the pig_id), 一般由用戶自行輸入
#y = matrix(c(1,10,1,2,10,2,1,9,1),9,1)
Treatment <- factor(c(1,2,3,1,2,3,1,2,3)) #each {1,2,3} is a group
mod = lm(y~Treatment) #linear regression
print(anova(mod))
#解釋:Df(degree of freedom)
#Sum Sq: deviance (within groups, and resials) 總偏差和
# Mean Sq: variance (within groups, and resials) 平均方差和
# compare the contribution given by Treatment and Resial
#F value: Mean Sq(Treatment)/Mean Sq(Resials)
#Pr(>F): p-value. 根據p-value決定是否接受Hypothesis H0:多個樣本總體均數相等(檢驗水準為0.05)
qqnorm(mod$resial) #plot the resial approximated by mod
#如果qqnorm of resial像一條直線,說明resial符合正態分布,也就是說Treatment帶來的contribution很小,也就是說Treatment無法帶來收益(多喂維他命少喂維他命沒區別)
如下面兩圖分別是
(左)用 y = matrix(c(1,10,1,2,10,2,1,9,1),9,1)和
(右)y = rnorm(9);
的結果。可見如果給定豬吃維他命2後體重特別突出的數據結果後,qq圖種resial不在是一條直線,換句話說resial不再符合正態分布,i.e., 維他命對豬的體重有影響。

『貳』 如何用R語言提取股票行情數據

最上邊一行菜單欄倒數第二個「高級」-「關聯任務定義」-選取最右邊從上到下第二個按鈕,找到2009年決算任務安裝路徑-確定。 然後 最上邊一行菜單欄正數第二個「錄入」-「上年數據提取」即可 提取完了,注意修改與去年不同的科目代碼!

『叄』 如何用R語言的quantmod包獲取一系列股票的歷史日線數據

我舉個例子供你參考:
> install.packages('quantmod') # 安裝安裝quantmod包
> require(quantmod)#引用quantmod包
> getSymbols("GOOG",src="yahoo",from="2013-01-01", to='2013-04-24') #從雅虎財經獲取google的股票數據
> chartSeries(GOOG,up.col='red',dn.col='green') #顯示K線圖

『肆』 如何用R語言提取股票行情數據

你好,關於股票價格有關的開盤價格,當日最高價格,當日最低價格,收盤價格,股票交易量;和調整後的價格;

DIA.Open 當日開盤價格

DIA.High 當日最高價格

DIA.Low 當日最低價格

DIA.Close 當日收盤價格

DIA.Volume 當日股票交易量

DIA.Adjusted 當日調整後的價格

『伍』 如何在r語言中抓取股票數據並分析論文

用quantomd包
然後getsymbols函數

分析論文 要看你研究方向
如果是看影響因素 一般回歸就行
如果看股票波動和預測 可能需要時間序列

『陸』 R語言怎麼把股票日收盤價轉換成對數收益率

知道一系列收盤價向量X,length=1000,求對數收益率的R語言代碼
acf(int[,2], lag.max = 15,type = "correlation", plot = TRUE,main='int monthly

acf(int.l[,2], lag.max = 15,type = "correlation", plot = TRUE,main='int monthly
log return')

Box.test(int[,2], lag = 5, type = "Ljung-Box")
Box.test(int[,2], lag = 10, type = "Ljung-Box")
Box.test(int.l[,2], lag = 5, type = "Ljung-Box")
Box.test(int.l[,2], lag = 10, type = "Ljung-Box")

運行結錯誤辦

> int <- read.table("d-intc7208.txt", head=T)
錯誤於file(file, "rt") : 打鏈結
外: 警告信息:
In file(file, "rt") :
打文件'd-intc7208.txt': No such file or directory

+ acf(int.l[,2], lag.max = 15,type = "correlation", plot = TRUE,main='int monthly
錯誤: 意外符號 in:
"
acf(int.l[,2], lag.max = 15,type = "correlation", plot = TRUE,main='int"
> log return')
錯誤: 意外符號 in "log return"

『柒』 如何用R 語言 建立 股票價格的時間序列

在下想用R語言對股票價格進行時間序列分析。
問題出在第一步,如何將股票價格轉換為時間序列。
我想用的語句是 pri <- ts (data, start=(), frequency= )
但是我不知道frequency 項該如何填?
因為股票的交易日是一周五天的。 那麼這個frequency 該如何設置呢?
我知道通常frequency= 12 為月度數據,frequency= 4 為季度數據,frequency= 1 為年度數據 但日數據怎麼寫我就不知道了

初學R語言,還望各位大俠多多幫助。

『捌』 如何用R語言安裝r語言quantmod包

ahoo finance 的數據,其中包括上證和深證的股票數據,還有港股數據。

上證代碼是 ss,深證代碼是 sz,港股代碼是 hk
比如茅台:6000519.ss,萬科 000002.sz,長江實業 0001.hk
在R的控制台里使用如下命令:
> library(quantmod)
> setSymbolLookup(WK=list(name='000002.sz',src='yahoo'))
> getSymbols("WK")
[1] "WK"

『玖』 R語言-數據類型及查看方式

R語言支持的數據類型

數值型(numeric)

復數型(complex)

邏輯型(logical)

字元型(character)

R語言的數據對象類型包括:

標量(Scalar)

向量(Vector) :一個向量只能有一種數據類型

因子(Factor):一個因子只能有一種數據類型

矩陣(Matrix) :一個矩陣只能有一種數據類型

數組(Array) :一個數組裡面的每個元素只能有一種數據類型,不同元素的類型可以不同

列表(List) :允許不同的數據類型

數據框(Data frame):不同的列的數據類型允許不同

查看數據特徵:

『拾』 R語言quantmod包下載的股票數據中如何確定某一數據的日期

篩選到這個行,然後輸出

閱讀全文

與R語言美國股票數據相關的資料

熱點內容
n財通股票最新價格 瀏覽:171
南方esg股票a最新 瀏覽:516
股票主力資金凈流入後會怎樣 瀏覽:20
可能退市股票哪裡能查 瀏覽:352
中國平安股票2016年報 瀏覽:962
三變科技股票東方財富實時行情 瀏覽:268
股票主力動向綠色 瀏覽:825
15年股票賬戶開戶數 瀏覽:692
納斯達克7交易指數etf股票指數 瀏覽:434
配資賬戶股票有手續費嗎 瀏覽:920
國信證券股票同花順 瀏覽:627
怎樣才能買到漲停股票6 瀏覽:277
中國一重股票今天多少錢 瀏覽:496
拓維信息股票趨勢分析 瀏覽:226
百華悅邦退市股票 瀏覽:223
泰豪科技股票歷史交易數據 瀏覽:692
股票入行最低標准 瀏覽:800
債券與股票有什麼區別說五點內容 瀏覽:294
股票用哪個軟體看走勢 瀏覽:512
新疆板塊st股票 瀏覽:803