im Rahmen eines Studienprojekts haben wir folgende AUfgabe (im Anhang) in R zu lösen.
Hier der bisher generierte Code:
Code: Alles auswählen
rm(list=ls())
#Topic 6 - Time value of money, ivnestment project valuation (DCF, NPv, IRR)
# Aufgabe a)
# initial invest is 100, 5 years, semiannually 6%
initialAmount <- 100
FVsemi <- 0
z <- 0.03
t <- 10
for (i in 1:t) {
FVsemi[i] <- initialAmount*((1+z)^i)
}
FVsemi[t]
#-----------------------------------------
# initial invest is 100, 5 years, quarterly 6%
initialAmount <- 100
FVquarterly <- 0
z <- 0.015
t <- 20
for (i in 1:t) {
FVquarterly[i] <- initialAmount*((1+z)^i)
}
FVquarterly[t]
#-----------------------------------------
# initial invest is 100, 5 years, monthly 6%
initialAmount <- 100
FVmthly <- 0
z <- 0.005
t <- 60
for (i in 1:t) {
FVmthly[i] <- initialAmount*((1+z)^i)
}
FVmthly[t]
#------------------------------------------
# initial invest is 100, 5 years, continuously 6%
initialAmount <- 100
FVcont <- 0
z <- 0.06
t <- 5
for (i in 1:t) {
FVcont[i] <- initialAmount*(exp(z*i))
}
FVcont[t]
#---------------------------------------------------------------------------------------------------
#b)
#future value discrete payments
II <- 100 #Initial investment
t <- 1 # time horizon
rf <- 0.03 #risk free rate
pm <- 5 # periodic payment
FV30disc <-0 # future value
CFdisc <- 0 # periodic cashflow
for (i in 29:t){
CFdisc[i+1] <- pm*(1+0.03)^i
}
CFdisc[1]<-5
FV30disc <- sum(CFdisc[1:30])
#NPV when discount rate = 0.03
NPVdisc <- (FV30disc / ((1+rf)^30)) - II
NPVdisc
#zweite (einfachere) Variante:
FV30disc2 <- function(x){
5+(5*(1+x)*((((1+x)^29)-1)/x)) #geometrische Reihe für 29 Perioden, plus Schluss-CF in Höhe von 5
}
FV30disc2(0.03)
(FV30disc2(0.03)/(1+rf)^30)-II
#future value continuously compounded
II <- 100
t <- 1
rf <- 0.03
pm <- 5
FVcont <-0
CFcont <- 0
for (i in t:29){
CFcont[i+1] <- pm*(exp(rf*i))
}
CFcont
CFcont[1] <- 5
FVcont <- sum(CFcont[1:30]) #Future Value for continuously compounded
#calculating NPV
NPVcont <- FVcont/exp(0.03*30)-II
NPVcont
CFcontMatrix <- matrix(CFcont, nrow = 30, ncol = 1)
colnames(CFcontMatrix) <- c("Cash Flow")
#---------------------------------------------------------------------------------------------------
library(FinancialMath)
# c)
#Zerobond berechnung
rm(list=ls())
IRR <- 0
zerobond <- function(x, y, z){
IRR <- (log(x/y))/z
print(IRR)
}
Zerobond.IRR <- zerobond(100,80,10)
#second option via uniroot function
IRRuniroot <- function (x){
(80*(1+x)^10)-100
}
uniroot(IRRuniroot, lower = 0.02, upper = 0.03)
#third option via IRR-function from package "FinancialMath")
IRR(-80, 100, 10)
#-------------------------------------
#IRRs for b)
# there are none because the NPVs are both negative!
#---------------------------------------------------------------------------------------------------
#d)
library(FinCal)
#NPV Project 1 & Project 2
NPV.Project1 <- NPV(-1000, c(1250, 10, 10, 20, 20), c(1:5), 0.06 )
NPV.Project2 <- NPV(-1000, c(-10, 0, 10, 20, 2000), c(1:5), 0.06 )
#Solution: NPV2 with 509 > NPV1 with 227 -> Pick Project 2
#IRR Project 1 & Project 2
IRR.Project1 <- IRR(-1000, c(1250, 10, 10, 20, 20), c(1:5))
IRR.Project2 <- IRR(-1000, c(-10, 0, 10, 20, 2000), c(1:5))
#Solution: IRR1 with 28% > IRR2 with 15% -> Pick Project 1
#PB Project 1 & Project 2
#PB Project 1
cf0 <- -1000
cf <- c(1250, 10, 10, 20, 20)
t <- 5
temp <- 0
#Calculating the Payback period
for (i in 1:5){
temp[i]=sum(cf[1:i])
}
for (i in 1:5){
if ((temp[i]+cf0) > 0){
payback.Project1 <- i
break
}
}
#PB Project 2
cf0 <- -1000
cf <- c(-10, 0, 10, 20, 2000)
t <- 5
temp <- 0
#Calculating the Payback period
for (i in 1:5){
temp[i]=sum(cf[1:i])
}
for (i in 1:5){
if ((temp[i]+cf0) > 0){
payback.Project2 <- i
break
}
}
#Solution: Period for PB with Project 1 is way smaller (1 year) than with Project 2 (5 years)
VG