qdpmc.tools.payoffs.Payoff

class qdpmc.tools.payoffs.Payoff(func, *args, **keywords)[source]

Bases: object

A class that allows payoff functions to be added, negated, and scalar-multiplied.

The first argument func must be callable, and the first argument of it must be the array of underlying asset prices. args and keywords contain arguments other than the price array of func. Calls to a Payoff object will be forwarded to func with the price array. Make sure that all other necessary arguments are specified, or an error will be raised.

Examples

Here are some examples.

In [1]: def my_payoff_func(asset_price, param1, param2):
   ...:     return param1 * np.array(asset_price) + param2
   ...: 

In [2]: my_payoff = qm.Payoff(
   ...:     func=my_payoff_func,
   ...:     param1 = 3.0,
   ...:     param2 = 2.0
   ...: )
   ...: 

In [3]: my_payoff([1, 2, 3, 4, 5])
Out[3]: array([ 5.,  8., 11., 14., 17.])

In [4]: -my_payoff([1, 2, 3, 4, 5])
Out[4]: array([ -5.,  -8., -11., -14., -17.])

In [5]: payoff25 = 2.5 * my_payoff

In [6]: payoff25([1, 2, 3, 4, 5])
Out[6]: array([12.5, 20. , 27.5, 35. , 42.5])

The user function should implement vectorization whenever possible to achieve maximum speed of computation.

Methods

__init__(func, *args, **keywords)

to_log(spot)

Convert the payoff function to log.

to_log(spot)[source]

Convert the payoff function to log.