---
# System prepended metadata

title: Updated derivations of NFT price ranges using new energy function

---

# Updated derivations of NFT price ranges using new energy function

## Definitions

There exists set $\mathcal{S}$ representing the universe of items. For each item $i\in \mathcal{S}$, there is a vector $x\in \mathbb{R}^n$ such that $x= M(i)$ where $M$ is an attribute map.

Given a set of $m$ items from $\mathcal{S}$ it is possible to apply a clustering method $C:\mathcal{S}^m\rightarrow\mathcal{C}$, (such as Gaussian Mixture) to assign each item $i\in \mathcal{S}^m$ to exactly one cluster $j\in\mathcal{C}$ with a centroid $\bar x_j\in \mathbb{R}^n$; futher more let's set $|\mathcal{C}|=k$ to be the number of clusters. The items in cluster $j$ are denoted $\mathcal{C}_j \subset \mathcal{S}$, satisfying $\mathcal{S}^m = 	\displaystyle{\bigsqcup_{j \in \mathcal{C}} C_j}$.

Now let's suppose we possess such a collection of $m$ items, sorted into into our $k$ clusters. Denote the quantity of items in cluster $j$ to be $q_j =\sum_{i =1}^m \mathbb{1}[i\in C_j]$, satisfying $\sum_{j=1}^k q_j=m$. Imposing a requirement on the method clustering method $C$, we will assume $q_j\ge 1 \forall j$.

Define the positive definite matrix $Q=Diag(q) \in \mathbb{S}_{++}^k \subset \mathbb{R}^{k \times k}$, which is the diagonal of the quantities of items each of the clusers: $Q_{jj}=q_j$ and $Q_{ij}=0$ for all $i\neq j$.

Construct the attribute matrix $X \in \mathbb{R}^{n \times k}$ by collecting the $n$-dimensional column vectors of cluster centroids $X=\left[\begin{array}{c} \cdots|&\bar x_j&|\cdots  \end{array}\right]$.

Combining the attribute matrix $X$ with the quantities of items $Q$ into a quadratic form yields the positive semidefinite matrix

$Z = XQX^T \in \mathbb{S}_+^n\subset \mathbb{R}^{n \times n}$, which has rank $l \leq \min(n,k)$. The Matrix $Z$ has a singular value decomposition $Z = V\Lambda V^T$ where $\Lambda = Diag(\lambda) \in \mathbb{S}_{++}^l \subset\mathbb{R}^{l \times l}$, the diagaonal matrix of eigenvalues, and $V=\left[\begin{array}{c}\cdots|& v_j&|\cdots\end{array}\right]\in\mathbb{R}^{n \times l}$.

It is still possible that $l$ is quite large. In order to allow for further dimensionality reduction, we may select the $p\le l$ largest eigenvalues to for $\hat \Lambda$ and associated eigenvectors $\hat V$ to approximate $Z$ with $\hat Z = \hat V \hat \Lambda\hat V^T$.

### Note on Eigenvalues

It is possible that in a specific case the singular value decomposition of $Z$ results in $\Lambda = Q$. Particularly, it will happen only when the rank of matrix $X$ is $k$. Note that the number of eigenvalues ($\lambda$) expected from the singular value decomposition of $Z$ is equal to its rank and $rank(Z) = rank(X)$. In order for $X$ to have rank $k$, we must have $k = min(n,k)$ meaning that the number of clusters ($k$) needs to be at most equal to the number of features ($n$). Additionally, all the centroids of the clusters need to be linearly independent from each other. 

However, in reality, it is expected that the number of clusters ($k$) are greater than the dimension of the feature space ($n$) which results in $n = min(n,k)$ and subsequently $rank(X) \leq n$.

With this in mind, $rank(X) = n$ is only possible if the features are linearly independent, otherwise $rank(X) < n$. In any of these two cases, the number of eigenvalues expected from the singular value decomposition is going to be less than the number of clusters, and therefore, $\Lambda \not = Q$.

## Energy function

Let's suppose our market contains a quantity of a reserve currency $r$, in addition to quantities of items $q_j>0$ of items in clusters $\mathcal{C}_j$ with attribute vectors $\bar x_j$. We define the energy function for this market as

$$ \Psi(r,q;X) = r \bigg[ \prod_{j=1}^{k}{\lambda_j(XQX^{T})} \bigg] $$


## Buy algorithm 

For a buy scenario that our market maker pays $\Delta r$ to add $\Delta q$ items into its inventory, the transaction must increase its energy. Therefore, having $r - \Delta r$ as the new currency reserve and $Q + \Delta q$ as the new diagonal quantity matrix, we have


\begin{aligned}
 \Psi(r-\Delta r, q+\Delta q; X) &> \Psi(r, q; X) \\
 (r-\Delta r) \bigg[ \prod_{j=1}^{k}{\lambda_j\big(X(Q+\Delta q)X^{T}\big)} \bigg] &> r \bigg[ \prod_{j=1}^{k}{\lambda_j(XQX^{T})} \bigg] \\
 1- \frac{\Delta r}{r}  &> \frac{ \prod_{j=1}^{k}{\lambda_j(XQX^{T})} }{\prod_{j=1}^{k}{\lambda_j\big(X(Q+\Delta q)X^{T}\big)} }\\
 1- \frac{ \prod_{j=1}^{k}{\lambda_j(XQX^{T})} }{\prod_{j=1}^{k}{\lambda_j\big(X(Q+\Delta q)X^{T}\big)} }  &> \frac{\Delta r}{r}\\
 \Delta r &< r \bigg[1- \frac{\prod_{j=1}^{k} \lambda_j(XQX^T) }{\prod_{j=1}^{k} \lambda_j(X(Q +\Delta q) X^T)}\bigg].
\end{aligned}


Therefore, in order to add $\Delta q$ items into its inventory, ARMM will pay a maximum amount of $r \bigg[1-  \frac{\prod_{j=1}^{k} \lambda_j(XQX^T) }{\prod_{j=1}^{k} \lambda_j(X(Q +\Delta q) X^T)}\bigg]$

## Sell algorithm 

For a sell scenario that our market maker receives $\Delta r$ to remove $\Delta q$ items from its inventory, the transaction must increase its energy. Therefore, having $r + \Delta r$ as the new currency reserve and $Q - \Delta q$ as the new diagonal quantity matrix, we have


\begin{aligned}
 \Psi(r+\Delta r, q-\Delta q; X) &> \Psi(r, q; X) \\
 (r+\Delta r) \bigg[ \prod_{j=1}^{k}{\lambda_j\big(X(Q-\Delta q)X^{T}\big)} \bigg] &> r \bigg[ \prod_{j=1}^{k}{\lambda_j(XQX^{T})} \bigg] \\
 1+ \frac{\Delta r}{r}  &> \frac{ \prod_{j=1}^{k}{\lambda_j(XQX^{T})} }{\prod_{j=1}^{k}{\lambda_j\big(X(Q-\Delta q)X^{T}\big)} }\\
 \frac{\Delta r}{r} &> \frac{ \prod_{j=1}^{k}{\lambda_j(XQX^{T})} }{\prod_{j=1}^{k}{\lambda_j\big(X(Q-\Delta q)X^{T}\big)} } - 1 \\
 \Delta r &> r\bigg[\frac{\prod_{j=1}^{k} \lambda_j(XQX^T) }{\prod_{j=1}^{k} \lambda_j(X(Q -\Delta q) X^T)} - 1\bigg].
\end{aligned}

$$ \Delta r > r\bigg[\sqrt[k]{\frac{\prod_{j=1}^{k} \lambda_j(XQX^T) }{\prod_{j=1}^{k} \lambda_j(X(Q -\Delta q) X^T)}} - 1\bigg]$$

Therefore, in order to sell $\Delta q$ items from its inventory, ARMM will receive a minimum amount of $r\bigg[\frac{\prod_{j=1}^{k} \lambda_j(XQX^T) }{\prod_{j=1}^{k} \lambda_j(X(Q -\Delta q) X^T)} - 1\bigg]$

# ARMM as Price recommender

Considering that, in order to increase its energy function, ARMM will buy low at a max price of $r \bigg[1- \frac{\prod_{j=1}^{k} \lambda_j(XQX^T) }{\prod_{j=1}^{k} \lambda_j(X(Q +\Delta q) X^T)}\bigg]$ and sell high at a min price of $r\bigg[\frac{\prod_{j=1}^{k} \lambda_j(XQX^T) }{\prod_{j=1}^{k} \lambda_j(X(Q -\Delta q) X^T)} - 1\bigg]$, these prices can also be used as our recommendations.

In other words, if ARMM is to be used as a price recommender,  the *minimum* recommended price is the maximum price that ARMM is willing to buy the item, and the *maximum* recomended price is the minimum price that ARMM is willing to sell the item.

# Recommended price assessment metric
How do we assess the quality of ARMM's recommended price?

A user queries the price of the NFTs that they want to sell/buy by posting the attributes of NFTs. Depending on whether an order exists matching the attributes or not, there will be two cases:
- ## Case 1:
    Query returns no existing order based on the attributes. Therefore, they are opening a new buy/sell order that doesn't have a complement on the books so ARMM needs to recommend a price to them. ARMM recommendation for item $i$ will be a range as $[\hat{p}_{i,min}, \hat{p}_{i,max}]$ where $\hat{p}_{i,min}$ and $\hat{p}_{i,max}$ are the minimum and the maximum recommended price, respectively.
    - Case 1a: the user creates an order with the price $p_{i}$ where $\hat{p}_{i,min} \leq p_{i} \leq \hat{p}_{i,max}$. This reflects that the user found the ARMM's recommended price acceptable, and therefore, we consider no penalty for this case.
        - in this case the $\Delta p_{i} =0$
    - Case 1b: the user deviates from the recommendation from the ARMM by some amount and places the order with price $p_{i} < \hat{p}_{i,min}$. This reflects that the user found the ARMM's recommended price more than the value of the NFT, and therefore, we consider a penalty for this case.
        - in this case the $\Delta p_{i} = \hat{p}_{i,min} - p_{i}$, and since $p_{i} < \hat{p}_{i,min}$, $\Delta p_{i} > 0$.
        - with this definition, $\Delta p_{i} > 0$ means that the recommended price was higher than the user's valuation for the NFT. 
    - Case 1c: the user deviates from the recommendation from the ARMM by some amount and places the order with price $p_{i} > \hat{p}_{i,max}$. This reflects that the user found the ARMM's recommended price less than the value of the NFT, and therefore, we consider a penalty for this case.
        - in this case the $\Delta p_{i} = \hat{p}_{i,max} - p_{i}$, and since $p_{i} > \hat{p}_{i,max}$, $\Delta p_{i} < 0$.
        - with this definition, $\Delta p_{i} < 0$ means that the recommended price was less than the user's valuation for the NFT.
    - Case 1d: the user chooses not to place an order at all. This case does not provide clear information over the user's valuation, and therefore, we consider no penalty for this case.
        - in this case the $\Delta p_{i} =0$
        
    As summary, having $[\hat{p}_{i,min}, \hat{p}_{i,max}]$ as the ARMM's recommended range, and $p_{i}$ as the price decided by the user, we define penalty as
        $$ \Delta p_{i} = \begin{cases} \hat{p}_{i,min} - p_{i} & p_{i} < \hat{p}_{i,min}\\
        \hat{p}_{i,max} - p_{i} & p_{i} > \hat{p}_{i,max}\\
        0 & otherwise
        \end{cases}$$
    and models can be compared in different ways such as
    1. RMSE = $\sqrt{\frac{\sum_{i=1}^{N} (\Delta p_i)^2}{N}}$
    2. MSE = $\frac{\sum_{i=1}^{N} (\Delta p_i)^2}{N}$
    3. MAE = $\frac{\sum_{i=1}^{N} |\Delta p_i|}{N}$

    Another set of metrics can be defined based on the number of out of recommended range orders.
    
    \begin{aligned} \text{Ratio of successful recommendations} &= \frac{\sum_{i=1}^{N} I(\hat{p}_{i,min} \leq p_{i} \leq \hat{p}_{i,max})}{N}\\
    \text{Ratio of failed recommendations} &= 1- \frac{\sum_{i=1}^{N} I(\hat{p}_{i,min} \leq p_{i} \leq \hat{p}_{i,max})}{N}\\
    \text{Ratio of overvalued recommendations} &= \frac{\sum_{i=1}^{N} I( p_{i} \leq \hat{p}_{i,min})}{N}\\
    \text{Number of undervalued recommendations} &= \frac{\sum_{i=1}^{N} I( \hat{p}_{i,max} \leq p_{i} )}{N}
    \end{aligned}
    
- ## Case 1 buyer/seller differentiated

    In the previous formulation, the price recommendation did not differentiate wether the price was for seller or buyer. To include this in the equations, we define ARMM recommendation for buying item $i$ as the range $[\hat{p}_{i,min}^b, \hat{p}_{i,max}^b]$ where $\hat{p}_{i,min}^b$ and $\hat{p}_{i,max}^b$ are the minimum and the maximum recommended price to buy item $i$, respectively. Similarly, we define ARMM recommendation for selling item $i$ as the range $[\hat{p}_{i,min}^s, \hat{p}_{i,max}^s]$ where $\hat{p}_{i,min}^s$ and $\hat{p}_{i,max}^s$ are the minimum and the maximum recommended price to buy item $i$, respectively.
    
    With this definitions, the same equations from Case 1 can be used to measure the price recommended for buy and sell seperately. Consider the following as the example for measuring the performance of buy recommended prices:
    
    having $[\hat{p}_{i,min}^b, \hat{p}_{i,max}^b]$ as the ARMM's recommended range, and $p_{i}^b$ as the price decided by the user, we define penalty as
        $$ \Delta p_{i}^b = \begin{cases} \hat{p}_{i,min}^b - p_{i}^b & p_{i}^b < \hat{p}_{i,min}^b\\
        \hat{p}_{i,max}^b - p_{i}^b & p_{i}^b > \hat{p}_{i,max}^b\\
        0 & otherwise
        \end{cases}$$
    and models can be compared in different ways such as
    1. RMSE = $\sqrt{\frac{\sum_{i=1}^{N^b} (\Delta p_i^b)^2}{N^b}}$
    2. MSE = $\frac{\sum_{i=1}^{N^b} (\Delta p_i^b)^2}{N^b}$
    3. MAE = $\frac{\sum_{i=1}^{N^b} |\Delta p_i^b|}{N^b}$
    
    where $N^b$ is the number of all the buy orders.

- ## Case 2:
    there are complementing orders that satisfy the user's query. In such case, users are closing out an existing buy/sell order, in which case they will be quoted prices based on the complementing orders. Depending on whether the existing order was following the price recommendation, we define ''accepatble'' and ''unaccepable''.  
    **Note:** as the pricing in this case is based on the existing orders, the metrics defined can be used for evaluating the performance of liquidity providing system rather than the pricing.
    - Case 2a - acceptable: The ''acceptable'' refers to the case that the existing order found the price recommendation reasonable and set the price in the recommended range. There are two potential outcomes:
        - Case 2a.1: the order is eventually cleared which tells us that it had an adequate price. This outcome indicates that both buyer and seller found the price acceptable.
        - Case 2a.2: the order sits there forever and/or eventual timesout or gets removed. This outcome indicates that pricing was only acceptable to the creator of the order. 
    
    - Case 2b - unacceptable: The ''unacceptable'' refers to the case that the existing order found the price recommendation unreasonable and set the price out of the recommended range.  There are two potential outcomes:
        - Case 2b.1: the order is eventually cleared which tells us that the market has a different valuation compared to the price recommendation system.
        - Case 2b.2: the order sits there forever and/or eventual timesout or gets removed. This outcome indicates that the market behaved as the price recommender system expected.
    
        
        
    As summary, having $N$ as the set of orders:
    
    \begin{aligned}
    &\text{Number of closed "acceptable" pricings} = &&\sum_{i=1}^{N} I(\text{Order $i$ followed recommended price and cleared})\\
    &\text{Number of expired "acceptable" pricings} = &&\sum_{i=1}^{N} I(\text{Order $i$ followed recommended price but timed out})\\
    &\text{Number of closed "unacceptable" pricings} = &&\sum_{i=1}^{N} I(\text{Order $i$ did NOT followed recommended price and cleared})\\
    &\text{Number of expired "unacceptable" pricings} = &&\sum_{i=1}^{N} I(\text{Order $i$ did NOT followed recommended price and timed out})
    \end{aligned}
    
    and models can be compared in different ways such as but not limited to
    1. Ratio of closed "acceptable" pricings = $\frac{\text{Number of closed "acceptable" pricings}}{\text{Total number of orders}}$
    2. Ratio of closed "unacceptable" pricings = $\frac{\text{Number of closed "unacceptable" pricings}}{\text{Total number of orders}}$
    