code.vegaprotocol.io/vega@v0.79.0/core/integration/features/position_tracking/verified-positions-resolution-5-lognormal.feature (about)

     1  Feature: Position resolution case 5 lognormal risk model
     2  
     3    Background:
     4      Given the log normal risk model named "lognormal-risk-model-fish":
     5        | risk aversion | tau  | mu | r   | sigma |
     6        | 0.001         | 0.01 | 0  | 0.0 | 1.2   |
     7      #calculated risk factor long: 0.336895684; risk factor short: 0.4878731
     8  
     9      And the price monitoring named "price-monitoring-1":
    10        | horizon | probability | auction extension |
    11        | 1       | 0.99999999  | 300               |
    12  
    13      And the margin calculator named "margin-calculator-1":
    14        | search factor | initial factor | release factor |
    15        | 1.2           | 1.5            | 2              |
    16  
    17      And the markets:
    18        | id        | quote name | asset | risk model                | margin calculator   | auction duration | fees         | price monitoring | data source config     | linear slippage factor | quadratic slippage factor | sla params      |
    19        | ETH/DEC19 | ETH        | USD   | lognormal-risk-model-fish | margin-calculator-1 | 1                | default-none | default-none     | default-eth-for-future | 1e-3                   | 1e-3                      | default-futures |
    20  
    21      And the following network parameters are set:
    22        | name                                    | value |
    23        | market.auction.minimumDuration          | 1     |
    24        | network.markPriceUpdateMaximumFrequency | 0s    |
    25        | limits.markets.maxPeggedOrders          | 2     |
    26  
    27    @MTMDelta
    28    Scenario: using lognormal risk model, set "designatedLoser " closeout while the position of "designatedLoser " is not fully covered by orders on the order book (0007-POSN-013)
    29  
    30      # setup accounts
    31      Given the parties deposit on asset's general account the following amount:
    32        | party            | asset | amount        |
    33        | sellSideProvider | USD   | 1000000000000 |
    34        | buySideProvider  | USD   | 1000000000000 |
    35        | designatedLoser  | USD   | 21981         |
    36        | aux              | USD   | 1000000000000 |
    37        | aux2             | USD   | 1000000000000 |
    38        | lpprov           | USD   | 1000000000000 |
    39  
    40      When the parties submit the following liquidity provision:
    41        | id  | party  | market id | commitment amount | fee | lp type    |
    42        | lp1 | lpprov | ETH/DEC19 | 9000              | 0.1 | submission |
    43        | lp1 | lpprov | ETH/DEC19 | 9000              | 0.1 | amendment  |
    44      And the parties place the following pegged iceberg orders:
    45        | party  | market id | peak size | minimum visible size | side | pegged reference | volume | offset |
    46        | lpprov | ETH/DEC19 | 225       | 18                   | buy  | BID              | 225    | 100    |
    47        | lpprov | ETH/DEC19 | 36        | 18                   | sell | ASK              | 36     | 100    |
    48  
    49      Then the parties should have the following account balances:
    50        | party  | asset | market id | margin | general      | bond |
    51        | lpprov | USD   | ETH/DEC19 | 0      | 999999991000 | 9000 |
    52  
    53      # place auxiliary orders so we always have best bid and best offer as to not trigger the liquidity auction
    54      Then the parties place the following orders:
    55        | party | market id | side | volume | price | resulting trades | type       | tif     |
    56        | aux   | ETH/DEC19 | buy  | 10     | 1     | 0                | TYPE_LIMIT | TIF_GTC |
    57        | aux   | ETH/DEC19 | sell | 10     | 2000  | 0                | TYPE_LIMIT | TIF_GTC |
    58        | aux   | ETH/DEC19 | buy  | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
    59        | aux2  | ETH/DEC19 | sell | 1      | 150   | 0                | TYPE_LIMIT | TIF_GTC |
    60      Then the opening auction period ends for market "ETH/DEC19"
    61      And the mark price should be "150" for the market "ETH/DEC19"
    62      And the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC19"
    63  
    64      # insurance pool generation - setup orderbook
    65      When the parties place the following orders with ticks:
    66        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference       |
    67        | sellSideProvider | ETH/DEC19 | sell | 290    | 150   | 0                | TYPE_LIMIT | TIF_GTC | sell-provider-1 |
    68        | buySideProvider  | ETH/DEC19 | buy  | 1      | 140   | 0                | TYPE_LIMIT | TIF_GTC | buy-provider-1  |
    69  
    70      Then the order book should have the following volumes for market "ETH/DEC19":
    71        | side | price | volume |
    72        | buy  | 1     | 10     |
    73        | buy  | 40    | 225    |
    74        | sell | 250   | 36     |
    75        | sell | 2000  | 10     |
    76  
    77  
    78      # insurance pool generation - trade
    79      When the parties place the following orders with ticks:
    80        | party           | market id | side | volume | price | resulting trades | type       | tif     | reference |
    81        | designatedLoser | ETH/DEC19 | buy  | 290    | 150   | 1                | TYPE_LIMIT | TIF_GTC | ref-1     |
    82  
    83      Then the order book should have the following volumes for market "ETH/DEC19":
    84        | side | price | volume |
    85        | sell | 2100  | 36     |
    86        | sell | 2000  | 10     |
    87        | buy  | 40    | 0      |
    88        | buy  | 1     | 0      |
    89  
    90      Then the parties should have the following account balances:
    91        | party           | asset | market id | margin | general |
    92        | designatedLoser | USD   | ETH/DEC19 | 0      | 0       |
    93  
    94      Then the parties should have the following profit and loss:
    95        | party           | volume | unrealised pnl | realised pnl |
    96        | designatedLoser | 0      | 0              | -17631       |
    97  
    98      Then the parties place the following orders:
    99        | party  | market id | side | volume | price | resulting trades | type       | tif     |
   100        | lpprov | ETH/DEC19 | buy  | 1000   | 1     | 0                | TYPE_LIMIT | TIF_GTC |
   101  
   102      When the parties place the following orders with ticks:
   103        | party            | market id | side | volume | price | resulting trades | type       | tif     | reference |
   104        | sellSideProvider | ETH/DEC19 | sell | 1      | 140   | 0                | TYPE_LIMIT | TIF_GTC | ref-3     |
   105        | buySideProvider  | ETH/DEC19 | buy  | 1      | 140   | 1                | TYPE_LIMIT | TIF_GTC | ref-4     |
   106      And the network moves ahead "1" blocks
   107  
   108      Then the mark price should be "140" for the market "ETH/DEC19"
   109  
   110      And the parties should have the following account balances:
   111        | party           | asset | market id | margin | general |
   112        | designatedLoser | USD   | ETH/DEC19 | 0      | 0       |
   113  
   114      Then the parties should have the following profit and loss:
   115        | party           | volume | unrealised pnl | realised pnl |
   116        | designatedLoser | 0      | 0              | -17631       |
   117  
   118      #And debug transfers
   119      # then we make sure the insurance pool collected the funds (however they get later spent on MTM payment to closeout-facilitating party)
   120      Then the following transfers should happen:
   121        | from            | to              | from account            | to account                       | market id | amount | asset |
   122        | designatedLoser | market          | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC19 | 0      | USD   |
   123        | buySideProvider | market          | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_MAKER          | ETH/DEC19 | 0      | USD   |
   124        | buySideProvider | market          | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_LIQUIDITY      | ETH/DEC19 | 14     | USD   |
   125        | designatedLoser |                 | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_FEES_INFRASTRUCTURE | ETH/DEC19 | 0      | USD   |
   126        | market          | lpprov          | ACCOUNT_TYPE_FEES_MAKER | ACCOUNT_TYPE_GENERAL             | ETH/DEC19 | 0      | USD   |
   127        | designatedLoser | market          | ACCOUNT_TYPE_MARGIN     | ACCOUNT_TYPE_INSURANCE           | ETH/DEC19 | 17631  | USD   |
   128        | market          | market          | ACCOUNT_TYPE_INSURANCE  | ACCOUNT_TYPE_SETTLEMENT          | ETH/DEC19 | 16710  | USD   |
   129        | market          | lpprov          | ACCOUNT_TYPE_SETTLEMENT | ACCOUNT_TYPE_MARGIN              | ETH/DEC19 | 15979  | USD   |
   130        | buySideProvider | buySideProvider | ACCOUNT_TYPE_GENERAL    | ACCOUNT_TYPE_MARGIN              | ETH/DEC19 | 76     | USD   |
   131  
   132      And the insurance pool balance should be "0" for the market "ETH/DEC19"
   133  
   134