In this set of exercises we shall explore possibilities for fundamental and technical analysis of stocks offered by the `quantmod`

package. If you don’t have the package already installed, install it using the following code:

install.packages("quantmod")

and load it into the session using the following code:

library("quantmod")

before proceeding.

Answers to the exercises are available here.

If you have a different solution, feel free to post it.

**Exercise 1**

Load FB (Facebook) market data from Yahoo and assign it to an xts object `fb.p`

.

**Exercise 2**

Display monthly closing prices of Facebook in 2015.

**Exercise 3**

Plot weekly returns of FB in 2016.

**Exercise 4**

Plot a candlestick chart of FB in 2016.

**Exercise 5**

Plot a line chart of FB in 2016., and add boilinger bands and a Relative Strength index to the chart.

**Exercise 6**

Get yesterday’s EUR/USD rate.

**Exercise 7**

Get financial data for FB and display it.

**Exercise 8**

Calculate the current ratio for FB for years 2013, 2014 and 2015. *(Tip: You can calculate the current ratio when you divide current assets with current liabilities from the balance sheet.)*

**Exercise 9**

Based on the last closing price and income statement for 12 months ending on December 31th 2015, Calculate the PE ratio for FB. *(Tip: PE stands for Price/Earnings ratio. You calculate it as stock price divided by diluted normalized EPS read from income statement.)*

**Exercise 10**

write a function getROA(symbol, year) which will calculate return on asset for given stock symbol and year. What is the ROI for FB in 2014. *(Tip: ROA stands for Return on asset. You calculate it as net income divided by total asset.)*

**What's next:**

- Explore all our (>1000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below

Dr Pankaj Kumar Agarwal says

Thanks.

Dr Pankaj Kumar Agarwal says

Exercises on other technical analysis indicators like MACD etc will be appreciated.