# Intervention v 1.0
## Initial Parameters and Definitions
| Parameter | Value | Description |
|---------------------------|----------------|-----------------------|
| $ER$ | Get by Request | NEAR/USDT exchange rates |
| $U$ | Get by Request | USDT part of USN Reserve in \$ |
| $N$ | Get by Request | NEAR part of USN Reserve in NEAR |
| $Q$ | Get by Request | Total Volume of issued USN |
| $m$ | 4 | is an even number indicating how highly we value being as close as possible to |
| $N_{dn}$ | 0.25 | is the critical lowest level of USN backing by NEAR |
| $U_{up}$ | 1.1 | the upper limit to USDT backing of USN that we consider at the SELL action | |
| $U_{dn}$ | 1 | the upper limit to USDT backing of USN that we consider at the BUY action. | |
| $P_{dn}$ | 0.6 | the lower ratio of USDT part of the Reserve Fund to the total value of the Reserve Fund |
| $P_{up}$ | 0.7 | the upper ratio of USDT part of the Reserve Fund to the total value of the Reserve Fund |
| $T_{buymin}$ | 1000 | minimal absolute buy transaction amounts in USDT terms |
| $T_{sellmin}$ | 1000 | minimal absolute sell transaction amounts in USDT terms |
| $T_{buystep}$ | 3’000’000 | maximal atomic absolute buy transaction amounts in USDT terms |
| $T_{sellstep}$ | 3’000’000 | maximal atomic absolute buy transaction amounts in USDT terms |
| $t_0$ | 0 | the relative time step of our observations |
| $t_{step}$ | 5 | the minimal distance between interventions (mins) |
# Intervention Strategy
Generally, the interventions’ strategy can be represented as Buy/Sell operations, which are performed based on the following conditions (see the table below), when Ylow - the lowest boundary of USDT in the Reserve Fund that meets the balance conditions, Yhigh - the highest boundary of USDT in the Reserve Fund that meets the balance conditions.
| |Yt-Ylow <0| Yt-Yhigh>0 |(Ylow-Yt)(Yt-Yhigh)<0 | Ft-XdnQt-Yt<0|
| ---- | --- | --- | --- | ----|
|C < 0 |Buy Y | Do nothing | Do nothing | Sell Y|
|C > 0 |Do nothing| Sell Y | Do nothing | Sell Y|
|C = 0 |Do nothing| Do nothing | Do nothing | Sell Y|
---
# Algorithm Steps
1. At time $t$ collect 8 historical NEAR/USDT exchange rates from PriceOracle (ER)
| | $ts_7$ | $ts_6$ | $ts_5$ | $ts_4$ | $ts_3$ | $ts_2$| $ts_1$| $ts_0$ |
| --- | ---- | ---- | ---- | ---- | --- | --- | --- | ----|
| ER | $V_1$ |$V_2$|$V_3$|$V_4$ |$V_5$|$V_6$|$V_7$ | $V_8$|
2. Set
$$N_{ER} = ER[ts0] = V_8$$
4. Calculate relative coordinates:
$$Tk = (tsk−8 − ts0)/tstep, k = 1, 8$$
4. Make the data smoothing with moving average:
$$TS_{k−1} = (T_{k−1} + T_k + T_{k+1})/3 | k = 2, 7$$
$$VS_{k−1} = (V_{k−1} + V_k + V_{k+1})/3 | k = 2, 7$$
Result is represented in the table:
| 0 | 1 | 2 | 2 | 3 | 4 | 5 |
| --- | --- | --- | --- | --- | --- | --- |
| X | $TS_1$ |$TS_2$ | $TS_3$ | $TS_3$ |$TS_4$| $TS_5$ |
| Y |$V$ | $S_1$ | $V$ |$S_2$ | $V$ | $S_2$ |
5. Fit a quadratic trend into the 6 NEAR/USDT smoothed exchange rate values collected using OLS:
a) Define Independent Variables:
$$Z_1 = X_2$$
$$Z_2 = X$$
b) Define Products:
$$Z_1Y = Z_1 * Y$$
$$Z_2Y = Z_2 * Y$$
$$Z_1Z_2 = Z_1 * Z2$$
c) Define the Aggregated Variables:
$$Z_1\_mean = \sum(Z_1)/len(Z_1)$$
$$Z_2\_mean = \sum(Z_2)/len(Z_2)$$
$$Y\_mean = \sum(Y )/len(Y )$$
$$Z_1Y\_mean = \sum(Z_1Y )/len(Z_1Y )$$
$$Z_2Y \_mean = \sum(Z_2Y )/len(Z_2Y )$$
$$Z_1Z_2\_mean = \sum(Z_1Z_2)/len(Z_1Z_2)$$
$$Z_1\_std =\sum\sqrt{(\sum(Z\begin{matrix}2\\1\end{matrix} )/len(Z_1) − (Z_1\_mean)^2)}$$
$$Z_1\_std =\sum\sqrt{(\sum(Z\begin{matrix}2\\2\end{matrix} )/len(Z_2) − (Z_2\_mean)^2)}$$
$$Y_std =\sqrt{(\sum(Y^2)/len(Y) − (Y\_mean)^2)}$$
d) Calculate Correlations:
$$rZ_1Y = (Z_1Y\_mean − Z_1\_mean · Y\_mean)/(Z_1\_std · Y\_std)$$
$$rZ_2Y = (Z_2Y\_mean − Z_2\_mean · Y\_mean)/(Z_2\_std · Y\_std)$$
$$rZ_1Z_2 = (Z_1Z_2\_mean − Z_1\_mean · Z_2\_mean)/(Z_1\_std · Z_2\_std)$$
e) Calculate Coefficients:
$$a = (rZ_1Y − rZ_2Y · rZ_1Z_2)/(1 − (rZ_1Z_2)^2) · (Y_\_std/Z_1\_std)$$
$$b = (rZ2Y − rZ1Y · rZ1Z2)/(1 − (rZ1Z2)^2) · (Y _std/Z2_std)$$
$$c = Y\_mean − a · Z_1\_mean − b · Z_2\_mean$$
f) Calculate $R^2$ :
$$ER\_mean = \sum V_k/len(ER)$$
$$S\_tot = \sum(V_k − ER\_mean)^2$$
$$S\_res = \sum(V_k − (a · T\begin{matrix}2\\k\end{matrix} + b · Tk + c))^2$$
$$R_2 = 1 − S\_res/S\_tot$$
6. Get coefficients $a, b$ and $R^2$ for this trend
7. Calculate coefficient $C$:
$$C = sign(a) · R^2/
(t_0 + \frac{b}{2a})^m + 1$$
8. IF $(N_{dn} · Q − N_{ER} · N) ≥ 0:$
a) Sell amount as
$$A_{sell}=\biggl\{ \begin{matrix}R_{sell}, R_{sell} ≥ T_{sellmin}\\
0, R_{sell} < T_{sellmin}
\end{matrix} , where R_{sell} = min ((N_{dn} · Q − NER · N), T_{sellstep}, U)$$
b) SELL USDT in the amount of $A_{sell}$
9. IF $((N_{dn} · Q − N_{ER} · N) < 0)\&(C>0)$:
a) Sell amount as
$$A_{sell}=\biggl\{ \begin{matrix}R_{sell}, R_{sell} ≥ T_{sellmin}\\
0, R_{sell} < T_{sellmin}
\end{matrix} , where R_{sell} = min (U_{sell}, T_{sellstep}, U)$$
$$Usell = max (C · (U − min (P_{up} · (U + N_{ER} · N),U_{up} · Q) , 0)$$
(b) SELL USDT in the amount of $A_{sell}$
10. IF $((Ndn · Q − NER · N) < 0) \& (C < 0):$
(a) Buy amount as
$$A_{buy}=\biggl\{ \begin{matrix}R_{buy}, R_{buy} ≥ T_{buymin}\\
0, R_{buy} < T_{buymin}
\end{matrix} , where R_{buy} = min (U_{buy}, T_{buystep}, N_{ER}·N)$$
$$U_{buy} = C · min(U − min(P_{dn} · (U + N_{ER} · N),U_{dn} · Q), 0)$$
(b) BUY USDT in the amount of $A_{buy}$