股票動態

股票市場是買賣雙方交易公司股票的地方,也是個人和公司投資的最受歡迎的方式之一。現在估計世界股票市場規模達到數兆。紐約證券交易所位於紐約市,是世界上最大的股票市場。 紐約證券交易所約有2,800家上市公司。在這個問題上,我們將看看其中五家公司的每月股價:IB、通用電氣(GE)、寶潔、可口可樂和波音。此問題中使用的數據來自Infochimps。

使用read.csv函數下載並讀取以下文件:IBMStock.csv,GEStock.csv,ProcterGambleStock.csv,CocaColaStock.csv和BoeingStock.cv。 (在完成此問題之前,請勿在任何電子表格軟件中打開這些文件,因為它可能會更改「日期」字段的格式。) 分別調用數據框“IBM”、“GE”、“ProcterGamble”、“CocaCola”和“Boeing”。每個數據框都有兩個變量,描述如下:



Section-1 Summary Statistics

§ 1.1 Our five datasets all have the same number of observations. How many observations are there in each data set?

IBM = read.csv("../data/IBMStock.csv")
GE = read.csv("../data/GEStock.csv")
PG = read.csv("../data/ProcterGambleStock.csv")
CK = read.csv("../data/CocaColaStock.csv")
BE = read.csv("../data/BoeingStock.csv")
IBM$Date = as.Date(IBM$Date, "%m/%d/%y")
GE$Date = as.Date(GE$Date, "%m/%d/%y")
CK$Date = as.Date(CK$Date, "%m/%d/%y")
PG$Date = as.Date(PG$Date, "%m/%d/%y")
BE$Date = as.Date(BE$Date, "%m/%d/%y")

str(IBM)
'data.frame':   480 obs. of  2 variables:
 $ Date      : Date, format: "1970-01-01" "1970-02-01" ...
 $ StockPrice: num  360 347 327 320 270 ...
nrow(IBM)
[1] 480

§ 1.2 What is the earliest year in our datasets?

min(IBM$Date)
[1] "1970-01-01"

§ 1.3 What is the latest year in our datasets?

max(IBM$Date)
[1] "2009-12-01"

§ 1.4 What is the mean stock price of IBM over this time period?

mean(IBM$StockPrice)
[1] 144.4

§ 1.5 What is the minimum stock price of General Electric (GE) over this time period?

min(GE$StockPrice)
[1] 9.294

§ 1.6 What is the maximum stock price of Coca-Cola over this time period?

max(CK$StockPrice)
[1] 146.6

§ 1.7 What is the median stock price of Boeing over this time period?

median(BE$StockPrice)
[1] 44.88

§ 1.8 What is the standard deviation of the stock price of Procter & Gamble over this time period?

sd(PG$StockPrice)
[1] 18.19




Section-2 Visualizing Stock Dynamics

§ 2.1 Around what year did Coca-Cola has its highest stock price in this time period? Around what year did Coca-Cola has its lowest stock price in this time period?

plot(CK$Date, CK$StockPrice, type='l')  # 1973 1980
abline(v=CK$Date[which.max(CK$StockPrice)], col='green')
abline(v=CK$Date[which.min(CK$StockPrice)], col='red')

§ 2.2 In March of 2000, the technology bubble burst, and a stock market crash occurred. According to this plot, which company’s stock dropped more?

plot(CK$Date, CK$StockPrice, type='l', col='blue', lwd=2)
lines(PG$Date, PG$StockPrice, col="green", lwd=2)
abline(v = as.Date("2000-03-01"), lty=3, col='orange')
abline(v = as.Date("1983-07-01"), lty=3, col='orange')
legend("topright",legend=c("Coke","P&G"),col=c('blue','green'),lwd=2)

§ 2.3 (a) Around 1983, the stock for one of these companies (Coca-Cola or Procter and Gamble) was going up, while the other was going down. Which one was going up?

# Coca-Cola
  1. In the time period shown in the plot, which stock generally has lower values?
# Coca-Cola




Section-3 Visualizing Stock Dynamics 1995-2005

§ 3.1 Which stock fell the most right after the technology bubble burst in March 2000?

plot(CK$Date[301:432], CK$StockPrice[301:432], 
     type="l", col="red", ylim=c(0,210))
lines(PG$Date[301:432],  PG$StockPrice[301:432],  col="blue")
lines(IBM$Date[301:432], IBM$StockPrice[301:432], col="green")
lines(GE$Date[301:432],  GE$StockPrice[301:432],  col="purple")
lines(BE$Date[301:432],  BE$StockPrice[301:432],  col="orange")
abline(v = as.Date("2000-03-01"), lty=3, col='gray')
abline(v = as.Date("1997-09-01"), lty=3, col='gray')
abline(v = as.Date("1997-11-01"), lty=3, col='gray')

§ 3.2 Which stock reaches the highest value in the time period 1995-2005?

# IBM

§ 3.3 In October of 1997, there was a global stock market crash that was caused by an economic crisis in Asia. Comparing September 1997 to November 1997, which companies saw a decreasing trend in their stock price? (Select all that apply.)

# P&G and Boeing

§ 3.4 In the last two years of this time period (2004 and 2005) which stock seems to be performing the best, in terms of increasing stock price?

# Boeing