示例#1
0
        public double value(IPath path)
        {
            Utils.QL_REQUIRE(!(path as Path).empty(), () => "the path cannot be empty");

            TimeGrid doubleGrid    = (path as Path).timeGrid();
            int      endIndex      = doubleGrid.closestIndex(lookbackEnd_);
            double   terminalPrice = (path as Path).back();
            double   strike;

            switch (payoff_.optionType())
            {
            case Option.Type.Call:
                strike = (path as Path).values().GetRange(0, endIndex).Min();
                break;

            case Option.Type.Put:
                strike = (path as Path).values().GetRange(0, endIndex).Max();
                break;

            default:
                strike = 0.0;
                Utils.QL_FAIL("unknown option type");
                break;
            }

            return(payoff_.value(terminalPrice, strike) * discount_);
        }
示例#2
0
        public double value(IPath path)
        {
            Utils.QL_REQUIRE(!(path as Path).empty(), () => "the path cannot be empty");

            TimeGrid doubleGrid = (path as Path).timeGrid();
            int      startIndex = doubleGrid.closestIndex(lookbackStart_);
            double   underlying;

            switch (payoff_.optionType())
            {
            case Option.Type.Put:
                underlying = (path as Path).values().GetRange(startIndex, (path as Path).values().Count - startIndex).Min();
                break;

            case Option.Type.Call:
                underlying = (path as Path).values().GetRange(startIndex, (path as Path).values().Count - startIndex).Max();
                break;

            default:
                underlying = 0.0;
                Utils.QL_FAIL("unknown option type");
                break;
            }

            return(payoff_.value(underlying) * discount_);
        }