code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/the_log_normal_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 TheLogNormalRiskModel(config *market.Config, name string, table *godog.Table) error {
    26  	row := logNormalRiskModelRow{row: parseLogNormalRiskModelTable(table)}
    27  
    28  	return config.RiskModels.AddLogNormal(name, &types.TradableInstrument_LogNormalRiskModel{
    29  		LogNormalRiskModel: &types.LogNormalRiskModel{
    30  			RiskAversionParameter: row.riskAversion(),
    31  			Tau:                   row.tau(),
    32  			Params: &types.LogNormalModelParams{
    33  				Mu:    row.mu(),
    34  				R:     row.r(),
    35  				Sigma: row.sigma(),
    36  			},
    37  		},
    38  	})
    39  }
    40  
    41  func parseLogNormalRiskModelTable(table *godog.Table) RowWrapper {
    42  	return StrictParseFirstRow(table, []string{
    43  		"risk aversion",
    44  		"tau",
    45  		"mu",
    46  		"r",
    47  		"sigma",
    48  	}, []string{})
    49  }
    50  
    51  type logNormalRiskModelRow struct {
    52  	row RowWrapper
    53  }
    54  
    55  func (r logNormalRiskModelRow) riskAversion() float64 {
    56  	return r.row.MustF64("risk aversion")
    57  }
    58  
    59  func (r logNormalRiskModelRow) tau() float64 {
    60  	return r.row.MustF64("tau")
    61  }
    62  
    63  func (r logNormalRiskModelRow) mu() float64 {
    64  	return r.row.MustF64("mu")
    65  }
    66  
    67  func (r logNormalRiskModelRow) r() float64 {
    68  	return r.row.MustF64("r")
    69  }
    70  
    71  func (r logNormalRiskModelRow) sigma() float64 {
    72  	return r.row.MustF64("sigma")
    73  }