Conditions

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Conditions

animesh
Finally after lots of hits and trials was able to figure the correct
code. This one prices vanilla options with my differential equation. Now
I was just looking for a slight change.
I just want to apply a check for each evaluation for a more exotic
payoff say Up and Out call. Let's say as soon as price breaches 120
level the option price becomes 0 (simple up and out call). I will be
using more exotic payoff's like worst of call etc for multi asset
options but at this point can someone please tell me how to apple this
simple boundary condition.

Thanks,

Animesh Saxena

Associate
(Exotic Derivatives)


class BlackScholesOperator : public TridiagonalOperator {
    public:
    BlackScholesOperator(double sigma, double nu,Rate r,unsigned int
points,double h):
    TridiagonalOperator(- (sigma*sigma/2.0) * DPlusDMinus(points,h) - nu
* DZero(points,h) + r * TridiagonalOperator::identity(points)
                                                                       
                                   
                                                                       
                                    ) {}
};

class ExerciseCondition : public StepCondition<Array> {
    public:
    ExerciseCondition(const Array& exercisingValue)
    : exercisingValue_(exercisingValue) {}
    void applyTo(Array& a, Time) const {
        for (unsigned int i = 0; i < a.size(); i++)
            a[i] = ( (a[i]>exercisingValue_[i])? a[i]:exercisingValue_[i]);
        }
    private:
    Array exercisingValue_;
};

std::vector<Time> stoppingTimes(1);

int main(int, char* []) {
   
    Option::Type type = Option::Call;
    double underlying = 100.0, strike = 100;
    Time residualTime = 1.0;
    Rate dividendYield = 0.00, riskFreeRate = 0.05;
    double volatility = 0.10;
   
    unsigned int timeSteps = 1000;
    unsigned int gridPoints = 1000;
    Array grid(gridPoints), prices(gridPoints);
    double x0 = log(underlying);
    double Delta = 4.0*volatility*pow(residualTime,0.5);
    double xMin = x0 - Delta, xMax = x0 + Delta;
    double h = (xMax-xMin)/(gridPoints-1);
    for (unsigned int i=0; i<gridPoints; i++) {
        grid[i] = xMin + i*h;
        prices[i] = exp(grid[i]);
        std::cout<<prices[i]<<"\t";
    }
   
    Array exercisingValue(gridPoints);
    for (unsigned int i=0; i<gridPoints; i++)
        exercisingValue[i] = ((prices[i]-strike)>0? prices[i]-strike:0.0);
   
    double nu = riskFreeRate - dividendYield - volatility*volatility/2.0;
    TridiagonalOperator L = BlackScholesOperator(volatility, nu,
riskFreeRate, gridPoints, h);
   
    std::vector<boost::shared_ptr<BoundaryCondition<TridiagonalOperator>
 > > BCs_;
   
//    BCs_[0] = boost::shared_ptr<BoundaryCondition<TridiagonalOperator>
 > (new NeumannBC(1,NeumannBC::Lower));
   
//    BCs_[1] = boost::shared_ptr<BoundaryCondition<TridiagonalOperator>
 > (new NeumannBC(400,NeumannBC::Upper));
   
    FiniteDifferenceModel<CrankNicolson<TridiagonalOperator> >
model(L,BCs_,stoppingTimes);    
    Array f = exercisingValue;
    model.rollback(f, residualTime, 0.0, timeSteps);
    int ik;
    ik = 100;
    std::cout<<"\n";
    for(ik=600;ik<=900;ik++)
        std::cout<<"Spots:"<<exp(grid[ik])<<"\t"<<f[ik]<<"\n";
   
   
   
}

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users