Install the package as usual using Pkg.
julia> using Pkg
julia> Pkg.("MCHammer")
If you need to install direct, we recommend using ']' to go in the native Pkg manager.
(v1.1) pkg> add https://github.com/etorkia/MCHammer.jl
To load the MCHammer package
julia> using MCHammer
In order to build your first model, you will need to get a few more packages installed:
Distributions.jl : To build a simulation, you need distributions as inputs. Julia offers univariate and multivariate distributons covering most needs.
StatsBase.jl and Statistics.jl : These packages provide all the functions to analyze results and build models.
To load the support packages:
julia> using Distributions, Statistics, StatsBase, DataFrames
EVERY MONTE CARLO MODEL HAS 3 COMPONENTS
Though the most used distributions are cite below, Julia's Distributions package has an impressive array of options. Please check out the complete library of distributions at Distributions.jl
# In order to define a simulated input you need to use the *rand* function. By assigning a a variable name, you can generate any simulated vector you want.
input_variable = rand(Normal(0,1),100)
A model is either a visual or mathematical representation of a situation or system. The easiest example of a model is PROFIT = REVENUE - EXPENSES
Let's create a simple simulation model with 1000 trials with the following inputs:
julia> n_trials = 1000
julia> Revenue = rand(TriangularDist(2500000,4000000,3000000), n_trials)
julia> Expenses = rand(TriangularDist(1400000,3000000,2000000), n_trials)
`Profit = Revenue - Expenses`
using Distributions, StatsBase, DataFrames, MCHammer
n_trials = 1000
Revenue = rand(TriangularDist(2500000,4000000,3000000), n_trials)
Expenses = rand(TriangularDist(1400000,3000000,2000000), n_trials)
#Create the Profit vector (OUTPUT)
Profit = Revenue - Expenses
# the fractiles() allows you to get the percentiles at various increments.
fractiles(Profit)
density_chrt(Profit)
# First we need to create a sensitivity table with hcat() using both the input and output vectors.
s_table = hcat(Profit, Revenue, Expenses)
#We then need to convert to a DataFrame
s_table = DataFrame(s_table)
names!(s_table, [:Profit, :Revenue, :Expenses])
# To produce a sensitivity tornado chart, we need to select the output against which the inputs are measured for effect.
sensitivity_chrt(s_table, 1, 3)