-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEconomic Model.Rmd
More file actions
107 lines (92 loc) · 2.83 KB
/
Copy pathEconomic Model.Rmd
File metadata and controls
107 lines (92 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
---
title: "Economic Model"
author: "AmrMoslim"
date: "`r Sys.Date()`"
output:
prettydoc::html_pretty:
theme: tactile
highlight: github
toc: yes
keep_md: yes
fig_caption: yes
---
```{r setup, include=FALSE}
```
## Creating Economic Model for Oil and Gas Projects _**EcoMan**_
### Writing The Economic Functions
```{r Functions }
### Writing the Economic Functions to calculate DCF, NPV, IRR and PBP, DPBP
dcf <- function(x, r, t0=FALSE){
# calculates discounted cash flows (DCF) given cash flow and discount rate
#
# x - cash flows vector
# r - vector or discount rates, in decimals. Single values will be recycled
# t0 - cash flow starts in year 0, default is FALSE, i.e. discount rate in first period is zero.
if(length(r)==1){
r <- rep(r, length(x))
if(t0==TRUE){r[1]<-0}
}
x/cumprod(1+r)
}
npv <- function(x, r, t0=FALSE){
# calculates net present value (NPV) given cash flow and discount rate
#
# x - cash flows vector
# r - discount rate, in decimals
# t0 - cash flow starts in year 0, default is FALSE
sum(dcf(x, r, t0))
}
pbp <- function(x, ...){
# calculates payback period (PBP)
#
# x - cash flows vector
# ... - ignored
i <- match(1, sign(cumsum(x)))
i-2+(-cumsum(x)[i-1]/x[i])
}
dpbp <- function(x, r, t0=FALSE){
# calculates discounted payback period (DPBP) given cash flow and discount rate
#
# x - cash flows vector
# r - discount rate, in decimals
# t0 - cash flow starts in year 0, default is FALSE
pbp(dcf(x, r, t0))
}
irr <- function(x, t0=FALSE, ...){
# calculates internal rate of return (IRR) given cash flow
#
# x - cash flows vector
# t0 - cash flow starts in year 0, default is FALSE
tryCatch(uniroot(f=function(i){sum(dcf(x, i, t0))},
interval=c(0,1))$root,
error=function(e) return(NA)
)
}
CDF.P1 <- dcf(Project1, r= 0.06, t0 = FALSE)
knitr::kable(CDF.P1)
```
## The Input data
We have two different projects to be evaluated based on the folowing economic parameters:
- Net Present Value _**NPV**_
- Internal Rate of Return _**IRR**_
- Pay back Period _**PBP**_
- Discounted Pay back Period _**DPBP**_
- Discounted Cash Flow _**DCF**_
```{r}
### the Two Project that needed to be evaluated
# To evaluate the two projects they should have the same project time
#together to evaluate them together or you should evaluate them separately
Time.Evaluation <-c(1:6)
Project1 <- c(-1000, 1250, 10, 10, 20, 20)
Project2 <- c(-1000, -10, 0, 10, 20, 2000)
Projects.data <- data.frame(Time.Evaluation, Project1 , Project2)
knitr::kable(Projects.data)
```
## The Method of Evaluations
```{r}
### Calculating the Discounted Cash Flow "DCF"
### the interest rate given is 0.06 "6%"
CDF.P1 <- dcf(Project1, r= 0.06, t0 = FALSE)
cdfProject1<- data.frame(Time.Evaluation, Project1,CDF.P1)
knitr::kable(cdfProject1)
```