Skip to content

Commit

Permalink
Remove obsolete initial mark price network parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinTrinque committed Mar 9, 2021
1 parent 1f68f7e commit 4653370
Show file tree
Hide file tree
Showing 73 changed files with 2,520 additions and 2,129 deletions.
5 changes: 0 additions & 5 deletions cmd/vega/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func createDefaultMarkets(confpath string) ([]string, error) {
settlementAsset string
quoteName string
maturity time.Time
initialMarkPrice uint64
settlementValue uint64
sigma float64
riskAversionParameter float64
Expand All @@ -185,7 +184,6 @@ func createDefaultMarkets(confpath string) ([]string, error) {
quoteName: "VUSD",
settlementAsset: "VUSD",
maturity: time.Date(2020, 12, 31, 23, 59, 59, 0, time.UTC),
initialMarkPrice: 1410000,
settlementValue: 1500000,
riskAversionParameter: 0.001,
sigma: 1.5,
Expand All @@ -198,7 +196,6 @@ func createDefaultMarkets(confpath string) ([]string, error) {
quoteName: "VUSD",
settlementAsset: "VUSD",
maturity: time.Date(2020, 10, 30, 22, 59, 59, 0, time.UTC),
initialMarkPrice: 130000,
settlementValue: 126000,
riskAversionParameter: 0.01,
sigma: 0.09,
Expand All @@ -211,7 +208,6 @@ func createDefaultMarkets(confpath string) ([]string, error) {
quoteName: "BTC",
settlementAsset: "BTC",
maturity: time.Date(2020, 12, 31, 23, 59, 59, 0, time.UTC),
initialMarkPrice: 10000,
settlementValue: 98123,
riskAversionParameter: 0.001,
sigma: 2.0,
Expand Down Expand Up @@ -250,7 +246,6 @@ func createDefaultMarkets(confpath string) ([]string, error) {
"product:futures",
},
},
InitialMarkPrice: skel.initialMarkPrice,
Product: &proto.Instrument_Future{
Future: &proto.Future{
QuoteName: skel.quoteName,
Expand Down
10 changes: 1 addition & 9 deletions execution/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ var (
ErrMarginCheckFailed = errors.New("margin check failed")
// ErrMarginCheckInsufficient signals that a margin had not enough funds
ErrMarginCheckInsufficient = errors.New("insufficient margin")
// ErrInvalidInitialMarkPrice signals that the initial mark price for a market is invalid
ErrInvalidInitialMarkPrice = errors.New("invalid initial mark price (mkprice <= 0)")
// ErrMissingGeneralAccountForParty ...
ErrMissingGeneralAccountForParty = errors.New("missing general account for party")
// ErrNotEnoughVolumeToZeroOutNetworkOrder ...
Expand Down Expand Up @@ -246,19 +244,14 @@ func NewMarket(
return nil, errors.Wrap(err, "unable to instantiate a new market")
}

if tradableInstrument.Instrument.InitialMarkPrice == 0 {
return nil, ErrInvalidInitialMarkPrice
}

closingAt, err := tradableInstrument.Instrument.GetMarketClosingTime()
if err != nil {
return nil, errors.Wrap(err, "unable to get market closing time")
}

// @TODO -> the raw auctionstate shouldn't be something exposed to the matching engine
// as far as matching goes: it's either an auction or not
book := matching.NewOrderBook(log, matchingConfig, mkt.Id,
tradableInstrument.Instrument.InitialMarkPrice, as.InAuction())
book := matching.NewOrderBook(log, matchingConfig, mkt.Id, as.InAuction())
asset := tradableInstrument.Instrument.Product.GetAsset()
riskEngine := risk.NewEngine(
log,
Expand Down Expand Up @@ -303,7 +296,6 @@ func NewMarket(
mkt: mkt,
closingAt: closingAt,
currentTime: now,
markPrice: tradableInstrument.Instrument.InitialMarkPrice,
matching: book,
tradableInstrument: tradableInstrument,
risk: riskEngine,
Expand Down
1 change: 0 additions & 1 deletion execution/market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ func getMarket(closingAt time.Time, pMonitorSettings *types.PriceMonitoringSetti
"product:futures",
},
},
InitialMarkPrice: 99,
Product: &types.Instrument_Future{
Future: &types.Future{
Maturity: closingAt.Format(time.RFC3339),
Expand Down
2 changes: 0 additions & 2 deletions governance/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ func createInstrument(
input *types.InstrumentConfiguration,
tags []string,
) (*types.Instrument, error) {
intialMarkPrice, _ := netp.GetInt(netparams.MarketInitialMarkPrice)
result := &types.Instrument{
Name: input.Name,
Code: input.Code,
Metadata: &types.InstrumentMetadata{
Tags: tags,
},
InitialMarkPrice: uint64(intialMarkPrice),
}

if err := assignProduct(netp, input, result); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ The `-v` flag tells `go test` to run with verbose output (sending logging to std
To run only certain tests (feature files), you can simply add the paths to a given feature file to the command:

```shell
go test -v ./integration/... -godog.format=pretty $(pwd)/integration/features/simple.feature
go test -v ./integration/... -godog.format=pretty $(pwd)/integration/features/my-feature.feature
```

## Race detection and cache
Expand All @@ -51,7 +51,7 @@ Should there be tests that are intermittently failing, this could indicate a dat
go test -v -count=1 -race ./integration/... -godog.format=pretty

# Same as above, but only run a specific feature file:
go test -v -count=1 -race ./integration/... -godog.format=pretty $(pwd)/integration/feature/core.feature
go test -v -count=1 -race ./integration/... -godog.format=pretty $(pwd)/integration/feature/my-feature-test.feature
```

Race detection is a complex thing to do, so it will make running tests significantly slower. The pipeline runs the tests with race detection, so this shouldn't be required to do locally.
Expand All @@ -66,6 +66,6 @@ Feature: A feature that reproduces some system test
Background:
Given the insurance pool initial balance for the markets is "0":
And the execution engine have these markets:
| name | baseName | quoteName | asset | markprice | risk model | lamd/long | tau/short | mu | r | sigma | release factor | initial factor | search factor | settlementPrice | openAuction | trading mode | makerFee | infrastructureFee | liquidityFee | p. m. update freq. | p. m. horizons | p. m. probs | p. m. durations | Prob of trading |
| ETH/DEC20 | ETH | ETH | ETH | 100 | simple | 0.08628781058136630000 | 0.09370922348428490000 | -1 | -1 | -1 | 1.4 | 1.2 | 1.1 | 100 | 1 | continuous | 0.004 | 0.001 | 0.3 | 0 | | | | 0.1 |
| name | baseName | quoteName | asset | risk model | lamd/long | tau/short | mu | r | sigma | release factor | initial factor | search factor | settlementPrice | openAuction | trading mode | makerFee | infrastructureFee | liquidityFee | p. m. update freq. | p. m. horizons | p. m. probs | p. m. durations | Prob of trading |
| ETH/DEC20 | ETH | ETH | ETH | simple | 0.08628781058136630000 | 0.09370922348428490000 | -1 | -1 | -1 | 1.4 | 1.2 | 1.1 | 100 | 1 | continuous | 0.004 | 0.001 | 0.3 | 0 | | | | 0.1 |
```
40 changes: 21 additions & 19 deletions integration/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,27 @@ var (

func initialiseMarket(row *gherkin.TableRow, mkt *proto.Market) {
// the header of the feature file (ie where to find the data in the row) looks like this:
// | name | markprice | risk model | lamd | tau | mu | r | sigma | release factor | initial factor | search factor |
// | name | risk model | lamd | tau | mu | r | sigma | release factor | initial factor | search factor |

// general stuff like name, ID, code, asset, and initial mark price
// mkt.TradingMode = proto.Market_TRADING_MODE_CONTINUOUS
// mkt.State = proto.Market_STATE_ACTIVE
// general stuff like name, ID, code, asset
parts := strings.Split(row.Cells[0].Value, "/")
mkt.Id = fmt.Sprintf("Crypto/%s/Futures/%s", parts[0], parts[1])
mkt.Id = val(row, 0)
mkt.TradableInstrument.Instrument.Code = fmt.Sprintf("FX:%s%s", parts[0], parts[1])
prod := mkt.TradableInstrument.Instrument.GetFuture()
prod.SettlementAsset = parts[0]
mkt.TradableInstrument.Instrument.Product = &proto.Instrument_Future{
Future: prod,
} // set asset, reassign the product
mkt.TradableInstrument.Instrument.InitialMarkPrice, _ = strconv.ParseUint(row.Cells[1].Value, 10, 64)

// whether it's lambd/tau or short/long depends on the risk model
lambdShort, _ := strconv.ParseFloat(row.Cells[3].Value, 64)
tauLong, _ := strconv.ParseFloat(row.Cells[4].Value, 64)
lambdShort, _ := strconv.ParseFloat(row.Cells[2].Value, 64)
tauLong, _ := strconv.ParseFloat(row.Cells[3].Value, 64)
// we'll always need to use these
release, _ := strconv.ParseFloat(row.Cells[8].Value, 64)
initial, _ := strconv.ParseFloat(row.Cells[9].Value, 64)
search, _ := strconv.ParseFloat(row.Cells[10].Value, 64)
//openAuctionDuration, _ := strconv.ParseInt(row.Cells[11].Value, 10, 64)
if row.Cells[12].Value != "continuous" {
batchDuration, _ := strconv.ParseInt(row.Cells[12].Value, 10, 64)
release, _ := strconv.ParseFloat(row.Cells[7].Value, 64)
initial, _ := strconv.ParseFloat(row.Cells[8].Value, 64)
search, _ := strconv.ParseFloat(row.Cells[9].Value, 64)
if row.Cells[11].Value != "continuous" {
batchDuration, _ := strconv.ParseInt(row.Cells[11].Value, 10, 64)
mkt.TradingModeConfig = &proto.Market_Discrete{
Discrete: &proto.DiscreteTrading{
DurationNs: batchDuration,
Expand All @@ -68,7 +64,9 @@ func initialiseMarket(row *gherkin.TableRow, mkt *proto.Market) {
}

// simple risk model:
if row.Cells[2].Value == "simple" {
fmt.Printf("Market %v\n", logging.Market(*mkt).String)

if row.Cells[1].Value == "simple" {
mkt.TradableInstrument.RiskModel = &proto.TradableInstrument_SimpleRiskModel{
SimpleRiskModel: &proto.SimpleRiskModel{
Params: &proto.SimpleModelParams{
Expand All @@ -80,9 +78,9 @@ func initialiseMarket(row *gherkin.TableRow, mkt *proto.Market) {
return
}
// for now, default to/assume future (forward risk model)
mu, _ := strconv.ParseFloat(row.Cells[5].Value, 64)
r, _ := strconv.ParseFloat(row.Cells[6].Value, 64)
sigma, _ := strconv.ParseFloat(row.Cells[7].Value, 64)
mu, _ := strconv.ParseFloat(row.Cells[4].Value, 64)
r, _ := strconv.ParseFloat(row.Cells[5].Value, 64)
sigma, _ := strconv.ParseFloat(row.Cells[6].Value, 64)
// No opening auction for now
//mkt.OpeningAuction.Duration = openAuctionDuration
mkt.TradableInstrument.RiskModel = &proto.TradableInstrument_LogNormalRiskModel{
Expand Down Expand Up @@ -177,7 +175,11 @@ func theMarket(mSetup *gherkin.DataTable) error {
return err
}

m.StartOpeningAuction(context.Background())
err = m.StartOpeningAuction(context.Background())
if err != nil {
return err
}

mktsetup.core = m
core = m
return nil
Expand Down
55 changes: 27 additions & 28 deletions integration/execution_layer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ func theMarkPriceForTheMarketIs(market, markPriceStr string) error {
}

if mktdata.MarkPrice != markPrice {
return fmt.Errorf("mark price if wrong for market(%v), expected(%v) got(%v)", market, markPrice, mktdata.MarkPrice)
return fmt.Errorf("mark price is wrong for market(%v), expected(%v) got(%v)", market, markPrice, mktdata.MarkPrice)
}

return nil
Expand Down Expand Up @@ -991,17 +991,17 @@ func accountID(marketID, partyID, asset string, _ty int32) string {
}

func baseMarket(row *gherkin.TableRow) types.Market {
horizons, err := i64arr(row, 21, ",")
horizons, err := i64arr(row, 20, ",")
if err != nil {
log.Fatalf("Can't parse horizons (%v) to int64 array: %v", row.Cells[21].Value, err)
log.Fatalf("Can't parse horizons (%v) to int64 array: %v", row.Cells[20].Value, err)
}
probs, err := f64arr(row, 22, ",")
probs, err := f64arr(row, 21, ",")
if err != nil {
log.Fatalf("Can't parse probabilities (%v) to float64 array: %v", row.Cells[22].Value, err)
log.Fatalf("Can't parse probabilities (%v) to float64 array: %v", row.Cells[21].Value, err)
}
durations, err := i64arr(row, 23, ",")
durations, err := i64arr(row, 22, ",")
if err != nil {
log.Fatalf("Can't parse durations (%v) to int64 array: %v", row.Cells[23].Value, err)
log.Fatalf("Can't parse durations (%v) to int64 array: %v", row.Cells[22].Value, err)
}
n := len(horizons)
if n != len(probs) || n != len(durations) {
Expand All @@ -1020,11 +1020,11 @@ func baseMarket(row *gherkin.TableRow) types.Market {
Parameters: &types.PriceMonitoringParameters{
Triggers: triggs,
},
UpdateFrequency: i64val(row, 20),
UpdateFrequency: i64val(row, 19),
}

openingAuction := &types.AuctionDuration{
Duration: i64val(row, 15),
Duration: i64val(row, 14),
}

if openingAuction.Duration <= 0 {
Expand All @@ -1038,9 +1038,9 @@ func baseMarket(row *gherkin.TableRow) types.Market {
DecimalPlaces: 2,
Fees: &types.Fees{
Factors: &types.FeeFactors{
LiquidityFee: val(row, 19),
InfrastructureFee: val(row, 18),
MakerFee: val(row, 17),
LiquidityFee: val(row, 18),
InfrastructureFee: val(row, 17),
MakerFee: val(row, 16),
},
},
TradableInstrument: &types.TradableInstrument{
Expand All @@ -1054,15 +1054,14 @@ func baseMarket(row *gherkin.TableRow) types.Market {
"product:futures",
},
},
InitialMarkPrice: u64val(row, 4),
Product: &types.Instrument_Future{
Future: &types.Future{
Maturity: marketExpiry,
Oracle: &types.Future_EthereumEvent{
EthereumEvent: &types.EthereumEvent{
ContractId: "0x0B484706fdAF3A4F24b2266446B1cb6d648E3cC1",
Event: "price_changed",
Value: u64val(row, 14),
Value: u64val(row, 13),
},
},
SettlementAsset: val(row, 3),
Expand All @@ -1073,19 +1072,19 @@ func baseMarket(row *gherkin.TableRow) types.Market {
RiskModel: &types.TradableInstrument_SimpleRiskModel{
SimpleRiskModel: &types.SimpleRiskModel{
Params: &types.SimpleModelParams{
FactorLong: f64val(row, 6),
FactorShort: f64val(row, 7),
MaxMoveUp: f64val(row, 8),
MinMoveDown: f64val(row, 9),
ProbabilityOfTrading: f64val(row, 24),
FactorLong: f64val(row, 5),
FactorShort: f64val(row, 6),
MaxMoveUp: f64val(row, 7),
MinMoveDown: f64val(row, 8),
ProbabilityOfTrading: f64val(row, 23),
},
},
},
MarginCalculator: &types.MarginCalculator{
ScalingFactors: &types.ScalingFactors{
SearchLevel: f64val(row, 13),
InitialMargin: f64val(row, 12),
CollateralRelease: f64val(row, 11),
SearchLevel: f64val(row, 12),
InitialMargin: f64val(row, 11),
CollateralRelease: f64val(row, 10),
},
},
},
Expand All @@ -1099,15 +1098,15 @@ func baseMarket(row *gherkin.TableRow) types.Market {
ScalingFactor: 10,
},
}
if val(row, 5) == "forward" {
if val(row, 4) == "forward" {
mkt.TradableInstrument.RiskModel = &types.TradableInstrument_LogNormalRiskModel{
LogNormalRiskModel: &types.LogNormalRiskModel{
RiskAversionParameter: f64val(row, 6), // 6
Tau: f64val(row, 7), // 7
RiskAversionParameter: f64val(row, 5), // 5
Tau: f64val(row, 6), // 6
Params: &types.LogNormalModelParams{
Mu: f64val(row, 8), // 8
R: f64val(row, 9), // 9
Sigma: f64val(row, 10), //10
Mu: f64val(row, 7), // 7
R: f64val(row, 8), // 8
Sigma: f64val(row, 9), //9
},
},
}
Expand Down
10 changes: 5 additions & 5 deletions integration/features/1779-cannot-place-network-order.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ Feature: Cannot place an network order
Background:
Given the insurance pool initial balance for the markets is "0":
And the execution engine have these markets:
| name | baseName | quoteName | asset | markprice | risk model | lamd/long | tau/short | mu | r | sigma | release factor | initial factor | search factor | settlementPrice | openAuction | trading mode | makerFee | infrastructureFee | liquidityFee | p. m. update freq. | p. m. horizons | p. m. probs | p. m. durations | Prob of trading |
| ETH/DEC19 | BTC | ETH | ETH | 1000 | simple | 0.11 | 0.1 | 0 | 0 | 0 | 1.4 | 1.2 | 1.1 | 42 | 0 | continuous | 0 | 0 | 0 | 0 | | | | 0.1 |
| name | baseName | quoteName | asset | risk model | lamd/long | tau/short | mu | r | sigma | release factor | initial factor | search factor | settlementPrice | openAuction | trading mode | makerFee | infrastructureFee | liquidityFee | p. m. update freq. | p. m. horizons | p. m. probs | p. m. durations | Prob of trading |
| ETH/DEC19 | BTC | ETH | ETH | simple | 0.11 | 0.1 | 0 | 0 | 0 | 1.4 | 1.2 | 1.1 | 42 | 0 | continuous | 0 | 0 | 0 | 0 | | | | 0.1 |

Scenario: an order is rejected if a trader try to place an order with type NETWORK
Given the following traders:
| name | amount |
| trader1 | 1 |
| trader1 | 1 |
Then I Expect the traders to have new general account:
| name | asset |
| trader1 | ETH |
And "trader1" general accounts balance is "1"
Then traders place following failing orders:
| trader | id | type | volume | price | error | type |
| trader1 | ETH/DEC19 | sell | 1 | 1000 | invalid order type | TYPE_NETWORK |
| trader | id | type | volume | price | error | type |
| trader1 | ETH/DEC19 | sell | 1 | 1000 | invalid order type | TYPE_NETWORK |
4 changes: 2 additions & 2 deletions integration/features/1847-closeout-long-with-fees.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Feature: Long close-out test (see ln 293 of system-tests/grpc/trading/tradesTest
Background:
Given the insurance pool initial balance for the markets is "0":
And the execution engine have these markets:
| name | baseName | quoteName | asset | markprice | risk model | lamd/long | tau/short | mu | r | sigma | release factor | initial factor | search factor | settlementPrice | openAuction | trading mode | makerFee | infrastructureFee | liquidityFee | p. m. update freq. | p. m. horizons | p. m. probs | p. m. durations | Prob of trading |
| ETH/DEC19 | ETH | BTC | BTC | 100 | simple | 0.1 | 0.1 | -1 | -1 | -1 | 1.4 | 1.2 | 1.1 | 100 | 0 | continuous | 0.00025 | 0.0005 | 0.001 | 0 | | | | 0.1 |
| name | baseName | quoteName | asset | risk model | lamd/long | tau/short | mu | r | sigma | release factor | initial factor | search factor | settlementPrice | openAuction | trading mode | makerFee | infrastructureFee | liquidityFee | p. m. update freq. | p. m. horizons | p. m. probs | p. m. durations | Prob of trading |
| ETH/DEC19 | ETH | BTC | BTC | simple | 0.1 | 0.1 | -1 | -1 | -1 | 1.4 | 1.2 | 1.1 | 100 | 0 | continuous | 0.00025 | 0.0005 | 0.001 | 0 | | | | 0.1 |

Scenario: https://drive.google.com/file/d/1bYWbNJvG7E-tcqsK26JMu2uGwaqXqm0L/view
# setup accounts
Expand Down
Loading

0 comments on commit 4653370

Please sign in to comment.