/*
 Copyright (C) 2003, 2004 Ferdinando Ametrano

 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it under the
 terms of the QuantLib license.  You should have received a copy of the
 license along with this program; if not, please email quantlib-dev@lists.sf.net
 The license is also available online at http://quantlib.org/html/license.html

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
*/
#include <ql/Instruments/oneassetstrikedoption.hpp>
#include"compoundoption.h"

namespace QuantLib {

    CompoundOption::CompoundOption(
        Option::Type compoundType,
		Date compoundExpiration,
        Real compoundStrike,
        const boost::shared_ptr<BlackScholesProcess>& stochProc,
        const boost::shared_ptr<StrikedTypePayoff>& payoff,
        const boost::shared_ptr<Exercise>& exercise,
        const boost::shared_ptr<PricingEngine>& engine)
    : OneAssetStrikedOption(stochProc, payoff, exercise, engine),
      compoundType_(compoundType), 
	  compoundExpiration_(compoundExpiration),
	  compoundStrike_(compoundStrike)
	{ };

    void CompoundOption::setupArguments(Arguments* args) const {

        OneAssetStrikedOption::setupArguments(args);

        CompoundOption::arguments* moreArgs =
            dynamic_cast<CompoundOption::arguments*>(args);
        QL_REQUIRE(moreArgs != 0, "wrong argument type");
        moreArgs->compoundType = compoundType_;
        moreArgs->compoundExpiration = compoundExpiration_;
        moreArgs->compoundStrike = compoundStrike_;
    
    }

    void CompoundOption::arguments::validate() const {

        #if defined(QL_PATCH_MSVC6)
        OneAssetStrikedOption::arguments copy = *this;
        copy.validate();
        #else
        OneAssetStrikedOption::arguments::validate();
        #endif

        QL_REQUIRE(Integer(compoundType) != -1, "unspecified average type");

        
    }
}