2017-04-09 30 views
1

中获得的价格提取特定股票我正在运行quantmod,我想读取某个日期的股票及其价格列表。那么我想要保持那些符合特定门槛的股票。根据Quant Mod从R

我的代码开始:

library(quantmod) 
s = c("AAPL","FB","GOOG", "CRM") 
e = new.env() #environment in which to store data 
getSymbols(s, src="yahoo", env=e) 
prices = do.call(merge, eapply(e, Cl)[s]) 

today = prices["2017-04-07",] 
today 

The output is: 

    AAPL.Close FB.Close GOOG.Close CRM.Close 
2017-04-07  143.34 140.78  824.67  84.38 

我想只有那些以跟上价格> 140所以它应该阅读:

AAPL.Close GOOG.Close 
2017-04-07  143.34  824.67 
+1

试试这个:'threshold = 140,filteredPx = today [,today> threshold]' – OdeToMyFiddle

回答

0

你已经拥有价格为某一特定日期的today。因此,您只需要将子集today设置为接近价格大于140的列。您可以通过将列与子逻辑向量进行子集来完成此操作。

R> today[, today > 140] 
      AAPL.Close FB.Close GOOG.Close 
2017-04-07  143.34 140.78  824.67