예제 #1
0
        public void MonoPayoffTest(string payoffScript, IDictionary <string, object> parameters, Func <double, double> refPayoff)
        {
            DslPayoffExpression payoffExpr = DslPayoffParser.Parse(payoffScript, parameters);
            IFixingFunction     payoff     = DslPayoffCompiler.Compile(payoffExpr).First();

            var rand = new Random(4321);

            for (int i = 0; i < 100; i++)
            {
                var fixingValue = 2.0 * rand.NextDouble();
                var cpnValue    = payoff.Value(new[] { fixingValue });
                var refCpnValue = refPayoff(fixingValue);
                Assert.AreEqual(cpnValue, refCpnValue);
            }
        }
예제 #2
0
        public static IFixingFunction[] Build(string labelOfRows, Parameters parameters, string[] dslPayoffScripts)
        {
            string[] paramLabels = parameters.ColLabels.Map(s => s.ToLowerInvariant().Trim());

            var couponDatas = new DslPayoffExpression[parameters.RowLabels.Length];

            for (int row = 0; row < couponDatas.Length; row++)
            {
                object[] paramVals = parameters.Values.Row(row);
                IDictionary <string, object> couponParameters = paramLabels.ZipToDictionary(paramVals);
                couponParameters.Add(labelOfRows.ToLowerInvariant().Trim(), parameters.RowLabels[row]);

                var payoff = DslPayoffParser.Parse(dslPayoffScripts[row], couponParameters);
                couponDatas[row] = payoff;
            }

            return(DslPayoffCompiler.Compile(couponDatas));
        }