-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcrowdrisk-dev.R
114 lines (93 loc) · 4.38 KB
/
crowdrisk-dev.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
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
# Crowdfunding investment risk.
# Calculating the risk of crowd investments and
# calculating the expected actual return on investment.
# ---- #
# Create a hypothetical portfolio:
# Investing 10.000 euros.
# Each project runs over 5 years and gives a 5% interest per year.
# Each project has in each given year a likelihood of 10% of default of payment.
# To start with, let's assume for simplicity that the yearly likelihood is
# independent from the occurrance of default of payment in the preceding year.
# Note there is no compound interest (Zinseszins)!
# How does the risk and especially the expected
# actual return on investment change with the number of
# projects invested into??
# Let's assume we invest into 1 project only.
# What's the expected actual return on investment?
years <- 5
interest_pa <- 0.05 # p.a. interest
investment <- 10000
default_likelihood <- 0.1 # default likelihood.
payment_likelihood <- 1 - default_likelihood # p.a. likelihood of payment.
n_projects <- 1
# return on investment without default of payment:
# Formula of return on investment:
# ROI = (earning - initial investment) / initial investment
(investment*0.05*years + investment) * 100 / investment
# after 5 years, the initial capital has grown to 125% (or by one quarter).
# Now let's assume there is a 10% default of payment each year.
(investment*0.05*payment_likelihood*years + investment) * 100 / investment
# after 5 years, the initial capital has grown to 122.5%.
# That's actually not that bad.
# ------------- #
# I think to accurately catch the risk of crowdinvestment,
# I need to look at a worst case scenario if one project out of
# ten fails altogether.
# If we invest only in one project, what's the best outcome?
# What's the worst outcome?
v <- numeric(100) # number of simulations
money_at_end_fun <- function(n_projects, default_likelihood, investment, years) {
for (i in seq_along(v)) {
portfolio_fail <- sample(x = c(0, 1), size = n_projects,
replace = T,
prob = c(1 - default_likelihood, default_likelihood))
portfolio_fail <- sum(portfolio_fail)/length(portfolio_fail) # percentage
portfolio_success <- 1 - portfolio_fail
money_earned <- investment*0.05*portfolio_success*years
money_lost <- investment*portfolio_fail
money_at_end <- investment*0.05*portfolio_success*years +
investment*portfolio_success
v[i] <- money_at_end
}
money_per_project = round(investment / n_projects, 0)
best_outcome <- round(max(v), 0)
worst_outcome <- round(min(v), 0)
boxplot(v,
ylim = c(0, investment*1.4), # create the same scale for all plots
main = "money at end of investment period",
horizontal = T)
title(xlab = paste0("number of projects: ", n_projects,
"\nmoney per project: ", money_per_project,
"\nbest outcome: ", best_outcome,
"\nworst outcome: ", worst_outcome), line = 3)
abline(v = mean(v), col = "red") # expected/mean outcome
# add points for the best and worst possible outcomes:
points(x = c(best_outcome, worst_outcome), y = c(1, 1),
col = c("green", "red"), pch = 19)
# add line to show the invested capital:
abline(v = investment, lty = 2) # expected/mean outcome
}
dev.off()
par(mfrow = c(2, 3), oma = c(2, 2, 1, 2),
mar = c(4, 3, 3, 3))
money_at_end_fun(n_projects = 1, default_likelihood = 0.1,
investment = 10000, years = 5)
# If we invest in 5 projects, what's the best outcome?
# What's the worst outcome?
money_at_end_fun(n_projects = 5, default_likelihood = 0.1,
investment = 10000, years = 5)
# If we invest in 9 projects, what's the best outcome?
# What's the worst outcome?
money_at_end_fun(n_projects = 9, default_likelihood = 0.1,
investment = 10000, years = 5)
money_at_end_fun(n_projects = 20, default_likelihood = 0.1,
investment = 10000, years = 5)
money_at_end_fun(n_projects = 30, default_likelihood = 0.1,
investment = 10000, years = 5)
money_at_end_fun(n_projects = 100, default_likelihood = 0.1,
investment = 10000, years = 5)
money_at_end_fun(n_projects = 150, default_likelihood = 0.1,
investment = 10000, years = 5)
# ROI:
# roi <- (investment*0.05*portfolio_success*years +
# investment - money_lost) * 100 / investment