# Generators

SEL 201: Source, Curve, Trend, and Extend

Moving beyond basic formulas and functions, SEL includes a small (but growing) number of event types. These classes give you powerful control over how values move throughout your model, a concept we call flow.

# Source

A `Source` generates values to sent to other events. A good example is a revenue source. If my business earns \$100,000 per month, growing at 3% per month, I could use a SEL formula to represent this income stream like so:

`=Source(100k @ 3%)`

### 📘Source or List

The benefit of using a Source over a list is the ability to attach a growth rate. Lists may only contain constants (unchanging) values, whereas the values returned from a Source can change over time using a growth rate, or a list of growth rates.

This event will send a steady stream of one hundred thousand (growing at 3%) to downstream events.

#### Maximum Values

Sources can also take a second argument, used to set a maximum value. For example:

`=Source(100k @ 3%, 110k)`

This will grow 100,000 by 3% until it reaches 110,000. At this point, it will consistently send 110,000.

If you send a value to a source, the size of the source will increase by the received value. This means you can simulate a pay increase, for example, by having an annually recurring event send a raise amount to a monthly salary source.

There's a second way to express a maximum value for a source, which can also take a minimum value -- the spread operator: `...`.

`=Source(100k...110k @ 3%)`

Will grow 100,000 by 3% per occurrence until 110,000 is reached, then repeat 110,000.

`=Source(100k...90k @ -10%)`

Will decrease 100,000 to 90,000 in increments of -10%.

This also works with negative values:

`=Source(-2k...-5k @ 10%)`

Will "grow" -2,000 by 10% per occurrence to a minimum of -5,000.

### 👍See example of Source in practice:

Customer Acquisition Example

# Curve

The `Curve` event generates values along a specified curve, like so:

`=Curve('s', [365, 1k])`

The first argument is the type of curve. The supported curve types are `s` (S-curve) and `m` (straight line or linear). The second argument is a list where the first value (`365`) represents the number of days until the maximum value is reached. The maximum value is defined by an optional second element in the list, here `1k` (1,000). If the maximum is omitted, the maximum will default to `1`.

Most growth in nature and business follows an S-curve (short for sigmoid). That makes this event especially useful for modeling the growth of almost anything, especially when a precise mathematical model (i.e. growth rates) is unknown.

# Trend

Like a source, a `Trend` generates a series of values that are sent downstream to other events. But unlike a source, rather than taking an initial value and optional growth rate, a `Trend` takes a series of historical values:

`=Trend([12.1k,15.5k,13.6k,14.4k])`

Summit will fit a trendline to this series of values and return the values in the sequence, in this case: `15,150, 15,650, 16,150, 16,650, ...`

### 🚧What's in a trend?

True to its name, a trend is just a trend. The purpose of a trend is directionality. Therefore, this source of values is useful when historical values bounce around, and the most important element is understanding the general movement of these values, rather than the specific value in any given future month.

# Extend

The `Extend` source takes a series of values and extends them using the last two values in the sequence. For example:

`=Extend([1,2,3,10])`

Will return `17, 24, 31, 38 ...` because the slope of the final two items is 7.

The extend event is useful for drawing a straight line when the most recent values are an indication of the future.