code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/the_simple_risk_model.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package steps
    17  
    18  import (
    19  	"code.vegaprotocol.io/vega/core/integration/steps/market"
    20  	types "code.vegaprotocol.io/vega/protos/vega"
    21  
    22  	"github.com/cucumber/godog"
    23  )
    24  
    25  func TheSimpleRiskModel(config *market.Config, name string, table *godog.Table) error {
    26  	row := simpleRiskModelRow{row: parseSimpleRiskModelTable(table)}
    27  
    28  	return config.RiskModels.AddSimple(name, &types.TradableInstrument_SimpleRiskModel{
    29  		SimpleRiskModel: &types.SimpleRiskModel{
    30  			Params: &types.SimpleModelParams{
    31  				FactorLong:           row.long(),
    32  				FactorShort:          row.short(),
    33  				MaxMoveUp:            row.maxMoveUp(),
    34  				MinMoveDown:          row.minMoveDown(),
    35  				ProbabilityOfTrading: row.probabilityOfTrading(),
    36  			},
    37  		},
    38  	})
    39  }
    40  
    41  func parseSimpleRiskModelTable(table *godog.Table) RowWrapper {
    42  	return StrictParseFirstRow(table, []string{
    43  		"probability of trading",
    44  		"long",
    45  		"short",
    46  		"max move up",
    47  		"min move down",
    48  	}, []string{})
    49  }
    50  
    51  type simpleRiskModelRow struct {
    52  	row RowWrapper
    53  }
    54  
    55  func (r simpleRiskModelRow) probabilityOfTrading() float64 {
    56  	return r.row.MustF64("probability of trading")
    57  }
    58  
    59  func (r simpleRiskModelRow) long() float64 {
    60  	return r.row.MustF64("long")
    61  }
    62  
    63  func (r simpleRiskModelRow) short() float64 {
    64  	return r.row.MustF64("short")
    65  }
    66  
    67  func (r simpleRiskModelRow) maxMoveUp() float64 {
    68  	return r.row.MustF64("max move up")
    69  }
    70  
    71  func (r simpleRiskModelRow) minMoveDown() float64 {
    72  	return r.row.MustF64("min move down")
    73  }