コード例 #1
0
 public QuantoVanillaOption(Payoff payoff, Exercise exercise) : this(NQuantLibcPINVOKE.new_QuantoVanillaOption(Payoff.getCPtr(payoff), Exercise.getCPtr(exercise)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
コード例 #2
0
 public ContinuousAveragingAsianOption(Average.Type averageType, Payoff payoff, Exercise exercise) : this(NQuantLibcPINVOKE.new_ContinuousAveragingAsianOption((int)averageType, Payoff.getCPtr(payoff), Exercise.getCPtr(exercise)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
コード例 #3
0
 public DividendVanillaOption(Payoff payoff, Exercise exercise, DateVector dividendDates, DoubleVector dividends) : this(NQuantLibcPINVOKE.new_DividendVanillaOption(Payoff.getCPtr(payoff), Exercise.getCPtr(exercise), DateVector.getCPtr(dividendDates), DoubleVector.getCPtr(dividends)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
コード例 #4
0
 public ForwardVanillaOption(double moneyness, Date resetDate, Payoff payoff, Exercise exercise) : this(NQuantLibcPINVOKE.new_ForwardVanillaOption(moneyness, Date.getCPtr(resetDate), Payoff.getCPtr(payoff), Exercise.getCPtr(exercise)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
コード例 #5
0
 public VanillaSwingOption(Payoff payoff, SwingExercise ex, uint minExerciseRights, uint maxExerciseRights) : this(NQuantLibcPINVOKE.new_VanillaSwingOption(Payoff.getCPtr(payoff), SwingExercise.getCPtr(ex), minExerciseRights, maxExerciseRights), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
コード例 #6
0
 public BlackCalculator(Payoff payoff, double forward, double stdDev) : this(NQuantLibcPINVOKE.new_BlackCalculator__SWIG_1(Payoff.getCPtr(payoff), forward, stdDev), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
コード例 #7
0
ファイル: Pricers.cs プロジェクト: songgaoxian/Advanced_C
 public BrownianBridgePricer(Payoff payoff, Func <double> discounter, GBM stochasticDE, double step) : base(payoff, discounter)
 {
     price = sum = sum2 = 0.0; NSim = 0;
     rand  = new Random();
     dt    = step;
     sde   = stochasticDE;
 }
コード例 #8
0
 public AverageBasketPayoff(Payoff p, uint n) : this(NQuantLibcPINVOKE.new_AverageBasketPayoff__SWIG_1(Payoff.getCPtr(p), n), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
コード例 #9
0
 public AverageBasketPayoff(Payoff p, QlArray a) : this(NQuantLibcPINVOKE.new_AverageBasketPayoff__SWIG_0(Payoff.getCPtr(p), QlArray.getCPtr(a)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
コード例 #10
0
 //Smoothing as describe in Orc quant guide.
 private void Smooth(string str, ITree spotTree)
 {
     if (str != null)
     {
         double dt = spotTree.Tau / spotTree.Gridsteps;
         if ((str.ToLower() == "y") | (str.ToLower() == "yes"))
         {
             int centre = 0;
             int k, j;
             int idx = Gridsteps - 1;
             for (k = 1; spotTree.GetSpotMatrix(idx, k - 1) <= Strike &&
                  spotTree.GetSpotMatrix(idx, k) <= Strike &&
                  k <= Gridsteps - 1; k++)
             {
             }
             if (k == 1)
             {
                 centre = 2;
             }
             else if (k >= Gridsteps - 1)
             {
                 centre = Gridsteps - 2;
             }
             else if (k <= Gridsteps - 2 && (k > 1))
             {
                 if (Math.Abs(spotTree.GetSpotMatrix(idx, k - 2) / Strike - 1) >
                     Math.Abs(spotTree.GetSpotMatrix(idx, k + 1) / Strike - 1))
                 {
                     centre = k;
                 }
                 else
                 {
                     centre = k - 1;
                 }
             }
             for (j = centre - 1; j <= centre + 1; j++)
             {
                 double temp;
                 if (Payoff.ToLower() == "c" || (Payoff.ToLower() == "call"))
                 {
                     //temp = BSprice(SpotTree.Get_SpotMatrix(idx, j)
                     //, dt, Strike, get_r(idx), SpotTree.sig, "C");
                     double fwd = spotTree.GetSpotMatrix(idx, j) - spotTree.GetDiv(idx);
                     fwd *= Math.Exp(spotTree.GetR(idx) * dt);
                     temp = BSprice(fwd, dt, Strike, spotTree.GetR(idx), spotTree.Sig, "C");
                     SetPriceMatrix(idx, j, temp);
                 }
                 else if ((Payoff.ToLower() == "p") || (Payoff.ToLower() == "put"))
                 {
                     //temp = BSprice(SpotTree.Get_SpotMatrix(idx, j)
                     //, dt, Strike, get_r(idx), SpotTree.sig, "P");
                     double fwd = spotTree.GetSpotMatrix(idx, j) - spotTree.GetDiv(idx);
                     fwd *= Math.Exp(spotTree.GetR(idx) * dt);
                     temp = BSprice(fwd, dt, Strike, spotTree.GetR(idx), spotTree.Sig, "P");
                     SetPriceMatrix(idx, j, temp);
                 }
             }
         }
     }
 }
コード例 #11
0
 public MinBasketPayoff(Payoff p) : this(NQuantLibcPINVOKE.new_MinBasketPayoff(Payoff.getCPtr(p)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
コード例 #12
0
ファイル: Builder.cs プロジェクト: songgaoxian/Advanced_C
    private IPricer GetPricer(Payoff payoff, Func <double> discounter)
    {
        // Choice here
        IPricer op = new EuropeanPricer(payoff, discounter);

        path   += op.ProcessPath;
        finish += op.PostProcess;

        // Payoff payoff2 = x => Math.Max(0.0, x - K);
        Payoff fixedStrikePayoff = x => Math.Max(0.0, K - x);

        /*    IPricer op2 = new EuropeanPricer(payoff2, discounter);
         *  path += op2.ProcessPath;
         *  finish += op2.PostProcess;*/


        //  Payoff fixedStrikePayoff = x => Math.Max(0.0, x - K);
        Payoff  ArithmeticAverage = A => Math.Max(0.0, A - K);
        IPricer op3 = new AsianPricer(ArithmeticAverage, discounter);

        path   += op3.ProcessPath;
        finish += op3.PostProcess;

        /*   IPricer op4 = new LSMPricer(payoff2, discounter, 10, 10, 60.0);
         * path += op4.ProcessPath;
         * finish += op4.PostProcess;*/

        return(op);
    }
コード例 #13
0
 public bool PayOff(Payoff payoff)
 {
     using (var dbContext = new TextLandDbContext())
     {
         dbContext.Users.Attach(payoff.RequestingUser);
         var newPayoff = dbContext.Payoffs.Add(payoff);
         dbContext.SaveChanges();
         return((newPayoff != null) ? true : false);
     }
 }
コード例 #14
0
        //Make grid passing in a tree object.
        public void MakeGrid(ITree spotTree)
        {
            Gridsteps = spotTree.Gridsteps;
            EmptyArrays();
            MakeArrays();
            FillRates(spotTree);
            TermValue(spotTree);
            FillP(spotTree);
            PreTermValue(spotTree);
            Smooth(Smoothing, spotTree);

            //Iterate backward through tree to price American or Euro calls or puts.

            double temp;
            double dt = spotTree.Tau / spotTree.Gridsteps;

            if ((Style.ToLower() == "a") | (Style.ToLower() == "american"))
            {
                for (int i = Gridsteps - 2; i >= 0; i--)
                {
                    for (int j = 0; j <= i; j++)
                    {
                        if ((Payoff.ToLower() == "c") | (Payoff.ToLower() == "call"))
                        {
                            temp = Math.Max(Math.Exp(-spotTree.GetR(i) * dt) * (GetP(i) *
                                                                                GetPriceMatrix(i + 1, j + 1) + (1 - GetP(i)) *
                                                                                GetPriceMatrix(i + 1, j)), spotTree.GetSpotMatrix(i, j)
                                            - Strike);
                            SetPriceMatrix(i, j, temp);
                        }
                        else if ((Payoff.ToLower() == "p") | (Payoff.ToLower() == "put"))
                        {
                            temp = Math.Max(Math.Exp(-spotTree.GetR(i) * dt) * (GetP(i) *
                                                                                GetPriceMatrix(i + 1, j + 1) + (1 - GetP(i)) *
                                                                                GetPriceMatrix(i + 1, j)), Strike - spotTree.GetSpotMatrix(i, j));
                            SetPriceMatrix(i, j, temp);
                        }
                    }
                }
            }
            else if ((Style.ToLower() == "e") | (Style.ToLower() == "european"))
            {
                for (int i = Gridsteps - 2; i >= 0; i--)
                {
                    for (int j = 0; j <= i; j++)
                    {
                        temp = Math.Exp(-spotTree.GetR(i) * dt) * (GetP(i) *
                                                                   GetPriceMatrix(i + 1, j + 1) + (1 - GetP(i)) *
                                                                   GetPriceMatrix(i + 1, j));
                        SetPriceMatrix(i, j, temp);
                    }
                }
            }
        }
コード例 #15
0
        public Payoff payoff()
        {
            global::System.IntPtr cPtr = NQuantLibcPINVOKE.Option_payoff(swigCPtr);
            Payoff ret = (cPtr == global::System.IntPtr.Zero) ? null : new Payoff(cPtr, true);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
コード例 #16
0
        /// <summary>
        /// Makes the grid.
        /// </summary>
        private void MakeGrid()
        {
            EmptyArrays();
            MakeArrays();
            TermValue();
            PreTermValue();
            Smooth(Smoothing);
            //Iterate backward through tree to price American or Euro calls or puts.
            int    n    = Tree.Columns;
            double _tau = Tree.Time;
            double temp = 0;
            double dt   = _tau / Tree.Columns;

            if ((Style.ToLower() == "a") | (Style.ToLower() == "american"))
            {
                for (int i = n - 2; i >= 0; i--)
                {
                    for (int j = 0; j <= i; j++)
                    {
                        if ((Payoff.ToLower() == "c") | (Payoff.ToLower() == "call"))
                        {
                            temp = Math.Max(Math.Exp(-Tree.Rate(i) * dt) * (GetP(i) *
                                                                            GetPriceMatrix(i + 1, j + 1) + (1 - GetP(i)) *
                                                                            GetPriceMatrix(i + 1, j)), Tree.Underlying(i, j)
                                            - Strike);
                            SetPriceMatrix(i, j, temp);
                        }
                        else if ((Payoff.ToLower() == "p") | (Payoff.ToLower() == "put"))
                        {
                            temp = Math.Max(Math.Exp(-Tree.Rate(i) * dt) * (GetP(i) *
                                                                            GetPriceMatrix(i + 1, j + 1) + (1 - GetP(i)) *
                                                                            GetPriceMatrix(i + 1, j)), Strike - Tree.Underlying(i, j));
                            SetPriceMatrix(i, j, temp);
                        }
                    }
                }
            }
            else if ((Style.ToLower() == "e") | (Style.ToLower() == "european"))
            {
                for (int i = n - 2; i >= 0; i--)
                {
                    for (int j = 0; j <= i; j++)
                    {
                        temp = Math.Exp(-Tree.Rate(i) * dt) * (GetP(i) *
                                                               GetPriceMatrix(i + 1, j + 1) + (1 - GetP(i)) *
                                                               GetPriceMatrix(i + 1, j));
                        SetPriceMatrix(i, j, temp);
                    }
                }
            }
        }
コード例 #17
0
ファイル: Builder.cs プロジェクト: songgaoxian/Advanced_C
    public Tuple <ISde, FdmBase, IRng> Parts()
    { // V2, parts initialised from the inside
        // Get the SDE
        ISde    sde = GetSde();
        IRng    rng = GetRng();
        FdmBase fdm = GetFdm(sde);

        Payoff payoff = x => Math.Max(0.0, K - x);
        //Payoff payoff = x => Math.Max(0.0, x - K);
        Func <double> discounter = () => Math.Exp(-r * T);
        IPricer       pricer     = GetPricer(payoff, discounter);

        return(new Tuple <ISde, FdmBase, IRng>(sde, fdm, rng));
    }
コード例 #18
0
ファイル: Utilities.cs プロジェクト: mikaboz/QLNet
        public static String payoffTypeToString(Payoff h)
        {
            object hd = null;

            hd = h as PlainVanillaPayoff;
            if (hd != null)
            {
                return("plain-vanilla");
            }
            hd = h as CashOrNothingPayoff;
            if (hd != null)
            {
                return("cash-or-nothing");
            }
            hd = h as AssetOrNothingPayoff;
            if (hd != null)
            {
                return("asset-or-nothing");
            }
            hd = h as SuperSharePayoff;
            if (hd != null)
            {
                return("super-share");
            }
            hd = h as SuperFundPayoff;
            if (hd != null)
            {
                return("super-fund");
            }
            hd = h as PercentageStrikePayoff;
            if (hd != null)
            {
                return("percentage-strike");
            }
            hd = h as GapPayoff;
            if (hd != null)
            {
                return("gap");
            }
            hd = h as FloatingTypePayoff;
            if (hd != null)
            {
                return("floating-type");
            }

            Utils.QL_FAIL("unknown payoff type");
            return(String.Empty);
        }
コード例 #19
0
ファイル: Program.cs プロジェクト: HubertNormandin/QRNGDotNet
        public double Run(int iter, Payoff payoff)
        {
            int             it = iter;
            ParallelOptions parallel_options = new ParallelOptions {
                MaxDegreeOfParallelism = 16
            };
            double sum = 0.0;


            Parallel.For(0, iter, parallel_options, (i) =>
            {
                ParallelOperation.Add(ref sum, payoff(this.param, this.mc.Next()));
            });

            return(sum / iter);
        }
コード例 #20
0
ファイル: Builder.cs プロジェクト: songgaoxian/Advanced_C
    private IPricer GetPricer(Payoff payoff, Func <double> discounter)
    {
        // Choice here
        //   IPricer op = new EuropeanPricer(payoff, discounter);
        //  path += op.ProcessPath;
        //   finish += op.PostProcess;

        //Payoff payoff2 = x => Math.Max(0.0, x - K);
        Payoff  payoff2 = x => Math.Max(0.0, K - x);
        IPricer op2     = new EuropeanPricer(payoff2, discounter);

        path   += op2.ProcessPath;
        finish += op2.PostProcess;

        return(op2);
    }
コード例 #21
0
        /// <summary>
        /// Gets the vega.
        /// </summary>
        /// <returns></returns>
        public double GetVega()
        {
            double             spot = Tree.Underlying(0, 0);
            double             _tau = Tree.Time;
            BinomialTreePricer lhs1 = new BinomialTreePricer(spot, Strike, Payoff.ToLower()[0] == 'p', _tau, 0.99 * _vol, Tree.Columns, _flatFlag, Style, Smoothing, _ratedays, _rateamts, _divdays, _divamts, _treeType);
            BinomialTreePricer lhs2 = new BinomialTreePricer(spot, Strike, Payoff.ToLower()[0] == 'p', _tau, 1.01 * _vol, Tree.Columns, _flatFlag, Style, Smoothing, _ratedays, _rateamts, _divdays, _divamts, _treeType);
            double             P1   = lhs1.GetPrice();
            double             P2   = lhs2.GetPrice();
            double             vega = 0.0;

            if (_vol != 0)
            {
                vega = 0.01 * (P2 - P1) / (2 * 0.01 * _vol);
            }
            return(vega);
        }
コード例 #22
0
ファイル: T_BasketOption.cs プロジェクト: tzhdingli/qlnet
        public BasketPayoff basketTypeToPayoff(BasketType basketType, Payoff p)
        {
            switch (basketType)
            {
            case BasketType.MinBasket:
                return(new MinBasketPayoff(p));

            case BasketType.MaxBasket:
                return(new MaxBasketPayoff(p));

            case BasketType.SpreadBasket:
                return(new SpreadBasketPayoff(p));
            }
            Utils.QL_FAIL("unknown basket option type");
            return(null);
        }
コード例 #23
0
        /// <summary>
        /// Gets the vega.
        /// </summary>
        /// <returns></returns>
        public double GetVega()
        {
            double             spot = Tree.Underlying(0, 0);
            double             tau  = Tree.Time;
            BinomialTreePricer lhs1 = new BinomialTreePricer(spot, Strike, Payoff.ToLower()[0] == 'p', tau, 0.99 * _volatility, Tree.Columns, _flatFlag, Style, Smoothing, _rateDays, _rateAmounts, _dividendDays, _dividendAmounts, _treeType);
            BinomialTreePricer lhs2 = new BinomialTreePricer(spot, Strike, Payoff.ToLower()[0] == 'p', tau, 1.01 * _volatility, Tree.Columns, _flatFlag, Style, Smoothing, _rateDays, _rateAmounts, _dividendDays, _dividendAmounts, _treeType);
            double             p1   = lhs1.GetPrice();
            double             p2   = lhs2.GetPrice();
            double             vega = 0.0;

            if (_volatility != 0)
            {
                vega = 0.01 * (p2 - p1) / (2 * 0.01 * _volatility);
            }
            return(vega);
        }
コード例 #24
0
        protected Forward(DayCounter dayCounter, Calendar calendar, BusinessDayConvention businessDayConvention,
                          int settlementDays, Payoff payoff, Date valueDate, Date maturityDate,
                          Handle <YieldTermStructure> discountCurve)
        {
            dayCounter_            = dayCounter;
            calendar_              = calendar;
            businessDayConvention_ = businessDayConvention;
            settlementDays_        = settlementDays;
            payoff_        = payoff;
            valueDate_     = valueDate;
            maturityDate_  = maturityDate;
            discountCurve_ = discountCurve;

            maturityDate_ = calendar_.adjust(maturityDate_, businessDayConvention_);

            Settings.registerWith(update);
            discountCurve_.registerWith(update);
        }
コード例 #25
0
ファイル: UsersService.cs プロジェクト: aisaa198/TextLand
        public bool PayOff(int userId)
        {
            var user = _usersRepository.GetUserById(userId);

            if (user == null || user.AccountForCompletedOrders <= 0)
            {
                return(false);
            }

            var payoff = new Payoff()
            {
                RequestingUser = user,
                Value          = user.AccountForCompletedOrders
            };

            ResetAccount(user); //to chcę stąd wywalić i zrobić w inny sposób
            return(_usersRepository.PayOff(payoff));
        }
コード例 #26
0
        /// <summary>
        /// Gets the gamma.
        /// </summary>
        /// <returns></returns>
        public double GetGamma()
        {
            double             spot  = Tree.Underlying(0, 0);
            int                steps = Tree.Columns + 2;
            double             tau   = Tree.Time * (1 + 2 / steps);
            BinomialTreePricer clone = new BinomialTreePricer(spot, Strike, Payoff.ToLower()[0] == 'p', tau, _volatility, steps, _flatFlag, Style, Smoothing, _rateDays, _rateAmounts, _dividendDays, _dividendAmounts, _treeType);

            double[] s = new double[3];
            double[] c = new double[3];
            for (int i = 0; i <= 2; ++i)
            {
                s[i] = clone.Tree.Underlying(2, i);
                c[i] = clone.GetPriceMatrix(2, i);
            }
            double gamma = 2 * (s[0] * (c[1] - c[2]) + s[1] * (c[2] - c[0]) + s[2] * (c[0] - c[1]))
                           / (s[1] - s[0]) / (s[2] - s[0]) / (s[2] - s[1]);

            return(gamma);
        }
コード例 #27
0
        /// <summary>
        /// Gets the gamma.
        /// </summary>
        /// <returns></returns>
        public double GetGamma()
        {
            double             spot  = Tree.Underlying(0, 0);
            int                steps = Tree.Columns + 2;
            double             tau   = Tree.Time * (1 + 2 / steps);
            BinomialTreePricer clone = new BinomialTreePricer(spot, Strike, Payoff.ToLower()[0] == 'p', tau, _vol, steps, _flatFlag, Style, Smoothing, _ratedays, _rateamts, _divdays, _divamts, _treeType);

            double[] S = new double[3];
            double[] C = new double[3];
            for (int i = 0; i <= 2; ++i)
            {
                S[i] = clone.Tree.Underlying(2, i);
                C[i] = clone.GetPriceMatrix(2, i);
            }
            double gamma = 2 * (S[0] * (C[1] - C[2]) + S[1] * (C[2] - C[0]) + S[2] * (C[0] - C[1]))
                           / (S[1] - S[0]) / (S[2] - S[0]) / (S[2] - S[1]);

            return(gamma);
        }
コード例 #28
0
ファイル: DescilMturkService.cs プロジェクト: stwehrli/Segreg
        /// <summary>
        /// Transfer Payoff to the DeSciL AMT Service 
        /// </summary>
        /// <param name="accessCode">AccessCode of Turker</param>
        /// <param name="bonus">Exit Code of Turker</param>
        /// <returns>Service Response as JSON string</returns>
        public string AddPayoff(string accessCode, double bonus)
        {
            var payoff = new Payoff
            {
                AccessCode = accessCode,
                Bonus = bonus,
                BonusReason = ""
            };

            var contract = new PostPayoffContract
            {
                Operation = "PostPayoffs",
                ServiceKey = _serviceKey,
                ProjectCode = _projectCode
            };

            contract.Payoffs.Add(payoff);
            string json =  JsonConvert.SerializeObject(contract);
            return Post(json);
        }
コード例 #29
0
 //Assign terminal payoff condition.
 private void TermValue(ITree spotTree)
 {
     if (spotTree != null)
     {
         for (int j = 0; j <= Gridsteps; j++)
         {
             double temp;
             Payoff = Payoff.ToLower();
             if ((Payoff == "c") | (Payoff == "call"))
             {
                 temp = Math.Max(spotTree.GetSpotMatrix(Gridsteps, j) - Strike, 0);
                 SetPriceMatrix(Gridsteps, j, temp);
             }
             else if ((Payoff.ToLower() == "p") | (Payoff.ToLower() == "put"))
             {
                 temp = Math.Max(Strike - spotTree.GetSpotMatrix(Gridsteps, j), 0);
                 SetPriceMatrix(Gridsteps, j, temp);
             }
         }
     }
 }
コード例 #30
0
        private double Bisection(double prem, double fwdPrice)
        {
            double right = 0.75;
            double left  = 0.35;
            double mid;
            var    cp         = Payoff.ToLower() == "c" ? 1 : -1;
            int    days       = Expiry.Subtract(Today).Days;
            double t          = days / 365.0;
            var    priceClone = (AmOptionAnalytics)Clone();

            if (fwdPrice <= 0 || Strike <= 0 || t <= 0 || prem <= 0)
            {
                return(0);
            }
            double df = Convert.ToDouble(RateCurve.GetDf(days));

            if (prem < Math.Max(cp * df * (fwdPrice - priceClone.Strike), 0))
            {
                throw new System.Exception("No solution for volatility");
            }
            do
            {
                mid            = (right + left) / 2;
                priceClone.Sig = left;
                double fleft = priceClone.Price() - prem;
                priceClone.Sig = right;
                double fright = priceClone.Price() - prem;
                priceClone.Sig = mid;
                double fmid = priceClone.Price() - prem;
                if (fleft * fmid < 0)
                {
                    right = mid;
                }
                else if (fright * fmid < 0)
                {
                    left = mid;
                }
            } while (Math.Abs(right - left) > 2 * Eps);
            return(mid);
        }
コード例 #31
0
ファイル: Pricer.cs プロジェクト: zhangz/Highlander.Net
        //Assign values at Gridsteps-1 node.
        private void PreTermValue(Tree SpotTree)
        {
            if (SpotTree != null)
            {
                double temp = 0;
                double dt   = SpotTree.Tau / SpotTree.Gridsteps;
                int    idx  = Gridsteps - 1;

                for (int j = 0; j <= Gridsteps - 1; j++)
                {
                    if ((Style.ToLower() == "a") | (Style.ToLower() == "american"))
                    {
                        if ((Payoff.ToLower() == "c") | (Payoff.ToLower() == "call"))
                        {
                            temp = Math.Max(Math.Exp(-SpotTree.GetR(idx) * dt) * (Get_P(idx) *
                                                                                  Get_PriceMatrix(idx + 1, j + 1) + (1 - Get_P(idx)) *
                                                                                  Get_PriceMatrix(idx + 1, j)), SpotTree.GetSpotMatrix(idx, j)
                                            - Strike);
                            Set_PriceMatrix(idx, j, temp);
                        }
                        else if ((Payoff.ToLower() == "p") | (Payoff.ToLower() == "put"))
                        {
                            temp = Math.Max(Math.Exp(-SpotTree.GetR(idx) * dt) * (Get_P(idx) *
                                                                                  Get_PriceMatrix(idx + 1, j + 1) + (1 - Get_P(idx)) *
                                                                                  Get_PriceMatrix(idx + 1, j)), -SpotTree.GetSpotMatrix(idx, j)
                                            + Strike);
                            Set_PriceMatrix(idx, j, temp);
                        }
                    }
                    else if ((Style.ToLower() == "e") | (Style.ToLower() == "european"))
                    {
                        temp = Math.Exp(-SpotTree.GetR(idx) * dt) * (Get_P(idx) *
                                                                     Get_PriceMatrix(idx + 1, j + 1) + (1 - Get_P(idx)) *
                                                                     Get_PriceMatrix(idx + 1, j));
                        Set_PriceMatrix(idx, j, temp);
                    }
                }
            }
        }
コード例 #32
0
ファイル: AverageBasketPayoff.cs プロジェクト: minikie/test
 public AverageBasketPayoff(Payoff p, uint n) : this(NQuantLibcPINVOKE.new_AverageBasketPayoff__SWIG_1(Payoff.getCPtr(p), n), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
コード例 #33
0
ファイル: AverageBasketPayoff.cs プロジェクト: minikie/test
 public AverageBasketPayoff(Payoff p, QlArray a) : this(NQuantLibcPINVOKE.new_AverageBasketPayoff__SWIG_0(Payoff.getCPtr(p), QlArray.getCPtr(a)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
コード例 #34
0
ファイル: BarrierOption.cs プロジェクト: minikie/test
 public BarrierOption(Barrier.Type barrierType, double barrier, double rebate, Payoff payoff, Exercise exercise) : this(NQuantLibcPINVOKE.new_BarrierOption((int)barrierType, barrier, rebate, Payoff.getCPtr(payoff), Exercise.getCPtr(exercise)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
コード例 #35
0
 public ContinuousAveragingAsianOption(Average.Type averageType, Payoff payoff, Exercise exercise) : this(NQuantLibcPINVOKE.new_ContinuousAveragingAsianOption((int)averageType, Payoff.getCPtr(payoff), Exercise.getCPtr(exercise)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
コード例 #36
0
ファイル: EuropeanOption.cs プロジェクト: minikie/test
 public EuropeanOption(Payoff payoff, Exercise exercise) : this(NQuantLibcPINVOKE.new_EuropeanOption(Payoff.getCPtr(payoff), Exercise.getCPtr(exercise)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
コード例 #37
0
ファイル: Payoff.cs プロジェクト: minikie/test
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Payoff obj) {
   return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }
コード例 #38
0
ファイル: MaxBasketPayoff.cs プロジェクト: minikie/test
 public MaxBasketPayoff(Payoff p) : this(NQuantLibcPINVOKE.new_MaxBasketPayoff(Payoff.getCPtr(p)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
コード例 #39
0
ファイル: BlackCalculator.cs プロジェクト: minikie/test
 public BlackCalculator(Payoff payoff, double forward, double stdDev) : this(NQuantLibcPINVOKE.new_BlackCalculator__SWIG_1(Payoff.getCPtr(payoff), forward, stdDev), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
コード例 #40
0
ファイル: DividendVanillaOption.cs プロジェクト: minikie/test
 public DividendVanillaOption(Payoff payoff, Exercise exercise, DateVector dividendDates, DoubleVector dividends) : this(NQuantLibcPINVOKE.new_DividendVanillaOption(Payoff.getCPtr(payoff), Exercise.getCPtr(exercise), DateVector.getCPtr(dividendDates), DoubleVector.getCPtr(dividends)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
コード例 #41
0
 public QuantoForwardVanillaOption(double moneyness, Date resetDate, Payoff payoff, Exercise exercise) : this(NQuantLibcPINVOKE.new_QuantoForwardVanillaOption(moneyness, Date.getCPtr(resetDate), Payoff.getCPtr(payoff), Exercise.getCPtr(exercise)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }
コード例 #42
0
 public DiscreteAveragingAsianOption(Average.Type averageType, double runningAccumulator, uint pastFixings, DateVector fixingDates, Payoff payoff, Exercise exercise) : this(NQuantLibcPINVOKE.new_DiscreteAveragingAsianOption((int)averageType, runningAccumulator, pastFixings, DateVector.getCPtr(fixingDates), Payoff.getCPtr(payoff), Exercise.getCPtr(exercise)), true) {
   if (NQuantLibcPINVOKE.SWIGPendingException.Pending) throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
 }