#Practical Assignment #4
# This assignment is worth 150 points.
# Useful hints: Utilize book examples and make sure to download and library
# appropriate packages (FRAPO, timeSeries, QRM, fGarch,copula)
# Under each of the items provide the relevant R code and answer the questions.
# 1) Set your working directory to RStudio folder
# that you have created inside the ANLY 515 forlder”
# 2) Download the followin data set, and lable it fcur
# This data sets reperesnets daily exchange rates between US dollar
# and 21 foreign currencies. Moreove, it has an Nominal Broad Dollar Index
# that captures the performance of USD against a equal weight basket
# of all the currencies. The exchange rates are expressed as price 1 USD
# in the foreign currency. Make sure to set first column in the date format
# and the remaining columns are in the numerical format.
# Hint: May have to set the format of each column manually.
# 3) Upload all of the following packages:
# FRAPO, timeSeries, QRM, fGarch, copula
# 4) Create a data set “fcurcc” that is a sub set of
# “fcur” and consists of all complete cases.
# 5) By using the ‘Time Period’ column of the “fcurcc” create
# a “date” variable and save it as.character.
# 6) Create a new data set “fcurccd”, that excludes
# the first column of the “fcurcc” data set (‘Time Period’).
# Should have 22 columns
# 7) By using sapply function modify all exchnge rates including the Broad Index
# to represent the prices of 1 foreign currency in terms of USD.
# Save these exchange rates as “fcprice”
# Hint: The price of 1 foreign currency in terms of USD, is a reciprocal
# of the price 1 USD in terms of foreign currency.
# 8) By using “fcprice” and “date” variables create time series object,
# and label it “fcpricets”.
# 9) By using first 3250 observations of the “fcpricets” create two objects
# called: “RM” and “RA”. The “RM” should represent, daily returns
# of “Nominal Broad Dollar Index” while the “RA” should represent
# daily returns on each foreign currency.If the percentage change
# is positive it means that the foreign currency is getting stronger,
# and more dollars are need to buy 1 unit of foreign currency.
# Hint: Use returnseries function and specify trim=TRUE
# to get rid of the missing values.
# 10) By using apply function compute the value of Beta for each currency.
# The beta (?? or beta coefficient) of an investment indicates whether
# the investment is more or less volatile than the market as a whole.
# Beta can be found by dividing cov(Foreign, Index)/Var(Index)
# Which currency has the lowest Beta?
# 11) By using apply function compute the value of Tau for each currency.
# Tau is a Kendall rank correlation coefficient, between
# two measured quantities(one of a foreign currency and one of Broad Index).
# 12) By using Kendal rank correlation coeffients “Tau”, estimate the
# value of Clayton (Archimedean family) copula parameter “Theta”
# 13) Use Theta to extact lower tail dependence coefficients “Lambda”.
# Lambda represents the interdependence between each foreign currency
# and Broad Index at the lower tail of the distributions
# 14) Select foreign currencies which Betas are below the median value of Beta,
# and save the results as “IdxBeta”.
# Which currencies would you select?
# 15) Create a variable “WBeta” which represents inverse log-weighted
# and scaled portfolio weights of each selected currency.
# 16) Select foreign currencies with Lambdas below
# the median value of Lambda, and save the results as “IdxTD”
# Which currencies would you select?
# 17) Create a variable “WTD” which represents inverse log-weighted
# and scaled portfolio weights of each selected currency based on
# low tale dependency selction criteria.
# 18) Create a variable “Intersection” that represnts in percentage terms
# how similar are the portfolios’ currency selections based
# on Low Tau vs Low Lambda criteria.
# Out-of-Sample Performance
# 19) By using last 44 observations of the “fcpricets” create two objects
# called: “RMo” and “RAo”. The “RMo” should represent, daily returns
# of “Nominal Broad Dollar Index”, while the “RAo” should represent
# the daily returns on each foreign currency.
# Hint: use returnseries function, express returns as decimals
# and DO NOT trim.
# 20) Set the value of the first observation of the “RMo” object to 100.
# 21) Generate a new variable called “RMEquity” that calculates cumulative
# product of the RMo object. By doing so you will find cumulative perfomance
# of the Broad Index.
# 22) Create a new variable called “LBEquite”, that is subset of the “RAo” object
# and includes only columns that represent currencies that were selected
# to be a part of the portfolio under the low beta selection criteria.
# 23) Assign the values of the first row of the “LBEquite” object to be equal to
# “WBeta” verctor.
# 24) Apply rowSums(apply()) function to calculate weighted cumulative
# product of the LBEquity object. By doing so you will find cumulative
# perfomance of the low beta portfolio over the out-of-sample period.
# Save the results as “LBEquity”.
# 25) Create a new variable called “TDEquite”, that is subset of the “RAo”
# object and includes only columns that represent currencies that were
# selected to be a part of the portfolio under the low tail dependence
# selection criteria.
# 26) Assign the values of the first row of the “TDEquity” object to be equal to
# “WTD” verctor.
# 27) Apply rowSums(apply()) function to calculate weighted cumulative product
# of the TDEquity object. By doing so you will find cumulative perfomance
# of the low tail dependency portfolio over the out-of-sample period.
# Save the results as “TDEquity”.
# 28) Collect results of the out-of-sample performance by binding together
# RMEquity, LBEquity, TDEquity, and compute summary statistics for each
# element. Which investment strategy yeilds the best average equity?
# 29) Create a time series plots of equity curves for the “Out-of-Sample Periods”.
# 30) Create a Bar plot of relative performance of the Broad Currency Index,
# “Low Beta Portfolio”, and “Low Tail Dependency Portfolio”
# Which portfolio would you choose?