The core of a financial cash flow model lies in its model variables. In this blog post, we will delve into the intricacies of different types of model variables and demonstrate how to create them using the cashflower package.

List of content:

## Defining model variables

To define a model variable, follow these steps:

- define a function with the t parameter (or without any parameters),
- decorate the function with @variable().

Model variables can produce results per time and model point. While most are time-dependent, some remain constant throughout. Let's explore both types.

Types of variables:

- A - time-dependent variable,
- B - time-independent variable,

We will guide you through creating both types of model variables in the sections below.

## Time-dependent variable

Time-dependent variables generate values for each future period. To create one, define a function with the t parameter and decorate it with @variable().

For example:

```
@variable()
def cal_month(t):
if t == 0:
return runplan.get("valuation_month")
if cal_month(t-1) == 12:
return 1
else:
return cal_month(t-1) + 1
```

The variable can be called inside of another variable.

For example:

```
@variable()
def cal_year(t):
...
cal_month(t-1)
...
```

## Constant variable

To define time-independent variables, create a function without any parameters.

```
@variable()
def elapsed_months():
issue_year = main.get("issue_year")
issue_month = main.get("issue_month")
valuation_year = runplan.get("valuation_year")
valuation_month = runplan.get("valuation_month")
return (valuation_year - issue_year) * 12 + (valuation_month - issue_month)
```

Constant variables, like elapsed_months, maintain a consistent value throughout the projection, making them independent of time. To call such variables, there's no need to pass any arguments.

For example:

```
@variable()
def pol_month(t):
...
mnth = elapsed_months() % 12
...
```

These variables are particularly useful for storing information that remains unchanged over time.

Thank you for reading this blog post! I hope it provided you with valuable insights. Feel free to leave a comment below or on github to share your thoughts or ask any questions. Your feedback is greatly appreciated!