『壹』 如何用R語言提取股票行情數據
最上邊一行菜單欄倒數第二個「高級」-「關聯任務定義」-選取最右邊從上到下第二個按鈕,找到2009年決算任務安裝路徑-確定。 然後 最上邊一行菜單欄正數第二個「錄入」-「上年數據提取」即可 提取完了,注意修改與去年不同的科目代碼!
『貳』 R語言quantmod包下載的股票數據中如何確定某一數據的日期
篩選到這個行,然後輸出
『叄』 如何用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 語言 建立 股票價格的時間序列
在下想用R語言對股票價格進行時間序列分析。
問題出在第一步,如何將股票價格轉換為時間序列。
我想用的語句是 pri <- ts (data, start=(), frequency= )
但是我不知道frequency 項該如何填?
因為股票的交易日是一周五天的。 那麼這個frequency 該如何設置呢?
我知道通常frequency= 12 為月度數據,frequency= 4 為季度數據,frequency= 1 為年度數據 但日數據怎麼寫我就不知道了
初學R語言,還望各位大俠多多幫助。
『伍』 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,相關系數R絕對值越大,顏色越深(紅正,藍負)。統計學中,P值越小相關性越顯著,一般來說 一個*代表顯著相關(P值為0.01,選取不同參數可能不一樣)、兩個**代表極顯著相關(P值為0.001)、三個***代表極極顯著相關(P值為0.0001). 圖中還可以看出,相關系數R的絕對值0.67(變數P50與T之間)以上的都顯著相關,至少一個*。符合一般關於相關系數R值的顯著性統計。
『柒』 如何用R語言提取股票行情數據
你好,關於股票價格有關的開盤價格,當日最高價格,當日最低價格,收盤價格,股票交易量;和調整後的價格;
DIA.Open 當日開盤價格
DIA.High 當日最高價格
DIA.Low 當日最低價格
DIA.Close 當日收盤價格
DIA.Volume 當日股票交易量
DIA.Adjusted 當日調整後的價格
『捌』 如何在r語言中抓取股票數據並分析論文
用quantomd包
然後getsymbols函數
分析論文 要看你研究方向
如果是看影響因素 一般回歸就行
如果看股票波動和預測 可能需要時間序列
『玖』 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語言做數據分析好學嗎
非常好學。輸入幾行代碼,即可得到結果。
R不但數據分析好用,而且作圖能力極好,推薦你用。
下面是R數據分析的一些代碼,包括數據導入、方差分析、卡方測驗、線性模型及其誤差分析。希望可以幫到你:
1.1導入數據
install.packages('xslx')
library(xlsx)
Sys.setlocale("LC_ALL", "zh_cn.utf-8")
a=read.xlsx2('d:/1.xlsx',1,header=F)
head(a)顯示前六行
class(a$y)/str(a)查看列/全集數據類型
a$y=as.numeric(a$y)轉換數據類型
1.2方差分析(F test)
with(a,tapply(liqi,tan,shapiro.test))正態性檢驗
library(car)leveneTest(liqi~tan,a)方差齊性檢驗
q=aov(liqi~tan*chong,a)方差分析(正態型)
summary(q)
TukeyHSD(q)多重比較
1.3卡方測驗(Pearson Chisq)
a1=summarySE(a,measurevar='y', groupvars=c('x1','x2'))卡方檢驗(邏輯型/計數型)
aa=a1$y
aaa=matrix(a2,ncol=2)
aaa= as.table(rbind(c(56,44), c(36,64), c(48,52),c(58,42)))
dimnames(aaa)= list(group=c("不添加抗性","不添加敏感","添加抗性","添加敏感"),effect=c("存活","死亡"))
aaa=xtabs(data=a,~x+y)
chisq.test(a)誤差分析(卡方測驗,Pearson法)
install.packages("rcompanion")
library(rcompanion)
pairwiseNominalIndependence(a)多重比較
1.4線性模型及其誤差分析(Wald Chisq)
q=lm(data=a,y~x1*x2)一般線性模型(正態性)
summary(q)
q=glm(data=a,y~x1*x2,family = gaussian(link='identity'))廣義線性模型(正態性)
summary(q)
q=glm(data=a,y~x1*x2,family = binomial(link='logit'))廣義線性模型(邏輯型,二項分布)
summary(q)
q=glm(data=a,y~x1*x2,family = poisson(link='log'))廣義線性模型(計數型,泊松分布)
summary(q)
install.packages('lmerTest')一般線性混合效應模型(正態性)
library(lmerTest)
install packages(『lme4』)
library(lme4)
q=lmer(data=a,y~x1*(1|x2))
q=lmer(data=a,y~x1*(1|x2),family = gaussian(link='identity'))廣義線性混合效應模型(正態性)
q=glmer(data=a,y~x1*(1|x2),family = binomial(link='logit'))廣義線性混合效應模型(邏輯型,二項分布)
q=glmer(data=a,y~x1*(1|x2),family = poisson(link='log'))廣義線性混合效應模型(計數型,泊松分布)
summary(q)
install.packages('car')
install.packages('openxlsx')
library(car)
install.packages('nlme')
library(nlme)
Anova(q,test='Chisq')線性模型的誤差分析(似然比卡方測驗,Wald法)
lsmeans(q,pairwise~chuli,adjust = "tukey")線性模型的多重比較(tukey法)