-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinancial.r
55 lines (41 loc) · 2.02 KB
/
financial.r
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
# this is based off of an udemy course
# Scenario: You are a Data Scientist working for a consulting firm. One of your
# colleagues from the Auditing department has asked you to help them assess the
# financial statement of organisation X.
# You have been supplied with two vectors of data: monthly revenue and monthly
# expenses for the financial year in question. Your task is to calculate the following
# financial metrics:
# - profit for each month
# - profit after tax for each month (the tax rate is 30%)
# - profit margin for each month - equals to profit a after tax divided by revenue
# - good months - where the profit after tax was greater than the mean for the year
# - bad months - where the profit after tax was less than the mean for the year
# - the best month - where the profit after tax was max for the year
# - the worst month - where the profit after tax was min for the year
# All results need to be presented as vectors.
# Results for dollar values need to be calculated with $0.01 precision, but need to be
# presented in Units of $1,000 (i.e. 1k) with no decimal points.
# Results for the profit margin ratio need to be presented in units of % with no
# decimal points.
# Note: You colleague has warned you that it is okay for tax for any given month to be
# negative (in accounting terms, negative tax translates into a deferred tax asset).
# yooooooooooo
#Data
revenue <- c(14574.49, 7606.46, 8611.41, 9175.41, 8058.65, 8105.44, 11496.28, 9766.09, 10305.32, 14379.96, 10713.97, 15433.50)
expenses <- c(12051.82, 5695.07, 12319.20, 12089.72, 8658.57, 840.20, 3285.73, 5821.12, 6976.93, 16618.61, 10054.37, 3803.96)
#Solution
profitYr <- revenue - expenses
print(round(profitYr))
profitYrTax <- round(profitYr * .70, digits = 2)
print(profitYrTax)
profitMarg <- (profitYrTax / revenue) * 100
print(profitMarg)
yrMean <- mean(profitYrTax)
goodMo <- profitYrTax >= yrMean
print(goodMo)
badMo <- profitYrTax < yrMean
print(badMo)
bestMo <- max(profitYrTax)
print(round(bestMo))
worstMo <- min(profitYrTax)
print(round(worstMo))