Load the necessary library called ‘tidyverse’. Do not be alarmed with a conflict detection notification, only if you see the word ‘error’ should you attend to the message.

The goal is to test your software installation, to demonstrate competency in being able to write text intermixed with code inside an Rmd file, and competency in the basics of the library ggplot.

I encourage the use of ‘ChatGPT’ where you feel it can help you. Imagine it as your useful assistant.

R and RStudio installation

You should have already successfully installed R and R studio in your computer. If in doubt please follow the pdf which I have created for you called ‘Introduction to R and RStudio’.

Install tidyverse package

The basic installation of R is known as base R. (If you haven’t already done so) we need to install a package called tidyverse. Go to the packages panel in the bottom right of RStudio, click on “Install,” type tidyverse, and press enter. You’ll see output in the RStudio console as all the package contents are installed. Do not be alarmed by red text, only if you see the word ‘error’.

Practice using Markdown

Written assignments will be submitted using Markdown. Markdown is a lightweight text formatting language that easily converts between file formats. It is integrated directly into R Markdown, which combines R code, output, and written text into a single document (.Rmd).

There is a very nice Markdwown tutorial that I suggest you go through before working on your assignment.

Pandoc

Pandocis a program that converts Markdown files into basically anything else. It was created by John MacFarlane, a philosophy professor at the University of California, Berkeley and is widely used as a writing tool and as a basis for publishing workflow. Kieran Healy’s Plain Text Social Science workflow describes how to use Markdown and then convert your Markdown document to HTML, PDF, word, etc.

You should create a file whose name will be your Name_Surname.Rmd.

Short Bio Written in Markdown

You should write within this Rmd file a brief biography of yourself using markdown syntax. I know you have already achieved a lot, but a couple of paragraphs is more than enough.

You are recommended including at least 4 of the following elements:

  • Headers
  • Emphasis (italics or bold)
  • Bullet points
  • Links
  • Embedding images

Please write your short biography after this blockquote.

Brief Introduction and Hello

Hello Mrs. Abramova,

It is a pleasure to introduce myself and to embark on this journey of improving my currently limited R skills with your guidance.

My name is Lucia Schmid. I am 23 years old, born and raised in Stuttgart, Germany. I spent the last four years of high school at a British boarding school just outside London. Some people say it looks a bit like Hogwards but take a look for youself: Hogwards or Boarding school?

After completing high school, I pursued my undergraduate studies in Milan, Italy, where I majored in International Economics and Management.

Throughout my academic journey, I’ve gained valuable experience through internships in the following industries:

  • Asset management
  • Consulting
  • Investment banking
  • Real estate

While I’m still exploring the precise direction I want to take in my career, I am committed to starting my professional journey in finance here in London.

In my free time, I enjoy long-distance running, visiting museums, and spending quality time with my friends and family. Additionally, I have a passion for cooking and particularly love trying out recipes by Ottolenghi such as: Stuffed aubergine in curry and coconut dal

I look forward to seeing you in class soon.

Best regards, Lucia

ggplot2 Library Practice

You have a dataset called BOND_TY10_US.csv that contains the Market Yield on U.S. Treasury Securities at 10-Year Constant Maturity Quoted on an Investment Basis from 1962 to 2024. To get a glimpse of the dataframe, namely to see the variable names, variable types, etc., we use the glimpse function. We also want to have a look at the first 20 rows of data.

bond_10yr <- read_csv("Data/BOND_TY10_US.csv")
glimpse(bond_10yr, 20)
## Rows: 15,598
## Columns: 2
## $ Date         <date> …
## $ BOND_TY10_US <dbl> …

I have created the data_2001_2010 data and data_2011_2020 with the code below.

data_2001_2010 <- bond_10yr %>% 
            filter(Date >= "2001-01-01" & Date < "2011-01-01") 
data_2011_2020 <- bond_10yr %>% 
            filter(Date >= "2011-01-01"& Date < "2021-01-01")

Produce Plots

Your task is to produce two plots (ensure to uncomment the ggplot lines): plot 1 how did the price evolve over the period of 2001-2010 (colour in blue) plot 2 how did the price evolve over the period of 2001-2010 (colour in red)

## 2001_2010
ggplot(data= data_2001_2010, aes(x = Date, y = BOND_TY10_US)) +
    geom_line(color = "blue") +
    theme_minimal()

## 2011_2020
ggplot(data=data_2011_2020, aes(x = Date, y = BOND_TY10_US)) +
    geom_line(color = "red") +
    theme_minimal()

Next we need to add a title and axis labels. Create a new plot, or extend plot1, using the labs() function to add an informative title and x-axis & y-axis labels to the plots.

## 2001_2010
ggplot(data= data_2001_2010, aes(x = Date, y = BOND_TY10_US)) +
    geom_line(color = "blue") +
   labs( title = "US Bond Prices from 2001 to 2010",
    x = "Dates",
    y = "US Bond Prices") +
  theme_minimal()

## 2011_2020
ggplot(data=data_2011_2020, aes(x = Date, y = BOND_TY10_US)) +
    geom_line(color = "red") +
labs( title = "US Bond Prices from 2011 to 2020",
    x = "Dates",
    y = "US Bond Prices") +
    theme_minimal()

Next, attempt to find the mean and standard deviation of the data for the two periods. Comment on your findings.

## Calculate the mean of BOND_TY10_US for data_2001_2010
mean_2001_2010 <- mean(data_2001_2010$BOND_TY10_US, na.rm = TRUE)
std_2001_2010 <- sd(data_2001_2010$BOND_TY10_US, na.rm = TRUE)

## Calculate the mean of BOND_TY10_US for data_2011_2020
mean_2011_2020 <- mean(data_2011_2020$BOND_TY10_US, na.rm = TRUE)
std_2011_2020 <- sd(data_2011_2020$BOND_TY10_US, na.rm = TRUE)

## Print the results
print(paste("Mean of BOND_TY10_US (2001-2010):", round(mean_2001_2010, 2)))
## [1] "Mean of BOND_TY10_US (2001-2010): 4.18"
print(paste("Mean of BOND_TY10_US (2011-2020):", round(mean_2011_2020, 2)))
## [1] "Mean of BOND_TY10_US (2011-2020): 2.17"
print(paste("Std of BOND_TY10_US (2001-2010):", round(std_2001_2010, 2)))
## [1] "Std of BOND_TY10_US (2001-2010): 0.7"
print(paste("Std of BOND_TY10_US (2011-2020):", round(std_2011_2020, 2)))
## [1] "Std of BOND_TY10_US (2011-2020): 0.64"

Submit the preliminary work

Knit the completed R Markdown file as an HTML or pdf document (use the “Knit” button at the top of the script editor window) and upload it to Canvas. Note, this work is not graded but highly benificial for you to complete before we start.

Details

If you want to, please answer the following

  • Who did you collaborate with: N/A
  • How much time did you spend on each of the 3 Datacamp chapters and on this preliminary assignment completion: 13h
  • What, if anything, gave you the most trouble: Setting up this assignment on R (as on Datacamp the system was always fully set up) and saving as a pdf