otp.agg.option_price#

option_price(volatility, interest_rate, compute_model, number_of_steps, compute_delta, compute_gamma, compute_theta, compute_vega, compute_rho, volatility_field_name, interest_rate_field_name, option_type_field_name, strike_price_field_name, days_in_year, days_till_expiration_field_name, expiration_date_field_name, running=False, bucket_interval=0, bucket_time='end', bucket_units='seconds', bucket_end_condition=None, boundary_tick_bucket='new')#

This aggregation requires several parameters to compute the option price. Those are, OPTION_TYPE, STRIKE_PRICE, EXPIRATION_DATE or DAYS_TILL_EXPIRATION, VOLATILITY, and INTEREST_RATE. Each parameter can be specified, either via a symbol parameter with the same name or via a tick field, by specifying the name of that field as an EP parameter, as follows. Besides, VOLATIITY and INTEREST_RATE can also be specified as parameters. In either case, the OPTION_TYPE value must be set to either CALL or PUT. EXPIRATION_DATE is in YYYYMMDD format, a string in case of a symbol parameter and an integer in case of a tick attribute. Additionally, NUMBER_OF_STEPS should be specified in case of Cox-Ross-Rubinstein method.

Parameters
  • volatility (float) – The historical volatility of the asset’s returns.

  • interest_rate (float) – The risk-free interest rate.

  • compute_model (str) – Allowed values are BS and CRR. Choose between Black–Scholes (BS) and Cox-Ross-Rubinstein (CRR) models for computing call/put option price. Default: BS

  • number_of_steps (int) – Specifies the number of time steps between the valuation and expiration dates. This is a mandatory parameter for CRR model.

  • compute_delta (bool) – Specifies whether Delta is to be computed or not. This parameter is used only in case of BS model. Default: False

  • compute_gamma (bool) – Specifies whether Gamma is to be computed or not. This parameter is used only in case of BS model. Default: False

  • compute_theta (bool) – Specifies whether Theta is to be computed or not. This parameter is used only in case of BS model. Default: False

  • compute_vega (bool) – Specifies whether Vega is to be computed or not. This parameter is used only in case of BS model. Default: False

  • compute_rho (bool) – Specifies whether Rho is to be computed or not. This parameter is used only in case of BS model. Default: False

  • volatility_field_name (str) – Specifies name of the field, which carries the historical volatility of the asset’s returns. Default: empty

  • interest_rate_field_name (str) – Specifies name of the field, which carries the risk-free interest rate. Default: empty

  • option_type_field_name (str) – Specifies name of the field, which carries the option type (either CALL or PUT). Default: empty

  • strike_price_field_name (str) – Specifies name of the field, which carries the strike price of the option. Default: empty

  • days_in_year (int) – Specifies number of days in a year (say, 365 or 252 (business days, etc.). Used with DAYS_TILL_EXPIRATION parameter to compute the fractional years till expiration. Default: 365

  • days_till_expiration_field_name (str) – Specifies name of the field, which carries number of days till expiration of the option. Default: empty

  • expiration_date_field_name (str) – Specifies name of the field, which carries the expiration date of the option, in YYYYMMDD format. Default: empty

  • running (bool) –

    Aggregation will be calculated as sliding window. running and bucket_interval parameters determines when new buckets are created.

    • running = True

      aggregation will be calculated in a sliding window.

      • bucket_interval = N (N > 0)

        Window size will be N. Output tick will be generated when tick “enter” window (arrival event) and when “exit” window (exit event)

      • bucket_interval = 0

        Left boundary of window will be bound to start time. For each tick aggregation will be calculated in [start_time; tick_t].

    • running = False

      buckets partition the [query start time, query end time) interval into non-overlapping intervals of size bucket_interval (with the last interval possibly of a smaller size). If bucket_interval is set to 0 a single bucket for the entire interval is created.

      Note that in non-running mode OneTick unconditionally divides the whole time interval into specified number of buckets. It means that you will always get this specified number of ticks in the result, even if you have less ticks in the input data.

    Default: False

  • bucket_interval (int) – Determines the length of each bucket (units depends on bucket_units).

  • bucket_time (Literal['start', 'end']) –

    Control output timestamp.

    • start

      the timestamp assigned to the bucket is the start time of the bucket.

    • end

      the timestamp assigned to the bucket is the end time of the bucket.

  • bucket_units (Literal['seconds', 'ticks', 'days', 'months', 'flexible']) –

    Set bucket interval units.

    If set to flexible then bucket_end_criteria must be set.

    Note that seconds bucket unit doesn’t take into account daylight-saving time of the timezone, so you may not get expected results when using, for example, 24 * 60 * 60 seconds as bucket interval. In such case use days bucket unit instead. See example in onetick.py.agg.sum().

  • bucket_end_condition (condition) – An expression that is evaluated on every tick. If it evaluates to “True”, then a new bucket is created. This parameter is only used if bucket_units is set to “flexible”

  • boundary_tick_bucket (Literal['new', 'previous']) –

    Controls boundary tick ownership.

    • previous

      A tick on which bucket_end_condition evaluates to “true” belongs to the bucket being closed.

    • new

      tick belongs to the new bucket.

    This parameter is only used if bucket_units is set to “flexible”

Note

Currently, this aggregation can be used only with .apply() method.

Examples

Black–Scholes with parameters passed through symbol params and calculated delta:

>>> symbol = otp.Tick(SYMBOL_NAME='SYMB')
>>> symbol['OPTION_TYPE'] = 'CALL'
>>> symbol['STRIKE_PRICE'] = 100.0
>>> symbol['DAYS_TILL_EXPIRATION'] = 30
>>> symbol['VOLATILITY'] = 0.25
>>> symbol['INTEREST_RATE'] = 0.05
>>> data = otp.Ticks(PRICE=[100.7, 101.1, 99.5], symbol=symbol)
>>> data = otp.agg.option_price(compute_delta=True).apply(data)
>>> otp.run(data)['SYMB']
        Time     VALUE    DELTA
0 2003-12-04  2.800999  0.50927
>>> data.schema
{'VALUE': <class 'float'>, 'DELTA': <class 'float'>}

Cox-Ross-Rubinstein with parameters passed through fields:

>>> data = otp.Ticks(
...     PRICE=[100.7, 101.1, 99.5],
...     OPTION_TYPE=['CALL']*3,
...     STRIKE_PRICE=[100.0]*3,
...     DAYS_TILL_EXPIRATION=[30]*3,
...     VOLATILITY=[0.25]*3,
...     INTEREST_RATE=[0.05]*3,
... )
>>> data = otp.agg.option_price(
...     compute_model='CRR',
...     number_of_steps=5,
...     option_type_field_name='OPTION_TYPE',
...     strike_price_field_name='STRIKE_PRICE',
...     days_till_expiration_field_name='DAYS_TILL_EXPIRATION',
...     volatility_field_name='VOLATILITY',
...     interest_rate_field_name='INTEREST_RATE',
... ).apply(data)
>>> otp.run(data)
        Time     VALUE
0 2003-12-04  2.937537

Black–Scholes with some parameters passed through parameters:

>>> data = otp.Ticks(
...     PRICE=[100.7, 101.1, 99.5],
...     OPTION_TYPE=['CALL']*3,
...     STRIKE_PRICE=[100.0]*3,
...     DAYS_TILL_EXPIRATION=[30]*3,
... )
>>> data = otp.agg.option_price(
...     option_type_field_name='OPTION_TYPE',
...     strike_price_field_name='STRIKE_PRICE',
...     days_till_expiration_field_name='DAYS_TILL_EXPIRATION',
...     volatility=0.25,
...     interest_rate=0.05,
... ).apply(data)
>>> otp.run(data)
        Time     VALUE
0 2003-12-04  2.800999

This aggregation can also be used with .agg() method (on the latest OneTick builds).

>>> data = otp.Ticks(
...     PRICE=[100.7, 101.1, 99.5],
...     OPTION_TYPE=['CALL']*3,
...     STRIKE_PRICE=[100.0]*3,
...     DAYS_TILL_EXPIRATION=[30]*3,
... )
>>> data = data.agg({  
...     'RESULT': otp.agg.option_price(
...         option_type_field_name='OPTION_TYPE',
...         strike_price_field_name='STRIKE_PRICE',
...         days_till_expiration_field_name='DAYS_TILL_EXPIRATION',
...         volatility=0.25,
...         interest_rate=0.05,
...     )
... })
>>> otp.run(data) 
        Time    RESULT
0 2003-12-04  2.800999

See also

OPTION_PRICE OneTick event processor