> For the complete documentation index, see [llms.txt](https://pietro-zanottas-organization.gitbook.io/dbb/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pietro-zanottas-organization.gitbook.io/dbb/api-reference/performoptimization.md).

# performOptimization

Function retrieving a martingale distribution Q and a physical distribution P s.t.

* Q prices financial instrument correctly
* The second moment of the pricing kernel by the bound $$\alpha$$
* The risk-neutral variance is higher than the physical expected variance

{% tabs %}
{% tab title="dbbpy" %}

```python
dbbpy.performOptimization(n, alpha, lambda_, omega_l, sp, strike, bid, ask, pFlag)
```

Parameters:

* `n` (int): The number of states considered
* `alpha` (float): A parameter limiting the second moment of the pricing kernel
* `lambda` (float): A parameter for the Tikhonov-type regularization
* `omega_l` (numpy.ndarray): A 1D numpy array of integers representing the disjunct state space partitions of interest
* `sp` (numpy.ndarray): A 1D numpy array of floats representing the spot prices in different states of the world
* `strike` (numpy.ndarray): A 1D numpy array of floats representing the strike prices of different options
* `bid` (numpy.ndarray): A 1D numpy array of floats representing the bid prices of different options
* `ask` (numpy.ndarray): A 1D numpy array of floats representing the ask prices of different options
* `pflag` (numpy.ndarray): A 1D numpy array of booleans indicating whether an option is a call (`True`) or a put (`False`) option

Output:

* (tuple): includes two elements:
  * P distribution: The recovered P distribution
  * Q distribution: The recovered Q distribution
    {% endtab %}

{% tab title="rdbb" %}

```
rdbb::performOptimization(n, alpha, lambda, omega_l, sp, strike, bid, ask, pFlag)
```

Parameters:

* `n` (int): The number of states considered
* `alpha` (float): A parameter limiting the second moment of the pricing kernel
* `lambda` (float): A parameter for the Tikhonov-type regularization
* `omega_l` (numeric vector): Includes the disjunct state space partitions of interest
* `sp` (numeric vector): Represents the spot prices in 4 different states of the world
* `strike` (numeric vector): Represents the strike prices of different options
* `bid` (numeric vector): Represents the bid prices of different options
* `ask` (numeric vector): Represents the ask prices of different options
* `pFlag` (logical vector): Indicates whether an option is a call (TRUE) or a put (FALSE) option

Output:

* (list): Includes two elements:
  * P distribution: The recovered P distribution
  * Q distribution: The recovered Q distribution
    {% endtab %}
    {% endtabs %}
