Lab 1: Basic Descriptive Analytics with R or Python
Getting Data
•Open Lab1 and unzip. You should have the following files:
o IBMStock.csv, GEStock.csv,ProcterGambleStock.csv, CocaColaStock.csv, BoeingStock.csv.
•Note: don’t open the CSVs in Excel before importing to R as it can mess up the Date field
Importing Data into R
•Import each CSV into R as a dataframe using the read.csv() function
•When you import the data, give each dataframe the following names:
o"IBM", "GE", "ProcterGamble", "CocaCola", and "Boeing
•Each data frame has two columns:
date: the date of the stock price, always given as the first of the month.
stock price: the average stock price of the company in the given month.
Clean Date Field
•You’ll notice the dates will not be in aformat R can understand rightafter you import. Check this out using the str(). What is the data type of the Data variable?
ANSWER:
We can use the as.Date() to convert the dates. Here’s an example of applying for the GE dataframe:
GE$Date = as.Date(GE$Date, "%m/%d/%y")
Using the sample code above, convert the datatype of the date field for all 4 files.
Warm-up/Basic statistics Questions:
1.How many rows of data are in each dataset?
2.What is the earliest/latest year in our datasets?
3.For the period above what is the average stock price of Coca Cola?
4.What is the maximum price of IBM during this period?
5.What is the standard deviation of P&G stock price over this period?
6.What is the median price of Boeing in the last 5 years for which we have data?
Basic Plotting Questions
Part 1: Plot the StockPrice of Coca-Cola on the Y-axis across Date on the x-axis using the basic plot() function. What do you see when you use the default plot function what do you see? Scatter-plot, eh? If you want a line graph instead, add the argument type=”l” to your plot function.
Answer the following questions:
1.Identify the year during which Coca-Cola had the highest/lowest stock price?
2.What calendar year did it look to have the biggest (Year-over-Year) percentage increase?
Part 2: Next we want to add P&G stock price onto the same graph. If you keep your plot window open and type in: lines(ProcterGamble$Date, ProcterGamble$StockPrice) you should see your plot update. Go back to the plot function and add argument col=”red” and col=”blue” argument for CocaCola and P&G respectively.
Answer the following questions
1.In March of 2000 the stock market plummeted as the tech bubble burst. Using the plot above, which company’s stock dropped more (relatively – i.e. percentage-wise)?
2.In the year 1983 which company stock was going up? Which was going down?
3.Across the entire time period shown in your plot which stock had a generally lower price?
Data Visualization from 1995-2005:
Instead of looking at the plot across the entire date range, we want to see what’s happening between 1995-2005. Remember, you can use the matrix notation [rows, columns] to subset data.
Keeping that in mind what row numbers represent the Dates from 1995-2005?
The first stock price of the year 1995 sits in row position: <Your Answer Start>
The last stock price of the year 2005 sits in row position: <Your Answer End>
Next, run the command below using the date range you found above. Note: change the values <Your Answer Start> and <Your Answer End> to your answers above.
plot(CocaCola$Date[<Your Answer Start> : <Your Answer End>], CocaCola$StockPrice[<Your Answer Start> : <Your Answer End>], type="l", col="red", ylim=c(0,210))
ylim=c(0,210), makes the y-axis range from 0 to 210. type="l" specifies to make it a line graph
•and col=”red” tell is to make the line colour red
Answer the following questions:
1.Which stock price fell the most right after the tech bubble of March 2000?
2.What stock had the highest maximum price between 1995-2005?
3.Afew years before the tech bubble of 1997, there was another stock market crash trigged by economic crisis in Asia in October of 1997. If you compare stock prices from September 1997 to November 1997, which companies saw a decrease in price? Which company experienced the biggest decrease?
4.Which stock seemed to provide the best return (i.e. increase in price) between 2004-2005?
5.Between 1995-2005, which company had the biggest delta between the maximum and minimum stock price?
6.Which two companies’ stock price seem to be the most correlated (i.e. move up/down together)?
CS 340 Milestone One Guidelines and Rubric Overview: For this assignment, you will implement the fundamental operations of create, read, update,
Retail Transaction Programming Project Project Requirements: Develop a program to emulate a purchase transaction at a retail store. This
7COM1028 Secure Systems Programming Referral Coursework: Secure
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
CS 340 Final Project Guidelines and Rubric Overview The final project will encompass developing a web service using a software stack and impleme