/*! \file generalizedOUprocess.hpp
    \brief Ornstein-Uhlenbeck process with piecewise linear coefficients
*/

#ifndef quantlib_generalized_ou_process_hpp
#define quantlib_generalized_ou_process_hpp

#include <ql/stochasticprocess.hpp>
#include <ql/models/shortrate/onefactormodel.hpp>
#include <ql/termstructures/yieldtermstructure.hpp>
#include <ql/termstructures/yield/zerocurve.hpp>
#include <ql/math/interpolations/linearinterpolation.hpp>
#include <ql/math/interpolations/loginterpolation.hpp>

namespace QuantLib {

    //! Piecewise linear Ornstein-Uhlenbeck process class
    /*! This class describes the Ornstein-Uhlenbeck process governed by
        \f[
            dx = a (level - x_t) dt + \sigma dW_t
        \f]

        \ingroup processes

		where the coefficients a and sigma are piecewise linear.
    */
    class GeneralizedOUprocess : public StochasticProcess1D {
      public:
		  GeneralizedOUprocess(const Handle<YieldTermStructure>& speedTS, 
			  const Handle<YieldTermStructure>& vol, 
			  Real x0 = 0.0, 
			  Real level = 0.0);
         //! \name StochasticProcess interface
        //@{
        Real x0() const;

        Real drift(Time t, Real x) const;
        Real diffusion(Time t, Real x) const;

        Handle<YieldTermStructure> speed() const;
        Handle<YieldTermStructure> volatility() const;
        Real level() const;

        Real expectation(Time t0, Real x0, Time dt) const;
        Real stdDeviation(Time t0, Real x0, Time dt) const;
        Real variance(Time t0, Real x0, Time dt) const;
        //@}
      private:
        Real x0_, level_;
		Handle<YieldTermStructure> speed_;
		Handle<YieldTermStructure> volatility_;
    };

}


#endif
