Skip to content

Pricing behavior

A pricing behavior defines the strategy under which flights assign prices to seats.

BaseBehaviorModel dataclass

Bases: PricingModel

Base class for all types of pricing behavior models.

Source code in src/rmlab/data/parametric/pricing_behavior.py
11
12
13
14
15
@dataclass
class BaseBehaviorModel(PricingModel):
    """Base class for all types of pricing behavior models."""

    pass

RakeBehaviorModel dataclass

Bases: BaseBehaviorModel

A kind of pricing behavior model in which a set of seat thresholds are used to allocate seats to fares based on the flight occupation. These thresholds can be squeezed with respect to the total flight occupation or shifted up from zero occupation.

Parameters:

NameTypeDescriptionDefault
zero_shiftfloat

Per-unit relative displacement of all the thresholds

required
squeezefloat

Per-unit relative contraction of the all thresholds

required
Source code in src/rmlab/data/parametric/pricing_behavior.py
17
18
19
20
21
22
23
24
25
26
27
28
29
@dataclass
class RakeBehaviorModel(BaseBehaviorModel):
    """A kind of pricing behavior model in which a set of seat thresholds are used to allocate seats to fares based on the flight occupation.
    These thresholds can be squeezed with respect to the total flight occupation or shifted up from zero occupation.

    Args:
      zero_shift (float): Per-unit relative displacement of all the thresholds
      squeeze (float): Per-unit relative contraction of the all thresholds

    """

    zero_shift: float
    squeeze: float

RakeEBCBehaviorModel dataclass

Bases: RakeStraightBehaviorModel

A kind of pricing behavior model in which a set of seat thresholds are derived from an expected booking curve and a confidence level. Derives from RakeStraightBehavior to have default rakes when there is no input data from which the EBC is built.

Parameters:

NameTypeDescriptionDefault
confidencefloat

Level from which the thresholds slope is derived.

required

Example

behavior = ExpectedBookingCurveThresholds(confidence=0.95, seats_per_dbd=0.15, zero_shift=0.06, squeeze=0.7)

Source code in src/rmlab/data/parametric/pricing_behavior.py
47
48
49
50
51
52
53
54
55
56
57
58
59
@dataclass
class RakeEBCBehaviorModel(RakeStraightBehaviorModel):
    """A kind of pricing behavior model in which a set of seat thresholds are derived from an expected booking curve and a confidence level.
    Derives from RakeStraightBehavior to have default rakes when there is no input data from which the EBC is built.
    Args:
        confidence (float): Level from which the thresholds slope is derived.
    Example
    ```py
    behavior = ExpectedBookingCurveThresholds(confidence=0.95, seats_per_dbd=0.15, zero_shift=0.06, squeeze=0.7)
    ```
    """

    confidence: float

RakeStraightBehaviorModel dataclass

Bases: RakeBehaviorModel

A kind of pricing behavior model in which a set of seat thresholds are used to allocate seats to fares based on the flight occupation. These thresholds are straight, in the sense that the seat limits form a straight line with day before departure.

Parameters:

NameTypeDescriptionDefault
seats_per_dbdfloat

Rate of increase in number of seats per day of all thresholds

required

Example

behavior = RakeStraightBehaviorModel(seats_per_dbd=0.15, zero_shift=0.06, squeeze=0.7)

Source code in src/rmlab/data/parametric/pricing_behavior.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
@dataclass
class RakeStraightBehaviorModel(RakeBehaviorModel):
    """A kind of pricing behavior model in which a set of seat thresholds are used to allocate seats to fares based on the flight occupation.
    These thresholds are straight, in the sense that the seat limits form a straight line with day before departure.

    Args:
      seats_per_dbd (float): Rate of increase in number of seats per day of all thresholds

    Example
    ```py
    behavior = RakeStraightBehaviorModel(seats_per_dbd=0.15, zero_shift=0.06, squeeze=0.7)
    ```
    """

    seats_per_dbd: float

make_pricing_behavior_from_json(filename_or_dict)

Make a pricing behavior instance from a json representation (from file or dict).

Parameters:

NameTypeDescriptionDefault
filename_or_dictUnion[str, dict]

JSON filename or dictionary in json format

required

Examples from dict:

dict_rake_straight_behavior = dic()
dict_rake_straight_behavior["type"] = "rake_straight"
dict_rake_straight_behavior["seats_per_dbd"] = 0.15
dict_rake_straight_behavior["zero_shift"] = 0.06
dict_rake_straight_behavior["squeeze"] = 0.7
my_pricing_rake_straight_behavior = make_from_json(dict_rake_straight_behavior)

Example from file: my_pricing_rake_straight_behavior.json

{
  "type" : "rake_straight",
  "seats_per_dbd" : 0.15,
  "zero_shift" : 0.06,
  "squeeze" : 0.7
}

my_pricing_rake_straight_behavior = make_pricing_behavior_from_json("my_pricing_behavior.json")
Source code in src/rmlab/data/parametric/pricing_behavior.py
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def make_pricing_behavior_from_json(
    filename_or_dict: Union[str, dict]
) -> BaseBehaviorModel:
    """Make a pricing behavior instance from a json representation (from file or dict).

    Args:
        filename_or_dict (Union[str, dict]): JSON filename or dictionary in json format

    Examples from dict:
    ```py
    dict_rake_straight_behavior = dic()
    dict_rake_straight_behavior["type"] = "rake_straight"
    dict_rake_straight_behavior["seats_per_dbd"] = 0.15
    dict_rake_straight_behavior["zero_shift"] = 0.06
    dict_rake_straight_behavior["squeeze"] = 0.7
    my_pricing_rake_straight_behavior = make_from_json(dict_rake_straight_behavior)
    ```

    Example from file:
    `my_pricing_rake_straight_behavior.json`
    ```json
    {
      "type" : "rake_straight",
      "seats_per_dbd" : 0.15,
      "zero_shift" : 0.06,
      "squeeze" : 0.7
    }
    ```

    ```py
    my_pricing_rake_straight_behavior = make_pricing_behavior_from_json("my_pricing_behavior.json")
    ```
    """

    model_id, filename, md5hash, content = parse_data_from_json(filename_or_dict)

    if not isinstance(content, dict):
        raise TypeError(f"Expected dict format in {filename_or_dict}")

    content: dict

    if content["type"] == "rake_straight":

        return RakeStraightBehaviorModel(
            id=model_id,
            filename=filename,
            cnt=json.dumps(content),
            hash=md5hash,
            kind=PricingModelKind.BEHAVIOR,
            extension=FileExtensions.JSON,
            seats_per_dbd=float(content["seats_per_dbd"]),
            zero_shift=float(content["zero_shift"]),
            squeeze=float(content["squeeze"]),
        )

    elif content["type"] == "rake_ebc":

        return RakeEBCBehaviorModel(
            id=model_id,
            filename=filename,
            cnt=json.dumps(content),
            hash=md5hash,
            kind=PricingModelKind.BEHAVIOR,
            extension=FileExtensions.JSON,
            seats_per_dbd=float(content["seats_per_dbd"]),
            confidence=float(content["confidence"]),
            zero_shift=float(content["zero_shift"]),
            squeeze=float(content["squeeze"]),
        )

    else:

        raise ValueError(f'Unknown pricing behavior type `{content["type"]}`')