code.vegaprotocol.io/vega@v0.79.0/core/integration/features/capped-futures/0016-PFUT-026.feature (about) 1 Feature: Futures market can be created with a with [hardcoded risk factors](./0018-RSKM-quant_risk_models.ipynb). 2 3 Background: 4 Given the average block duration is "1" 5 6 And the oracle spec for settlement data filtering data from "0xCAFECAFE1" named "ethDec21Oracle": 7 | property | type | binding | 8 | prices.ETH.value | TYPE_INTEGER | settlement data | 9 10 And the oracle spec for trading termination filtering data from "0xCAFECAFE1" named "ethDec21Oracle": 11 | property | type | binding | 12 | trading.terminated | TYPE_BOOLEAN | trading termination | 13 14 And the settlement data decimals for the oracle named "ethDec21Oracle" is given in "0" decimal places 15 16 And the following network parameters are set: 17 | name | value | 18 | market.auction.minimumDuration | 1 | 19 | network.markPriceUpdateMaximumFrequency | 1s | 20 | market.liquidity.successorLaunchWindowLength | 1s | 21 | limits.markets.maxPeggedOrders | 4 | 22 23 And the fees configuration named "fees-config-1": 24 | maker fee | infrastructure fee | 25 | 0.005 | 0.02 | 26 And the price monitoring named "price-monitoring-1": 27 | horizon | probability | auction extension | 28 | 3600000 | 0.99 | 300 | 29 And the simple risk model named "simple-risk-model": 30 | long | short | max move up | min move down | probability of trading | 31 | 0.1 | 0.2 | 100 | -100 | 0.2 | 32 And the log normal risk model named "lognormal-risk-model-1": 33 | risk aversion | tau | mu | r | sigma | 34 | 0.0002 | 0.01 | 0 | 0.0 | 1.2 | 35 And the markets: 36 | id | quote name | asset | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | max price cap | fully collateralised | binary | 37 | ETH/DEC21 | ETH | USD | simple-risk-model | default-margin-calculator | 1 | fees-config-1 | default-none | ethDec21Oracle | 0.25 | 0 | default-futures | 1500 | false | false | 38 39 @SLABug @NoPerp @Capped @MarginCap 40 Scenario: 0016-PFUT-026, 0016-PFUT-028: Capped futures market can be created with a with [hardcoded risk factors](./0018-RSKM-quant_risk_models.ipynb). 41 Given the initial insurance pool balance is "10000" for all the markets 42 And the parties deposit on asset's general account the following amount: 43 | party | asset | amount | 44 | party1 | USD | 10000 | 45 | party2 | USD | 10000 | 46 | aux1 | USD | 100000 | 47 | aux2 | USD | 100000 | 48 | aux3 | USD | 100000 | 49 | aux4 | USD | 100000 | 50 | aux5 | USD | 100000 | 51 | party-lp | USD | 100000000 | 52 53 And the parties submit the following liquidity provision: 54 | id | party | market id | commitment amount | fee | lp type | 55 | lp2 | party-lp | ETH/DEC21 | 30000 | 0 | submission | 56 57 When the parties place the following orders: 58 | party | market id | side | volume | price | resulting trades | type | tif | reference | error | 59 | aux1 | ETH/DEC21 | buy | 2 | 1 | 0 | TYPE_LIMIT | TIF_GTC | ref-1 | | 60 | aux2 | ETH/DEC21 | sell | 2 | 1499 | 0 | TYPE_LIMIT | TIF_GTC | ref-2 | | 61 | party1 | ETH/DEC21 | buy | 5 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | ref-3 | | 62 | party2 | ETH/DEC21 | sell | 5 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | ref-4 | | 63 And the network moves ahead "2" blocks 64 65 Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21" 66 And the market state should be "STATE_ACTIVE" for the market "ETH/DEC21" 67 And the mark price should be "1000" for the market "ETH/DEC21" 68 And the parties should have the following account balances: 69 | party | asset | market id | margin | general | 70 | party1 | USD | ETH/DEC21 | 2100 | 7900 | 71 | party2 | USD | ETH/DEC21 | 2700 | 7300 | 72 73 #order margin for aux1: limit price * size = 999*2=1998 74 #order margin for aux2: (max price - limit price) * size = (1500-1301)*2=398 75 #party1 maintenance margin level: position size * average entry price = 5*1000=5000 76 #party2 maintenance margin level: position size * (max price - average entry price)=5*(1500-1000)=2500 77 #aux1: potential position * average price on book = 2 * 0 = 0 78 #aux2: potential position * (max price - limit price) = 2 * 0 = 0 79 And the parties should have the following margin levels: 80 | party | market id | maintenance | search | initial | release | margin mode | 81 | party1 | ETH/DEC21 | 1750 | 1925 | 2100 | 2450 | cross margin | 82 | party2 | ETH/DEC21 | 2250 | 2475 | 2700 | 3150 | cross margin | 83 | aux2 | ETH/DEC21 | 400 | 440 | 480 | 560 | cross margin | 84 | aux1 | ETH/DEC21 | 200 | 220 | 240 | 280 | cross margin | 85 86 #update mark price 87 When the parties place the following orders: 88 | party | market id | side | volume | price | resulting trades | type | tif | reference | 89 | aux1 | ETH/DEC21 | buy | 1 | 1 | 0 | TYPE_LIMIT | TIF_GTC | aux1-2 | 90 | aux2 | ETH/DEC21 | sell | 1 | 1 | 1 | TYPE_LIMIT | TIF_GTC | aux2-2 | 91 92 And the network moves ahead "2" blocks 93 Then the mark price should be "1" for the market "ETH/DEC21" 94 95 And the following trades should be executed: 96 | buyer | price | size | seller | 97 | aux1 | 1 | 1 | aux2 | 98 99 # MTM settlement 5 long makes a loss of 5000, 5 short makes a profit of 5000 100 # Now for aux1 and 2, the calculations from above still hold but more margin is required due to the open positions: 101 # aux1: position * 1100 + 999*2 = 1100 + 1998 = 3098 102 # aux2: then placing the order (max price - average order price) * 3 = (1500 - (1301 + 1301 + 1100)/3) * 3 = (1500 - 1234) * 3 = 266 * 3 = 798 103 # aux2's short position and potential margins are calculated separately as 2 * (1500-1301) + 1 * (1500 - 1100) = 398 + 400 = 798 104 And the parties should have the following account balances: 105 | party | asset | market id | margin | general | 106 | party1 | USD | ETH/DEC21 | 2 | 5003 | 107 | party2 | USD | ETH/DEC21 | 3 | 14992 | 108 | aux1 | USD | ETH/DEC21 | 1 | 100000 | 109 | aux2 | USD | ETH/DEC21 | 1 | 99997 | 110 111 #update mark price to max_price 112 When the parties place the following orders: 113 | party | market id | side | volume | price | resulting trades | type | tif | reference | error | 114 | aux3 | ETH/DEC21 | buy | 2 | 1499 | 1 | TYPE_LIMIT | TIF_GTC | aux3-1 | | 115 116 And the following trades should be executed: 117 | buyer | price | size | seller | 118 | aux3 | 1499 | 2 | aux2 | 119 120 And the network moves ahead "2" blocks 121 Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21" 122 Then the mark price should be "1499" for the market "ETH/DEC21" 123 124 # MTM settlement 5 long makes a profit of 2000, 5 short loses 2000 125 # Now for aux1 and 2, the calculations from above still hold but more margin is required due to the open positions: 126 # aux1: position * 1100 + 999*2 = 1100 + 1998 = 3098 127 # aux2: short position of size 2, traded price at 1500, then margin: postion size * (max price - average entry price) = 3*(1100+1500*2)/3 128 And the parties should have the following account balances: 129 | party | asset | market id | margin | general | 130 | party1 | USD | ETH/DEC21 | 3148 | 9347 | 131 | party2 | USD | ETH/DEC21 | 4047 | 3458 | 132 | aux1 | USD | ETH/DEC21 | 990 | 100509 | 133 | aux2 | USD | ETH/DEC21 | 2428 | 96087 | 134 | aux3 | USD | ETH/DEC21 | 1260 | 98665 | 135 136 And the parties should have the following margin levels: 137 | party | market id | maintenance | search | initial | release | margin mode | 138 | party1 | ETH/DEC21 | 2624 | 2886 | 3148 | 3673 | cross margin | 139 | party2 | ETH/DEC21 | 3373 | 3710 | 4047 | 4722 | cross margin | 140 | aux2 | ETH/DEC21 | 2024 | 2226 | 2428 | 2833 | cross margin | 141 | aux1 | ETH/DEC21 | 825 | 907 | 990 | 1155 | cross margin | 142 143 When the markets are updated: 144 | id | risk model | 145 | ETH/DEC21 | lognormal-risk-model-1 | 146 # Place a trade, but don't move mark price. This will trigger the margin to be recalculated 147 And the parties place the following orders: 148 | party | market id | side | volume | price | resulting trades | type | tif | reference | 149 | aux2 | ETH/DEC21 | sell | 1 | 1499 | 0 | TYPE_LIMIT | TIF_GTC | aux2-3 | 150 | aux1 | ETH/DEC21 | buy | 1 | 1499 | 1 | TYPE_LIMIT | TIF_GTC | aux1-3 | 151 When the network moves ahead "2" blocks 152 Then the trading mode should be "TRADING_MODE_CONTINUOUS" for the market "ETH/DEC21" 153 # Ensure the mark price is still 1499 154 And the mark price should be "1499" for the market "ETH/DEC21" 155 # Now check the margin levels 156 And the parties should have the following margin levels: 157 | party | market id | maintenance | search | initial | release | margin mode | 158 | party1 | ETH/DEC21 | 4645 | 5109 | 5574 | 6503 | cross margin | 159 | party2 | ETH/DEC21 | 6109 | 6719 | 7330 | 8552 | cross margin | 160 | aux2 | ETH/DEC21 | 4888 | 5376 | 5865 | 6843 | cross margin | 161 | aux1 | ETH/DEC21 | 2967 | 3263 | 3560 | 4153 | cross margin |