當前位置:首頁 » 分析預測 » r語言股票分析數據
擴展閱讀
股票總是買不完 2025-02-12 02:39:10

r語言股票分析數據

發布時間: 2022-07-31 06:49:51

⑴ 如何用R語言提取股票行情數據

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

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

篩選到這個行,然後輸出

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

用quantomd包
然後getsymbols函數

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

⑷ 如何用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語言的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語言的dea分析的分析結果怎麼看

方法/步驟

1.錄入原始數據。如圖所示,原始數據一般採用excel表格來錄入,第一列為決策單元序列,比如公司、行業等;後續各列依次是產出和投入變數,切忌產出變數一定要在投入變數前面。

2.分析效率情況。如圖所示,將原始數據的格式進行統一調整之後,導入deap分析軟體中,設定好相應的程序和命令後,即可運行出數據分析的結果。其中firm是公司序號,crste是技術效率,vrste是純技術效率,scale是規模效率,最後一列是規模報酬的狀態,irs是規模報酬遞增,drs是規模報酬遞減,-是規模報酬不變。

3
2.分析冗餘情況。如圖所示,DEA數據分析結果會分別給出投入、產出的冗餘量,其中產出冗餘數值是表示產出少了多少,而投入冗餘則是表示投入多了多少。

4
4.分析參考單元。如圖所示,peers表示的是可以作為效率改進參照的公司序號。由結果可見,5和13的決策單元的效率值為一,這樣其他公司以此作為參照,對投入產出量進行調整,便可實現DEA有效。

⑼ 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語言是數據分析領域比較常用的工具,它具有什麼特點

reshape2 橫向、縱向做數據變換,例如把縱向堆疊在資料庫中的證券行情數據轉換成一個按照不同證券代碼橫向排列,按照時間縱向排列收盤價的數據表
stringr 方便地用正則表達式做批量字元串操作,可做檢測、匹配、替換、計數等等
lubridate 方便地做日期/時間操作,各種標准化時間和時區的處理!