> 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/getting-started/example-1.md).

# Example 1

This example performs the optimization described in the <mark style="color:orange;">paper</mark> to obtain the physical distribution P and the martingale distributions Q, where:

* `n` is the number of states considered
* `alpha` is a parameter limiting the second moment of the pricing kernel
* `lambda` is a parameter for the Tikhonov-type regularization
* `omega_l` includes the disjunct state space partitions of interest
* `sp` represents the spot prices in 4 different states of the world
* `strike` represents the strike prices of different options
* `bid` represents the bid prices of different options
* `ask` represents the ask prices of different options
* `pflag` indicates whether an option si a call or a put option
* `result` includes two elements: the P distribution and the Q distribution

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

```
import dbbpy
import numpy as np 

n = 4 
alpha = 1.3
lambda_ = 1.1
omega_l = np.array([0, 3])
sp = np.array([1200, 1250, 1300, 1350])
strike = np.array([1290, 1295, 1295, 1300])
bid = np.array([27.7, 27.4, 29.4, 25.0])
ask = np.array([29.3, 29.7, 31.4, 26.9])
pFlag = np.array([1,0,1,0])

result = dbbpy.performOptimization(n, alpha, lambda_, omega_l, sp, strike, bid, ask, pFlag)
p = result[0]
q = result[1]

print(p)
print(q)
```

{% endtab %}

{% tab title="rdbb" %}

```
library(rdbb)

n <- 4
alpha <- 1.3
lambda <- 1.1
omega_l <- c(0, 3) # zero-indexed
sp <- c(1200, 1250, 1300, 1350)
strike <- c(1290, 1295, 1295, 1300)
bid <- c(27.7, 27.4, 29.4, 25.0)
ask <- c(29.3, 29.7, 31.4, 26.9)
pFlag <- c(TRUE, FALSE, TRUE, FALSE)

result <- performOptimization(n, alpha, lambda, omega_l, sp, strike, bid, ask, pFlag)
p <- result[[1]]
q <- result[[2]]
  
print(p)
print(q)

```

{% endtab %}
{% endtabs %}
