-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEconomic_Model.html
More file actions
305 lines (270 loc) · 12.1 KB
/
Copy pathEconomic_Model.html
File metadata and controls
305 lines (270 loc) · 12.1 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="AmrMoslim" />
<meta name="date" content="2019-04-24" />
<title>Economic Model</title>
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>
<link rel="stylesheet" href="Economic_Model_files/style.css" type="text/css" />
</head>
<body>
<div id="container">
<div class="inner">
<header>
<h1 class="title toc-ignore">Economic Model</h1>
<h3 class="author">AmrMoslim</h3>
<h3 class="date">2019-04-24</h3>
</header>
<hr>
<div id="TOC" class="toc">
<ul>
<li><a href="#creating-economic-model-for-oil-and-gas-projects-ecoman">Creating Economic Model for Oil and Gas Projects <em><strong>EcoMan</strong></em></a><ul>
<li><a href="#writing-the-economic-functions">Writing The Economic Functions</a></li>
</ul></li>
<li><a href="#the-input-data">The Input data</a></li>
<li><a href="#the-method-of-evaluations">The Method of Evaluations</a></li>
</ul>
</div>
<div id="creating-economic-model-for-oil-and-gas-projects-ecoman" class="section level2">
<h2>Creating Economic Model for Oil and Gas Projects <em><strong>EcoMan</strong></em></h2>
<div id="writing-the-economic-functions" class="section level3">
<h3>Writing The Economic Functions</h3>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">### Writing the Economic Functions to calculate DCF, NPV, IRR and PBP, DPBP
dcf <-<span class="st"> </span><span class="cf">function</span>(x, r, <span class="dt">t0=</span><span class="ot">FALSE</span>){
<span class="co"># calculates discounted cash flows (DCF) given cash flow and discount rate</span>
<span class="co">#</span>
<span class="co"># x - cash flows vector</span>
<span class="co"># r - vector or discount rates, in decimals. Single values will be recycled</span>
<span class="co"># t0 - cash flow starts in year 0, default is FALSE, i.e. discount rate in first period is zero.</span>
<span class="cf">if</span>(<span class="kw">length</span>(r)<span class="op">==</span><span class="dv">1</span>){
r <-<span class="st"> </span><span class="kw">rep</span>(r, <span class="kw">length</span>(x))
<span class="cf">if</span>(t0<span class="op">==</span><span class="ot">TRUE</span>){r[<span class="dv">1</span>]<-<span class="dv">0</span>}
}
x<span class="op">/</span><span class="kw">cumprod</span>(<span class="dv">1</span><span class="op">+</span>r)
}
npv <-<span class="st"> </span><span class="cf">function</span>(x, r, <span class="dt">t0=</span><span class="ot">FALSE</span>){
<span class="co"># calculates net present value (NPV) given cash flow and discount rate</span>
<span class="co">#</span>
<span class="co"># x - cash flows vector</span>
<span class="co"># r - discount rate, in decimals</span>
<span class="co"># t0 - cash flow starts in year 0, default is FALSE</span>
<span class="kw">sum</span>(<span class="kw">dcf</span>(x, r, t0))
}
pbp <-<span class="st"> </span><span class="cf">function</span>(x, ...){
<span class="co"># calculates payback period (PBP)</span>
<span class="co">#</span>
<span class="co"># x - cash flows vector</span>
<span class="co"># ... - ignored</span>
i <-<span class="st"> </span><span class="kw">match</span>(<span class="dv">1</span>, <span class="kw">sign</span>(<span class="kw">cumsum</span>(x)))
i<span class="op">-</span><span class="dv">2</span><span class="op">+</span>(<span class="op">-</span><span class="kw">cumsum</span>(x)[i<span class="op">-</span><span class="dv">1</span>]<span class="op">/</span>x[i])
}
dpbp <-<span class="st"> </span><span class="cf">function</span>(x, r, <span class="dt">t0=</span><span class="ot">FALSE</span>){
<span class="co"># calculates discounted payback period (DPBP) given cash flow and discount rate</span>
<span class="co">#</span>
<span class="co"># x - cash flows vector</span>
<span class="co"># r - discount rate, in decimals</span>
<span class="co"># t0 - cash flow starts in year 0, default is FALSE</span>
<span class="kw">pbp</span>(<span class="kw">dcf</span>(x, r, t0))
}
irr <-<span class="st"> </span><span class="cf">function</span>(x, <span class="dt">t0=</span><span class="ot">FALSE</span>, ...){
<span class="co"># calculates internal rate of return (IRR) given cash flow </span>
<span class="co">#</span>
<span class="co"># x - cash flows vector</span>
<span class="co"># t0 - cash flow starts in year 0, default is FALSE</span>
<span class="kw">tryCatch</span>(<span class="kw">uniroot</span>(<span class="dt">f=</span><span class="cf">function</span>(i){<span class="kw">sum</span>(<span class="kw">dcf</span>(x, i, t0))},
<span class="dt">interval=</span><span class="kw">c</span>(<span class="dv">0</span>,<span class="dv">1</span>))<span class="op">$</span>root,
<span class="dt">error=</span><span class="cf">function</span>(e) <span class="kw">return</span>(<span class="ot">NA</span>)
)
}
CDF.P1 <-<span class="st"> </span><span class="kw">dcf</span>(Project1, <span class="dt">r=</span> <span class="fl">0.06</span>, <span class="dt">t0 =</span> <span class="ot">FALSE</span>)
knitr<span class="op">::</span><span class="kw">kable</span>(CDF.P1)</code></pre></div>
<table>
<thead>
<tr class="header">
<th align="right">x</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="right">-943.396226</td>
</tr>
<tr class="even">
<td align="right">1112.495550</td>
</tr>
<tr class="odd">
<td align="right">8.396193</td>
</tr>
<tr class="even">
<td align="right">7.920937</td>
</tr>
<tr class="odd">
<td align="right">14.945163</td>
</tr>
<tr class="even">
<td align="right">14.099211</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="the-input-data" class="section level2">
<h2>The Input data</h2>
<p>We have two different projects to be evaluated based on the folowing economic parameters:<br />
- Net Present Value <em><strong>NPV</strong></em><br />
- Internal Rate of Return <em><strong>IRR</strong></em><br />
- Pay back Period <em><strong>PBP</strong></em><br />
- Discounted Pay back Period <em><strong>DPBP</strong></em><br />
- Discounted Cash Flow <em><strong>DCF</strong></em></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">### the Two Project that needed to be evaluated
<span class="co"># To evaluate the two projects they should have the same project time</span>
<span class="co">#together to evaluate them together or you should evaluate them separately</span>
Time.Evaluation <-<span class="kw">c</span>(<span class="dv">1</span><span class="op">:</span><span class="dv">6</span>)
Project1 <-<span class="st"> </span><span class="kw">c</span>(<span class="op">-</span><span class="dv">1000</span>, <span class="dv">1250</span>, <span class="dv">10</span>, <span class="dv">10</span>, <span class="dv">20</span>, <span class="dv">20</span>)
Project2 <-<span class="st"> </span><span class="kw">c</span>(<span class="op">-</span><span class="dv">1000</span>, <span class="op">-</span><span class="dv">10</span>, <span class="dv">0</span>, <span class="dv">10</span>, <span class="dv">20</span>, <span class="dv">2000</span>)
Projects.data <-<span class="st"> </span><span class="kw">data.frame</span>(Time.Evaluation, Project1 , Project2)
knitr<span class="op">::</span><span class="kw">kable</span>(Projects.data)</code></pre></div>
<table>
<thead>
<tr class="header">
<th align="right">Time.Evaluation</th>
<th align="right">Project1</th>
<th align="right">Project2</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="right">1</td>
<td align="right">-1000</td>
<td align="right">-1000</td>
</tr>
<tr class="even">
<td align="right">2</td>
<td align="right">1250</td>
<td align="right">-10</td>
</tr>
<tr class="odd">
<td align="right">3</td>
<td align="right">10</td>
<td align="right">0</td>
</tr>
<tr class="even">
<td align="right">4</td>
<td align="right">10</td>
<td align="right">10</td>
</tr>
<tr class="odd">
<td align="right">5</td>
<td align="right">20</td>
<td align="right">20</td>
</tr>
<tr class="even">
<td align="right">6</td>
<td align="right">20</td>
<td align="right">2000</td>
</tr>
</tbody>
</table>
</div>
<div id="the-method-of-evaluations" class="section level2">
<h2>The Method of Evaluations</h2>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">### Calculating the Discounted Cash Flow "DCF"
### the interest rate given is 0.06 "6%"
CDF.P1 <-<span class="st"> </span><span class="kw">dcf</span>(Project1, <span class="dt">r=</span> <span class="fl">0.06</span>, <span class="dt">t0 =</span> <span class="ot">FALSE</span>)
cdfProject1<-<span class="st"> </span><span class="kw">data.frame</span>(Time.Evaluation, Project1,CDF.P1)
knitr<span class="op">::</span><span class="kw">kable</span>(cdfProject1)</code></pre></div>
<table>
<thead>
<tr class="header">
<th align="right">Time.Evaluation</th>
<th align="right">Project1</th>
<th align="right">CDF.P1</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="right">1</td>
<td align="right">-1000</td>
<td align="right">-943.396226</td>
</tr>
<tr class="even">
<td align="right">2</td>
<td align="right">1250</td>
<td align="right">1112.495550</td>
</tr>
<tr class="odd">
<td align="right">3</td>
<td align="right">10</td>
<td align="right">8.396193</td>
</tr>
<tr class="even">
<td align="right">4</td>
<td align="right">10</td>
<td align="right">7.920937</td>
</tr>
<tr class="odd">
<td align="right">5</td>
<td align="right">20</td>
<td align="right">14.945163</td>
</tr>
<tr class="even">
<td align="right">6</td>
<td align="right">20</td>
<td align="right">14.099211</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>