Modules
Top-level package for jax_russell.
CRRBinomialTree
¶
Bases: BinomialTree
Cox Ross Rubinstein binomial tree.
__call__()
is tested against example in Haug.
Source code in jax_russell/trees.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
|
__call__(*args, **kwargs)
¶
Value arrays of options.
By default, __call__
checks its arguments against value()
and passes them through.
Returns:
Type | Description |
---|---|
jnp.array: option values |
Source code in jax_russell/base.py
65 66 67 68 69 70 71 72 73 74 75 |
|
__init__(steps, option_type, discounter=None)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
steps |
int
|
The number of time steps in the binomial tree. |
required |
Source code in jax_russell/trees.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
first_order(*args, **kwargs)
¶
Automatically calculate first-order greeks.
Returns:
Name | Type | Description |
---|---|---|
_type_ |
description |
Source code in jax_russell/base.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
second_order(*args, **kwargs)
¶
Automatically calculate second-order greeks.
Returns:
Name | Type | Description |
---|---|---|
_type_ |
description |
Source code in jax_russell/base.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
solve_implied(expected_option_values, init_params, **kwargs)
¶
Solve for an implied value, usually volatility.
This method allows the flexibility to solve for any combination of values used in the valuation method's __call__()
signature.
For example, passing {"risk_free_rate": jnp.array([0.05]),"volatility":jnp.array([.5])}
will solve for the implied values of both volatility and the risk free rate.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expected_option_values |
array
|
option values, typically observed market prices |
required |
init_params |
dict[array]
|
initial guesses to begin solve optimization |
required |
Returns:
Type | Description |
---|---|
params, state: the parameters and state returned by a |
Source code in jax_russell/base.py
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 135 136 137 138 139 140 141 142 143 144 145 |
|
value(start_price, volatility, time_to_expiration, risk_free_rate, cost_of_carry, is_call, strike)
¶
Calculate values for option contracts.
Returns:
Type | Description |
---|---|
Float[Array, '*#contracts']
|
jnp.array: contract values |
Source code in jax_russell/trees.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
|
ExerciseValuer
¶
Bases: ABC
Abstract class for Callables that implement, or approximate, the max(exercise value, 0) operation.
This is applied in the intermediate steps of a binomial tree.
Source code in jax_russell/trees.py
56 57 58 59 60 61 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 |
|
__call__(underlying_values, strike, is_call)
¶
Calculate or approximate the value of exercising an option.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
underlying_values |
Float[Array, '#contracts n']
|
value of the underlying asset |
required |
strike |
Float[Array, '*#contracts']
|
option strike prices |
required |
is_call |
Float[Array, '*#contracts']
|
whether each option is a call (1.0) or put (0.0) |
required |
Returns:
Type | Description |
---|---|
Float[Array, '*#contracts']
|
jaxtyping.Float[jaxtyping.Array, "*#contracts"]: Exercise values. |
Source code in jax_russell/trees.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 |
|
adjust(unadjusted_values)
abstractmethod
¶
Adjust value difference to calculate an intermediate exercise value.
This method should transform the difference between strike and underlying, i.e. underlying - strike
for calls, strike - underlying
for puts, to an exercise value.
For example, a standard binomial tree uses max(unadjusted_values, 0.0).
Source code in jax_russell/trees.py
96 97 98 99 100 101 102 103 104 105 |
|
MaxValuer
¶
Bases: ExerciseValuer
Implements the standard maximum operation found in intermediate steps in binomial trees.
Source code in jax_russell/trees.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
__call__(underlying_values, strike, is_call)
¶
Calculate or approximate the value of exercising an option.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
underlying_values |
Float[Array, '#contracts n']
|
value of the underlying asset |
required |
strike |
Float[Array, '*#contracts']
|
option strike prices |
required |
is_call |
Float[Array, '*#contracts']
|
whether each option is a call (1.0) or put (0.0) |
required |
Returns:
Type | Description |
---|---|
Float[Array, '*#contracts']
|
jaxtyping.Float[jaxtyping.Array, "*#contracts"]: Exercise values. |
Source code in jax_russell/trees.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 |
|
adjust(unadjusted_values)
¶
Adjust signed strike-underlying differences by applying the max op.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unadjusted_values |
Float[Array, '*']
|
|
required |
Returns:
Type | Description |
---|---|
Float[Array, '*']
|
jaxtyping.Float[jaxtyping.Array, "*"]: element-wise max(unadjusted_values, 0.0) |
Source code in jax_russell/trees.py
111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
SoftplusValuer
¶
Bases: ExerciseValuer
Approximate the maximum operation using a softplus function.
This Callable will return log(1 + exp(kx)) / k
where k is the sharpness parameter.
Source code in jax_russell/trees.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
__call__(underlying_values, strike, is_call)
¶
Calculate or approximate the value of exercising an option.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
underlying_values |
Float[Array, '#contracts n']
|
value of the underlying asset |
required |
strike |
Float[Array, '*#contracts']
|
option strike prices |
required |
is_call |
Float[Array, '*#contracts']
|
whether each option is a call (1.0) or put (0.0) |
required |
Returns:
Type | Description |
---|---|
Float[Array, '*#contracts']
|
jaxtyping.Float[jaxtyping.Array, "*#contracts"]: Exercise values. |
Source code in jax_russell/trees.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 |
|
__init__(sharpness=1.0)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sharpness |
float
|
sharpness parameter k |
1.0
|
Source code in jax_russell/trees.py
132 133 134 135 136 137 138 139 |
|
adjust(unadjusted_values, sharpness=None)
¶
Adjust using the softplus function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unadjusted_values |
Float[Array, '*']
|
jaxtyping.Float[jax.Array, "*"]): |
required |
sharpness |
Union[None, float]
|
If None, uses |
None
|
Returns:
Type | Description |
---|---|
Float[Array, '*']
|
jaxtyping.Float[jaxtyping.Array, "*"]: element-wise softplus |
Source code in jax_russell/trees.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
StockOptionBSM
¶
Bases: StockOptionMixin
, GeneralizedBlackScholesMerten
Stock option Black Scholes Merten valuation.
Source code in jax_russell/__init__.py
40 41 42 43 |
|
StockOptionCRRTree
¶
Bases: StockOptionMixin
, CRRBinomialTree
Stock option CRR tree.
Source code in jax_russell/__init__.py
13 14 15 16 |
|
StockOptionContinuousDividendCRRTree
¶
Bases: StockOptionContinuousDividendMixin
, CRRBinomialTree
Stock option CRR tree with a continuous dividend.
Source code in jax_russell/__init__.py
19 20 21 22 |
|
StockOptionContinuousDividendRBTree
¶
Bases: StockOptionContinuousDividendMixin
, RendlemanBartterBinomialTree
Stock option Rendleman Bartter tree with a continuous dividend.
Source code in jax_russell/__init__.py
31 32 33 34 35 36 37 |
|
StockOptionRBTree
¶
Bases: StockOptionMixin
, RendlemanBartterBinomialTree
Stock option Rendleman Bartter tree.
Source code in jax_russell/__init__.py
25 26 27 28 |
|
ValuationModel
¶
Bases: ABC
Abstract class for valuation methods.
Source code in jax_russell/base.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 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 135 136 137 138 139 140 141 142 143 144 145 |
|
__call__(*args, **kwargs)
¶
Value arrays of options.
By default, __call__
checks its arguments against value()
and passes them through.
Returns:
Type | Description |
---|---|
jnp.array: option values |
Source code in jax_russell/base.py
65 66 67 68 69 70 71 72 73 74 75 |
|
first_order(*args, **kwargs)
¶
Automatically calculate first-order greeks.
Returns:
Name | Type | Description |
---|---|---|
_type_ |
description |
Source code in jax_russell/base.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
second_order(*args, **kwargs)
¶
Automatically calculate second-order greeks.
Returns:
Name | Type | Description |
---|---|---|
_type_ |
description |
Source code in jax_russell/base.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
solve_implied(expected_option_values, init_params, **kwargs)
¶
Solve for an implied value, usually volatility.
This method allows the flexibility to solve for any combination of values used in the valuation method's __call__()
signature.
For example, passing {"risk_free_rate": jnp.array([0.05]),"volatility":jnp.array([.5])}
will solve for the implied values of both volatility and the risk free rate.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expected_option_values |
array
|
option values, typically observed market prices |
required |
init_params |
dict[array]
|
initial guesses to begin solve optimization |
required |
Returns:
Type | Description |
---|---|
params, state: the parameters and state returned by a |
Source code in jax_russell/base.py
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 135 136 137 138 139 140 141 142 143 144 145 |
|
value(start_price, volatility, time_to_expiration, risk_free_rate, cost_of_carry, is_call, strike)
abstractmethod
¶
Calculate the value of an option.
This method is used internally by __call__()
, and should return the value of options.
By default, __call__()
is a pass through to value()
, but many available mixins overwrite this behavior to pass arguments to value()
.
In these cases, this allows the single, general method value()
to implement valuations, while leveraging __call__()
for security-specific argument logic and meaningful autodifferentiation.
Source code in jax_russell/base.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|