Simulation operates using the simple constructor :Data In , Data Out or Inputs -> Model -> Outputs. This section covers importing inputs, perhaps from a different department or external source and then exporting the results for consumption by the interested stakeholders.
Essentially all Monte-Carlo simulation results take the form of a 2 dimensional table consisting of Trials (rows) and Variables (columns). Each variable is a vector (column) of numbers in a specific order. The order is important because it is what maintains the correlation structure. For example, because of the ordered sequence, you could calculate the R2 or correlation using any 2 output vector or input vectors.
Another thing to keep in mind is that each trial is assigned an ID and the generated by pushing a set of inputs into a model and recording the results in a row. Below is an example of a simulation results for Revenue - Expenses = Profit [output].
A simulation results table should contain inputs variables and output variables side by side. This is a good practice because in theory it allows you to reconstruct/validate the results. In all cases, the number of trials/rows, must be of consistent length for all inputs and outputs in the model. (i.e. A 1000 trials). Each trial should have a trial ID. You can easily generate a Trial ID vector using TrialID = collect(1:1000)_ and append the column to your results using hcat().
SIPMath and probability management are approaches that were popularized by Sam Savage in 2009. A SIP Is known technically as a stochastic information packet or vector. The basic idea behind SIPMath is that models can be simplified and broken out into submodels. Generally, the output of a submodel can be summarized as an output vector and saves a lot of the computing efforts required to rerun both models together side-by-side.
In the SIPmath Standard, uncertainties are communicated as data arrays called SIPs (Stochastic Information Packets). For example, the SIP representing the roll of a die would be expressed as thousands of outcomes, which could be stored in Excel or a database. The open SIPmath™ Standard enables legacy and future simulation models to communicate with each other, ushering in a new paradigm for enterprise risk management.
The SIPMath standard can be consulted on the probabilitymanagement.org website
Importing results from another model for use in your analysis is a core element in building shared/collaborative models. The goal is to leverage the expertise/existing models/knowledge residing in other parts of the organization into a new model.
In Julia, You can pretty much important thing you like with formats such as XML, JSON, CSV. Furthermore, most Internet data APIs will allow you to download either of these formats and gives you the ability to have an auto updating model. Though you can use anything available in Julia to import your data into a data frame, MC Hammer handles CSV the most efficiently. There are 2 basic ways to import data into your MCHammer monte-carlo model:
- using standard CSV tables. Julia's CSV package is quite an effective tool and converts a CSV table into a data frame. As mentioned, as long as you remember that the number of trials must be consistent, you can import almost any table from the Internet.
- using the SIPMath 2.0 CSV Standard. MCHammer provides several functions to do so.
To import from the SIPModeler tool (also available for free from ProbabilityManagement.org), we recommend using the importxlsip()
This function allows to import SIPs in CSV format from Excel using the SIP 2.0 Standard (Stochastic Information Packets, Savage) to build unified simulation models. Based on the CSV package, the function cleans up meta data and cleans out redundant columns. You can also set a source string that will be included in your SIP DataFrame as a dimension.
When importing data using the strict 2.0 standard from another environment, including R, Python or some other business/planning system, we recommend using the importsip() function instead.
importsip(FileName, source="Not specified by user")
This function allows to import SIPs in CSV format from Julia using the SIP 2.0 Standard (Stochastic Information Packets, Savage) to build unified simulation models. Based on the CSV package, the function cleans up meta data and cleans out redundant columns. You can also set a source string that will be included in your SIP DataFrame as a dimension.
Exporting results from a simulation built in Julia can also be done using either the standard CSV package or with the functions included in MC Hammer to export using the SIPMath standard. One of the main differences when working in a programmatic environment versus a spreadsheet is that the metadata needs to reside in a separate file first before it can be recombined in the final export format. To do so, we have created both a function for incorporating MetaData into your SIP library and one for exporting the simulation results.
SIPs using the SIP 2.0 Standard (Stochastic Information Packets, Savage) require that Meta Data be available and maintained. This function creates a file template to add MetaData to your SIP Library. This is a seperate file must accompany the DataFrame to generate the SIP Library correctly. If ommited, the file will export the SIP Library without any metadata.
sip2csv(FileName, source_df, s_name="SLURP", s_origin="Julia Language")
- In order to export a SIP Library from Julia, you simply need to have a DataFrame.
- Only specify header fields if your data does not contain any.
- Also make to specify the full filename, including extension