コード例 #1
0
        /// <summary>
        /// Returns the base score of the CVSS object.
        /// </summary>
        /// <exception cref="System.ArgumentException">Thrown when vector is not valid.</exception>
        public double BaseScore()
        {
            if (!IsValid())
            {
                throw new ArgumentException();
            }

            return(BaseMetric.Score());
        }
コード例 #2
0
        /// <summary>
        /// Create instance of the neural net with parameters
        /// </summary>
        /// <param name="optimizer"></param>
        /// <param name="cost"></param>
        /// <param name="metric"></param>
        public NeuralNet(BaseOptimizer optimizer, BaseCost cost, BaseMetric metric = null)
        {
            Layers          = new List <BaseLayer>();
            TrainingLoss    = new List <double>();
            TrainingMetrics = new List <double>();

            this.Optimizer = optimizer != null ? optimizer : throw new Exception("Need optimizer");
            this.Cost      = cost != null ? cost : throw new Exception("Need cost");
            Metric         = metric;
        }
コード例 #3
0
        /// <summary>
        /// Returns the selected value for a metric.
        /// </summary>
        /// <returns>
        /// Returns the selected value or empty string if metric is not found.
        /// </returns>
        /// <example>
        /// <code>
        /// var selected = cvss.SelectedValue("Access Vector");
        /// returns "Network"
        /// </code>
        /// </example>
        /// <param name="metric">A valid metric e.g. "Access Vector", "Authentication", "Attack Vector".</param>
        /// <exception cref="System.ArgumentException">Thrown when vector is not valid.</exception>
        public string SelectedMetric(string metric)
        {
            if (!IsValid())
            {
                throw new ArgumentException();
            }

            if (!String.IsNullOrEmpty(BaseMetric.SelectedValue(metric)))
            {
                return(BaseMetric.SelectedValue(metric));
            }
            if (!String.IsNullOrEmpty(TemporalMetric.SelectedValue(metric)))
            {
                return(TemporalMetric.SelectedValue(metric));
            }
            if (!String.IsNullOrEmpty(EnvironmentalMetric.SelectedValue(metric)))
            {
                return(EnvironmentalMetric.SelectedValue(metric));
            }
            return("");
        }
コード例 #4
0
 public void Compile(BaseOptimizer optimizer, LossType loss, MetricType metric)
 {
     OptimizerFn = optimizer;
     LossFn      = BaseLoss.Get(loss);
     MetricFn    = BaseMetric.Get(metric);
 }
コード例 #5
0
        private AssetFxMCModel GetSut(bool expensiveFutures, BaseMetric baseMetric = BaseMetric.PV)
        {
            var buildDate = DateTime.Parse("2018-10-04");
            var usd       = TestProviderHelper.CurrencyProvider["USD"];

            TestProviderHelper.CalendarProvider.Collection.TryGetCalendar("NYC", out var usdCal);
            var dfCurve = new IrCurve(new[] { buildDate, buildDate.AddDays(1000) }, new[] { 0.0, 0.0 }, buildDate, "disco", Math.Interpolation.Interpolator1DType.Linear, usd, "DISCO");

            var comCurve = new PriceCurve(buildDate, new[] { buildDate, buildDate.AddDays(15), buildDate.AddDays(100) }, new[] { 100.0, 100.0, 100.0 }, PriceCurveType.NYMEX, TestProviderHelper.CurrencyProvider)
            {
                Name    = "CL",
                AssetId = "CL"
            };
            var comSurface = new ConstantVolSurface(buildDate, 0.32)
            {
                AssetId = "CL"
            };
            var fModel = new FundingModel(buildDate, new Dictionary <string, IrCurve> {
                { "DISCO", dfCurve }
            }, TestProviderHelper.CurrencyProvider, TestProviderHelper.CalendarProvider);
            var fxM = new FxMatrix(TestProviderHelper.CurrencyProvider);

            fxM.Init(usd, buildDate, new Dictionary <Currency, double>(), new List <FxPair>(), new Dictionary <Currency, string> {
                { usd, "DISCO" }
            });
            fModel.SetupFx(fxM);

            var aModel = new AssetFxModel(buildDate, fModel);

            aModel.AddVolSurface("CL", comSurface);
            aModel.AddPriceCurve("CL", comCurve);

            var product = AssetProductFactory.CreateTermAsianSwap(buildDate.AddDays(10), buildDate.AddDays(20), 99, "CL", usdCal, buildDate.AddDays(21), usd);

            product.TradeId       = "waaah";
            product.DiscountCurve = "DISCO";


            var pfolio = new Portfolio {
                Instruments = new List <IInstrument> {
                    product
                }
            };
            var creditSettings = new CreditSettings
            {
                ExposureDates = new DateTime[] { buildDate.AddDays(5), buildDate.AddDays(20), buildDate.AddDays(22) },
                Metric        = baseMetric
            };
            var settings = new McSettings
            {
                Generator                  = RandomGeneratorType.MersenneTwister,
                McModelType                = McModelType.Black,
                NumberOfPaths              = 2048,
                NumberOfTimesteps          = 1,
                ReportingCurrency          = usd,
                ExpensiveFuturesSimulation = expensiveFutures,
                Parallelize                = false,
                FuturesMappingTable        = new Dictionary <string, string> {
                    { "CL", "CL" }
                },
                CreditSettings = creditSettings
            };
            var sut = new AssetFxMCModel(buildDate, pfolio, aModel, settings, TestProviderHelper.CurrencyProvider, TestProviderHelper.FutureSettingsProvider, TestProviderHelper.CalendarProvider);

            return(sut);
        }