code.vegaprotocol.io/vega@v0.79.0/core/integration/features/verified/0019-MCAL-margin_calculator-risk_parameters.feature (about) 1 Feature: test risk model parameter change in margin calculation 2 Background: 3 4 Given the log normal risk model named "log-normal-risk-model-1": 5 | risk aversion | tau | mu | r | sigma | 6 | 0.000001 | 0.001 | 0 | 0 | 1.0 | 7 #risk factor short = 0.16882368861315200 8 #risk factor long = 0.145263949 9 10 Given the log normal risk model named "log-normal-risk-model-2": 11 | risk aversion | tau | mu | r | sigma | 12 | 0.000001 | 0.001 | 0 | 0 | 2.0 | 13 #risk factor short = 0.36483236867768200 14 #risk factor long = 0.270133394 15 16 Given the log normal risk model named "log-normal-risk-model-3": 17 | risk aversion | tau | mu | r | sigma | 18 | 0.000001 | 0.002 | 0 | 0 | 1.0 | 19 #risk factor short = 0.24649034405344100 20 #risk factor long = 0.199294303 21 22 Given the log normal risk model named "log-normal-risk-model-4": 23 | risk aversion | tau | mu | r | sigma | 24 | 0.0001 | 0.001 | 0 | 0 | 1.0 | 25 #risk factor short = 0.13281340025639400 26 #risk factor long = 0.118078679 27 28 And the fees configuration named "fees-config-1": 29 | maker fee | infrastructure fee | 30 | 0.004 | 0.001 | 31 And the price monitoring named "price-monitoring-1": 32 | horizon | probability | auction extension | 33 | 1000 | 0.99 | 300 | 34 35 And the following network parameters are set: 36 | name | value | 37 | network.markPriceUpdateMaximumFrequency | 0s | 38 And the following network parameters are set: 39 | name | value | 40 | market.liquidity.bondPenaltyParameter | 0.2 | 41 | limits.markets.maxPeggedOrders | 8 | 42 And the liquidity monitoring parameters: 43 | name | triggering ratio | time window | scaling factor | 44 | lqm-params | 0.10 | 24h | 1 | 45 And the markets: 46 | id | quote name | asset | liquidity monitoring | risk model | margin calculator | auction duration | fees | price monitoring | data source config | linear slippage factor | quadratic slippage factor | sla params | 47 | ETH/MAR21 | ETH | USD | lqm-params | log-normal-risk-model-1 | default-margin-calculator | 1 | fees-config-1 | price-monitoring-1 | default-eth-for-future | 0.25 | 0 | default-futures | 48 | ETH/MAR22 | ETH | USD | lqm-params | log-normal-risk-model-2 | default-margin-calculator | 1 | fees-config-1 | price-monitoring-1 | default-eth-for-future | 0.25 | 0 | default-futures | 49 | ETH/MAR23 | ETH | USD | lqm-params | log-normal-risk-model-3 | default-margin-calculator | 1 | fees-config-1 | price-monitoring-1 | default-eth-for-future | 0.25 | 0 | default-futures | 50 | ETH/MAR24 | ETH | USD | lqm-params | log-normal-risk-model-4 | default-margin-calculator | 1 | fees-config-1 | price-monitoring-1 | default-eth-for-future | 0.25 | 0 | default-futures | 51 52 And the parties deposit on asset's general account the following amount: 53 | party | asset | amount | 54 | party0 | USD | 5000000000 | 55 | party1 | USD | 100000000 | 56 | party2 | USD | 100000000 | 57 | party3 | USD | 100000000 | 58 59 @SLABug 60 Scenario: lognormal risk model in 4 markets with different risk parameters , 0010-MARG-012, 0010-MARG-013, 0010-MARG-014 61 62 Given the average block duration is "1" 63 64 And the parties submit the following liquidity provision: 65 | id | party | market id | commitment amount | fee | lp type | 66 | lp1 | party0 | ETH/MAR21 | 50000 | 0.001 | submission | 67 | lp1 | party0 | ETH/MAR21 | 50000 | 0.001 | amendment | 68 | lp2 | party0 | ETH/MAR22 | 50000 | 0.001 | submission | 69 | lp2 | party0 | ETH/MAR22 | 50000 | 0.001 | amendment | 70 | lp3 | party0 | ETH/MAR23 | 50000 | 0.001 | submission | 71 | lp3 | party0 | ETH/MAR23 | 50000 | 0.001 | submission | 72 | lp4 | party0 | ETH/MAR24 | 50000 | 0.001 | submission | 73 | lp4 | party0 | ETH/MAR24 | 50000 | 0.001 | amendment | 74 75 When the parties place the following orders: 76 | party | market id | side | volume | price | resulting trades | type | tif | reference | 77 | party0 | ETH/MAR21 | buy | 57 | 880 | 0 | TYPE_LIMIT | TIF_GTC | peg-1 | 78 | party0 | ETH/MAR21 | sell | 45 | 1120 | 0 | TYPE_LIMIT | TIF_GTC | peg-2 | 79 | party0 | ETH/MAR22 | buy | 57 | 880 | 0 | TYPE_LIMIT | TIF_GTC | peg-1 | 80 | party0 | ETH/MAR22 | sell | 45 | 1120 | 0 | TYPE_LIMIT | TIF_GTC | peg-2 | 81 | party0 | ETH/MAR23 | buy | 57 | 880 | 0 | TYPE_LIMIT | TIF_GTC | peg-1 | 82 | party0 | ETH/MAR23 | sell | 45 | 1120 | 0 | TYPE_LIMIT | TIF_GTC | peg-2 | 83 | party0 | ETH/MAR24 | buy | 57 | 880 | 0 | TYPE_LIMIT | TIF_GTC | peg-1 | 84 | party0 | ETH/MAR24 | sell | 45 | 1120 | 0 | TYPE_LIMIT | TIF_GTC | peg-2 | 85 86 And the parties place the following orders: 87 | party | market id | side | volume | price | resulting trades | type | tif | reference | 88 | party1 | ETH/MAR21 | buy | 1 | 900 | 0 | TYPE_LIMIT | TIF_GTC | buy-ref-11 | 89 | party1 | ETH/MAR21 | buy | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | buy-ref-12 | 90 | party2 | ETH/MAR21 | sell | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | sell-ref-13 | 91 | party2 | ETH/MAR21 | sell | 1 | 1100 | 0 | TYPE_LIMIT | TIF_GTC | sell-ref-14 | 92 | party1 | ETH/MAR22 | buy | 1 | 900 | 0 | TYPE_LIMIT | TIF_GTC | buy-ref-21 | 93 | party1 | ETH/MAR22 | buy | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | buy-ref-22 | 94 | party2 | ETH/MAR22 | sell | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | sell-ref-23 | 95 | party2 | ETH/MAR22 | sell | 1 | 1100 | 0 | TYPE_LIMIT | TIF_GTC | sell-ref-24 | 96 | party1 | ETH/MAR23 | buy | 1 | 900 | 0 | TYPE_LIMIT | TIF_GTC | buy-ref-31 | 97 | party1 | ETH/MAR23 | buy | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | buy-ref-32 | 98 | party2 | ETH/MAR23 | sell | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | sell-ref-33 | 99 | party2 | ETH/MAR23 | sell | 1 | 1100 | 0 | TYPE_LIMIT | TIF_GTC | sell-ref-34 | 100 | party1 | ETH/MAR24 | buy | 1 | 900 | 0 | TYPE_LIMIT | TIF_GTC | buy-ref-41 | 101 | party1 | ETH/MAR24 | buy | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | buy-ref-42 | 102 | party2 | ETH/MAR24 | sell | 10 | 1000 | 0 | TYPE_LIMIT | TIF_GTC | sell-ref-43 | 103 | party2 | ETH/MAR24 | sell | 1 | 1100 | 0 | TYPE_LIMIT | TIF_GTC | sell-ref-44 | 104 105 When the network moves ahead "2" blocks 106 107 Then the market data for the market "ETH/MAR21" should be: 108 | mark price | trading mode | horizon | min bound | max bound | target stake | supplied stake | open interest | 109 | 1000 | TRADING_MODE_CONTINUOUS | 1000 | 986 | 1014 | 1688 | 50000 | 10 | 110 #target_stake = mark_price x max_oi x target_stake_scaling_factor x rf_short = 1000 x 10 x 1 x 0.16882368861315200 =1689 111 And the market data for the market "ETH/MAR22" should be: 112 | mark price | trading mode | horizon | min bound | max bound | target stake | supplied stake | open interest | 113 | 1000 | TRADING_MODE_CONTINUOUS | 1000 | 972 | 1029 | 3648 | 50000 | 10 | 114 # target_stake = mark_price x max_oi x target_stake_scaling_factor x rf_short = 1000 x 10 x 1 x 0.36483236867768200 = 3648 115 And the market data for the market "ETH/MAR24" should be: 116 | mark price | trading mode | horizon | min bound | max bound | target stake | supplied stake | open interest | 117 | 1000 | TRADING_MODE_CONTINUOUS | 1000 | 986 | 1014 | 1328 | 50000 | 10 | 118 # target_stake = mark_price x max_oi x target_stake_scaling_factor x rf_short = 1000 x 10 x 1 x 0.13281340025639400 = 1328 119 And the market data for the market "ETH/MAR24" should be: 120 | mark price | trading mode | horizon | min bound | max bound | target stake | supplied stake | open interest | 121 | 1000 | TRADING_MODE_CONTINUOUS | 1000 | 986 | 1014 | 1328 | 50000 | 10 | 122 # target_stake = mark_price x max_oi x target_stake_scaling_factor x rf_short = 1000 x 10 x 1 x 0.13281340025639400 = 1328 123 124 #check the volume on the order book, liquidity price has been kept within price monitoring bounds 125 126 Then the order book should have the following volumes for market "ETH/MAR21": 127 | side | price | volume | 128 | sell | 1120 | 45 | 129 | sell | 1100 | 1 | 130 | buy | 900 | 1 | 131 | buy | 880 | 57 | 132 Then the order book should have the following volumes for market "ETH/MAR22": 133 | side | price | volume | 134 | sell | 1120 | 45 | 135 | sell | 1100 | 1 | 136 | buy | 900 | 1 | 137 | buy | 880 | 57 | 138 Then the order book should have the following volumes for market "ETH/MAR23": 139 | side | price | volume | 140 | sell | 1120 | 45 | 141 | sell | 1100 | 1 | 142 | buy | 900 | 1 | 143 | buy | 880 | 57 | 144 Then the order book should have the following volumes for market "ETH/MAR24": 145 | side | price | volume | 146 | sell | 1120 | 45 | 147 | sell | 1100 | 1 | 148 | buy | 900 | 1 | 149 | buy | 880 | 57 | 150 151 # # risk model 001: check the required balances 152 # And the parties should have the following account balances: 153 # | party | asset | market id | margin | general | bond | 154 # | party0 | USD | ETH/MAR21 | 9937 | 248653 | 50000 | 155 # | party1 | USD | ETH/MAR21 | 3333 | 99984664 | | 156 # | party2 | USD | ETH/MAR21 | 3645 | 99982284 | | 157 158 # #party1 margin level is: margin_position+margin_order = vol * (MarkPrice-ExitPrice)+ vol * rf * MarkPrice + order * rf * MarkPrice = 10 * (1000-882)+10*0.145263949*1000 + 1*0.145263949*1000=2778 159 # Then the parties should have the following margin levels: 160 # | party | market id | maintenance | search | initial | release | 161 # | party0 | ETH/MAR21 | 8281 | 9109 | 9937 | 11593 | 162 # | party1 | ETH/MAR21 | 2778 | 3055 | 3333 | 3889 | 163 # | party2 | ETH/MAR21 | 3038 | 3341 | 3645 | 4253 | 164 165 # # risk model 002: check the required balances 166 # And the parties should have the following account balances: 167 # | party | asset | market id | margin | general | bond | 168 # | party0 | USD | ETH/MAR22 | 19701 | 248653 | 50000 | 169 # | party1 | USD | ETH/MAR22 | 4982 | 99984664 | | 170 # | party2 | USD | ETH/MAR22 | 6232 | 99982284 | | 171 172 # #party1 margin level is: margin_position+margin_order = vol * (MarkPrice-ExitPrice)+ vol * rf * MarkPrice + order * rf * MarkPrice = 10 * (1000-882)+10*0.270133394*1000 + 1*0.270133394*1000=4152 173 # Then the parties should have the following margin levels: 174 # | party | market id | maintenance | search | initial | release | 175 # | party0 | ETH/MAR22 | 16418 | 18059 | 19701 | 22985 | 176 # | party1 | ETH/MAR22 | 4152 | 4567 | 4982 | 5812 | 177 # | party2 | ETH/MAR22 | 5194 | 5713 | 6232 | 7271 | 178 179 # #risk model 003: check the required balances 180 # And the parties should have the following account balances: 181 # | party | asset | market id | margin | general | bond | 182 # | party0 | USD | ETH/MAR23 | 13632 | 248653 | 50000 | 183 # | party1 | USD | ETH/MAR23 | 4047 | 99984664 | | 184 # | party2 | USD | ETH/MAR23 | 4670 | 99982284 | | 185 186 # #party1 margin level is: margin_position+margin_order = vol * (MarkPrice-ExitPrice)+ vol * rf * MarkPrice + order * rf * MarkPrice = 10 * (1000-882)+10*0.199294303*1000 + 1*0.199294303*1000=3373 187 # Then the parties should have the following margin levels: 188 # | party | market id | maintenance | search | initial | release | 189 # | party0 | ETH/MAR23 | 11360 | 12496 | 13632 | 15904 | 190 # | party1 | ETH/MAR23 | 3373 | 3710 | 4047 | 4722 | 191 # | party2 | ETH/MAR23 | 3892 | 4281 | 4670 | 5448 | 192 # # | party1 | ETH/MAR23 | 3193 | 3512 | 3831 | 4470 | 193 # # | party2 | ETH/MAR23 | 3712 | 4083 | 4454 | 5196 | 194 # # risk model 004: check the required balances 195 # And the parties should have the following account balances: 196 # | party | asset | market id | margin | general | bond | 197 # | party0 | USD | ETH/MAR24 | 8077 | 248653 | 50000 | 198 # | party1 | USD | ETH/MAR24 | 2974 | 99984664 | | 199 # | party2 | USD | ETH/MAR24 | 3169 | 99982284 | | 200 201 # #party1 margin level is: margin_position+margin_order = vol * (MarkPrice-ExitPrice)+ vol * rf * MarkPrice + order * rf * MarkPrice = 10 * (1000-882)+10*0.118078679*1000 + 1*0.118078679*1000=2479 202 # Then the parties should have the following margin levels: 203 # | party | market id | maintenance | search | initial | release | 204 # | party0 | ETH/MAR24 | 6731 | 7404 | 8077 | 9423 | 205 # | party1 | ETH/MAR24 | 2479 | 2726 | 2974 | 3470 | 206 # | party2 | ETH/MAR24 | 2641 | 2905 | 3169 | 3697 | 207 208