Пример #1
0
            public double script(ScriptFunctions sf, ScriptData sd)
            {
                double fixingValue = 0.0;
                double payoff      = 0.0;
                double yield       = 0.0;
                bool   iscalled    = false;
                double discount    = 1.0;
                int    i           = 0;

                double strike = sd.INDEX("strike")[0];

                // Go through all dates //
                for (int t = 0; t < sf.PATHNB(); t++)
                {
                    double k = sf.PATHVALUE(t);
                    if (sf.PATHTIME(t) == sd.TIME("fixing")[i] && (iscalled == false))
                    {
                        fixingValue = sf.PATHVALUE(t);
                        yield       = fixingValue / strike;
                        if (yield > 1.0)
                        {
                            iscalled = true;
                            discount = sf.DISCOUNT(sf.PATHTIME(t));

                            payoff = (1 + sd.INDEX("coupons")[i]) * 100 * discount;
                            sf.INSPOUT("ProbaCall " + i, 1.0);
                            return(payoff);
                        }
                        i++;
                    }
                }

                // if no previous payoff compute last redemption //
                fixingValue = sf.PATHVALUE();
                yield       = fixingValue / strike;
                discount    = sf.DISCOUNT();

                if ((iscalled == false) && (yield < sd.INDEX("barrier")[0]))
                {
                    payoff = yield * 100 * discount;
                    sf.INSPOUT("ProbaDown", 1.0);
                    sf.INSPOUT("AvgDown", yield);
                }
                else
                {
                    payoff = 100.0 * discount;
                    sf.INSPOUT("ProbaMid", 1.0);
                }

                // return payoff  //
                return(payoff);
            }
Пример #2
0
            public double script(ScriptFunctions sf, ScriptData sd)
            {
                double bond        = 0.0;
                double put         = 0.0;
                double binaryStrip = 0.0;
                double swap        = 0.0;

                int    i    = 0;
                double time = 0.0;

                double strike       = sd.INDEX("strike")[0];
                double couponBond   = sd.INDEX("couponBond")[0];
                double couponBinary = sd.INDEX("couponBinary")[0];
                double barrierDown  = sd.INDEX("barrierDown")[0];

                double recovery = sd.INDEX("recovery")[0];
                double maturity = sd.ENDTIME("fixing");

                double div       = 0.0;
                double rf        = 0.0;
                double survpb    = 1.0;
                double survpb_m1 = 1.0;
                double vol       = 0.0;
                double s         = 0.0;

                // Go through all dates //
                for (int t = 0; t < sf.PATHNB(); t++)
                {
                    s    = sf.PATHVALUE(t);
                    time = sf.PATHTIME(t);

                    if ((time == sd.TIME("fixing")[i]) && (time != maturity))
                    {
                        bond        = 0.0;
                        put         = 0.0;
                        binaryStrip = 0.0;

                        //bond
                        for (int j = i; j < sd.TIME("fixing").Count - 1; j++)
                        {
                            bond = couponBond * sf.DISCOUNT(sd.TIME("fixing")[j]);
                        }
                        //bond += sf.DISCOUNT(maturity);
                        bond = bond / sf.DISCOUNT(time);
                        sf.INSPOUT("Bond" + i, bond);

                        //pdi
                        vol = sf.VOLATILITY(maturity - time, s);
                        rf  = sf.RISKFREERATE(maturity, time);
                        div = sf.DIVIDENDRATE(maturity, time);

                        put = sf.OPTIONPRICE(maturity, time, barrierDown, s, div, rf, vol, Option.Type.Put);
                        put = put / barrierDown;
                        sf.INSPOUT("PDI" + i, put);

                        // binary strip
                        for (int j = i; j < sd.TIME("fixing").Count - 1; j++)
                        {
                            vol = sf.VOLATILITY(sd.TIME("fixing")[j] - time, s);
                            rf  = sf.RISKFREERATE(maturity, time);
                            div = sf.DIVIDENDRATE(maturity, time);

                            binaryStrip += couponBinary / sf.DISCOUNT(time) * sf.BINARYPRICE(maturity, time, barrierDown, s, div, rf, vol, Option.Type.Call);
                        }
                        sf.INSPOUT("Binary" + i, binaryStrip);

                        // Swap
                        survpb = sf.SURVIVALPB(time);
                        swap  += (survpb_m1 - survpb) * Math.Max(0.0, recovery - bond + binaryStrip - put) * sf.DISCOUNT(time);
                        sf.INSPOUT("CondProba" + i, (survpb_m1 - survpb));
                        survpb_m1 = survpb;

                        i++;
                    }
                }

                sf.INSPOUT("yield ", s);
                // return payoff  //
                return(swap);
            }