c语言 随机种子 monte carlo,GitHub - LJY404/bizforecast-exercise: 商业化蒙特卡洛模拟练习...
README
蒙特卡洛模擬可以幫助分析在商業(yè)上一些復雜的場景, 包括了衡量風險以及計算某項目在特定條件下可產(chǎn)生的收益. 我們將通過一個簡化的例子表現(xiàn)蒙特卡洛模擬的應用.
Often, Monte Carlo simulation can come in handy to calculate risk or evaluate investments in projects. This is a simple demonstration.
背景
小象數(shù)據(jù)科學是剛成立不久的事業(yè)部. 主要針對9到12歲的兒童進行數(shù)據(jù)科學基礎培訓, 以促進培育國家未來數(shù)據(jù)人才的步伐. 經(jīng)過3個月的試點, 管理層希望對業(yè)務采集的數(shù)據(jù)進行分析, 衡量該業(yè)務的風險點與可持續(xù)性.
你作為商業(yè)分析組的一員, 將通過數(shù)據(jù)模擬優(yōu)先回答以下問題:
以【月】為單位的利潤是怎么樣的一個分布? 以百分之95的置信度而言, 利潤在什么范圍區(qū)間?
解答: 服從正太分布
library(tidyverse)
## ─ Attaching packages ─────────────────────────────────────── tidyverse 1.2.1 ─
## ? ggplot2 3.1.0 ? purrr 0.3.2
## ? tibble 2.0.0 ? dplyr 0.7.8
## ? tidyr 0.8.2 ? stringr 1.3.1
## ? readr 1.3.1 ? forcats 0.3.0
## ─ Conflicts ──────────────────────────────────────── tidyverse_conflicts() ─
## ? dplyr::filter() masks stats::filter()
## ? dplyr::lag() masks stats::lag()
library(ggthemes)
library(ggplot2)
library(rio)
library(infer)
set.seed(1212)
N=1000
R=rnorm(N, mean=0.4, sd=0.05)
M=runif(5,350,400)
L=runif(5,3000,4000)
S=L*R #收入
INCOME=M*S
Cpl=runif(5,8,10)
H=20000
Expenses=Cpl*L+H #成本
Profit=INCOME-Expenses
如果我們設置一個月的利潤目標為10萬元, 達成目標的概率是多少? 虧損風險 (利潤小于0的概率) 是多少?
利潤的累積分布函數(shù) (cumulative distribution)? (繪圖即可)
經(jīng)過第一輪的探索, 你與業(yè)務分享你的結(jié)果. 業(yè)務發(fā)現(xiàn)你的模擬出現(xiàn)了嚴重的漏洞. 以他們的業(yè)務經(jīng)驗, 單個栗子的成本與其轉(zhuǎn)化率是強關(guān)聯(lián)關(guān)系的. 你提取了以往投放的數(shù)據(jù) (見附帶表格 csv), 發(fā)現(xiàn)果真如此. 于是, 你更新了你的模型. 請以新模型回答以上3點問題.
data
cor_matr = cor(data) #相關(guān)矩陣
cor_matr
## cost_per_lead conversion_rate
## cost_per_lead 1.0000000 0.9882867
## conversion_rate 0.9882867 1.0000000
data %>%
ggplot(aes(cost_per_lead, conversion_rate)) +
geom_line(size = 1, color = "grey30") #數(shù)據(jù)實際分布圖
test_mod
test_mod
##
## Call:
## lm(formula = conversion_rate ~ cost_per_lead, data = data)
##
## Coefficients:
## (Intercept) cost_per_lead
## -0.18104 0.02456
predict(test_mod,newdata=data.frame(cost_per_lead=9.8),interval="confidence")
## fit lwr upr
## 1 0.05964785 0.0578207 0.06147499
knitr::opts_chunk$set(echo = FALSE)
如果業(yè)務提出一個產(chǎn)品方案, 在增加固定成本百分之25至30的前提下, 每天的栗子數(shù)量可以提升百分之15至25. 請問你會如何評估該方案?
管理層認為單個栗子的成本過高, 具有很大的優(yōu)化空間. 他們希望把虧損風險控制在百分之35之內(nèi). 請問根據(jù)該需求, 單個栗子成本的上線是多少?
業(yè)務信息
利潤 (Profit) = 收入 (Revenue) - 開銷 (Expenses)
注意: 這里所有指標均以【天】為單位
* 收入為個單毛利 (Profit margin, M) 乘與銷量 (Sales, S);
* 個單毛利為均勻 (uniform) 分布, 一單 350 元至 400 元;
* 銷量為栗子數(shù)量 (Number of leads, L) 乘與轉(zhuǎn)化率 (Conversion rate, R);
* 栗子數(shù)量為均勻分布, 一天 3000 個至 4000 個;
* 轉(zhuǎn)化率為正態(tài) (normal) 分布, 均值為 4%, 偏差為 0.5%;
* 開銷為固定成本 (Fixed overheads, H) 加上栗子成本;
* 固定成本 (研發(fā), 辦公) 平攤為每天 2 萬元;
* 栗子成本為栗子數(shù)量乘于單個栗子成本 (Cost per lead, Cpl);
* 單個栗子成本為均勻分布, 單個 8 元至 10 元;
Profit = Income - Expenses
Income = Profit Margin per Sale (M) * Sales (S)
M assumes an uniform dist. from $350 to $400
S = Number of Leads (L) * Conversion Rate (R)
L assumes an uniform dist. with from 3000 to 4000
R assumes a normal dist. with mean of 4% and sd of 0.5%
Expenses = Fixed Overhead (H) + Total Cost of the Leads (C)
H assumes a constant of $20000
C = Cost Per Lead (Cpl) * Number of Leads (L)
Cpl assumes an uniform dist. from $8 to $10
Profit = Leads * Conversion Rate * Profit Margin per Sale - (Cost per Lead * Leads + Fixed Overhead)
幫助
你可能會用到一下函數(shù):
sample replicate which rnorm runif rbeta lm predict geom_point geom_line stat_ecdf
請設置隨機種子為 1212
總結(jié)
以上是生活随笔為你收集整理的c语言 随机种子 monte carlo,GitHub - LJY404/bizforecast-exercise: 商业化蒙特卡洛模拟练习...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 专色印刷的相关知识
- 下一篇: android网络请求框架汇总