Output

The cash flow model generates three types of output files: output, diagnostic, and log. These files are organized within the output folder, as shown below:

.
└── output/
    └── <timestamp>.log
    └── <timestamp>_diagnostic.csv
    └── <timestamp>_output.csv

The model will automatically create an output folder if it doesn’t already exist. Inside this folder, the model will generate a CSV file containing the output results. If specified, the model will also save a diagnostics file, which is also in CSV format, and a log file in text format.


Structure

The output of a cash flow model is presented as a table, where rows represent time periods, and columns represent model variables. The structure of the output depends on the following settings:

  • GROUP_BY - the column name used to group the results.

  • T_MAX_OUTPUT - specifies the number of projection periods included in the output.

  • OUTPUT_VARIABLES - a list of output variables to be included (by default, all variables are included).

Let’s explore these settings with examples.


Grouped output

By default, the GROUP_BY is set to None which means that the results are aggregated across all model points.

settings.py
settings = {
    # ...
    "GROUP_BY": None,
    # ...
}

In the aggregated output, results are summed across all model points, resulting in a single set of projections. The number of rows in this output is determined by T_MAX_OUTPUT + 1, where the +1 accounts for the projection starting at time period 0.

You can also aggregate data by groups. To do this, specify the GROUP_BY as the column name containing the grouping variable from your model point set.

For example, to group results by product_code, configure your settings as follows:

settings.py
settings = {
    # ...
    "GROUP_BY": "product_code",
    # ...
}

Subset of variables

The OUTPUT_VARIABLES setting takes a list of variables names to include in the output. By default, when this setting is an empty list, results for all model variables are generated.

If you only require specific variables in the output, you can select them using the OUTPUT_VARIABLES setting:

settings.py
settings = {
    # ...
    "OUTPUT_VARIABLES": ["bel"],
    # ...
}
output
t    bel
0    27000.0
1    27054.0
2    27108.11
3    27162.32
...  ...
720  31413.12

Default vs. custom output


Default output

By default, the model’s results are saved to a CSV file. This file is saved in the output folder within the model’s directory. The filename follows the format <timestamp>_output.csv, where <timestamp> represents the date and time when the model was executed (e.g., 20231125_173512_output.csv).


Custom output

The default output behavior can be customized to suit specific requirements, such as saving results to different file formats or uploading them to a database. To use custom output, follow these steps:

1. Set the SAVE_OUTPUT setting to False in your settings.py file. This prevents the model from saving the output in the default manner:

settings.py
settings = {
    # ...
    "SAVE_OUTPUT": False,
    # ...
}

2. Modify the run.py script to handle custom output. For instance, you can save results as a text file without timestamps:

run.py
if __name__ == "__main__":
    output, _, _ = run(settings)
    output.to_string("output.txt")

Now, instead of creating an <timestamp>_output.csv file, the script will generate an output.txt file with the results.