/*
 * (c) Copyright Christian P. Fries, Germany. All rights reserved. Contact: email@christian-fries.de.
 *
 * Created on 10.06.2004
 */
package net.finmath.montecarlo.assetderivativevaluation.products;

import java.util.Arrays;

import net.finmath.exception.CalculationException;
import net.finmath.functions.AnalyticFormulas;
import net.finmath.montecarlo.RandomVariable;
import net.finmath.montecarlo.assetderivativevaluation.AssetModelMonteCarloSimulationInterface;
import net.finmath.stochastic.RandomVariableInterface;

/**
 * This class implements a delta and delta-gamma hedged portfolio of an European option (a hedge simulator).
 * 
 * The hedge is done under the assumption of a Black Scholes Model (even if the pricing model is a different one).
 * 
 * In case of the gamma hedge and the vega hedge, note that we make the assumption that the
 * market trades these option according to Black-Scholes parameters assumed in hedging.
 * While this is a simple model, it is to some extend resonable, when we assume that the
 * hedge is done by calculating delta from a calibrated model (where the risk free rate and
 * the volatility are "market implied").
 * 
 * That said, this class evaluates the hedge portfolio given that the market implies a given
 * risk free rate and volatility, while the underlying follows a given (possibly different) stochastic
 * process.
 * 
 * @author Christian Fries
 * @version 1.3
 */
public class BlackScholesHedgedPortfolio extends AbstractAssetMonteCarloProduct {

	public enum HedgeStrategy {
		deltaHedge,
		deltaGammaHedge,
		deltaVegaHedge		
	}

	// Properties of the European option we wish to replicate
	private final double maturity;
	private final double strike;
	
	// Model assumptions for the hedge
	private final double riskFreeRate;		// Actually the same as the drift (which is not stochastic)
	private final double volatility;
	
	// Properties for the hedge option if we do a gamma hedge
	private final double hedgeOptionMaturity;
	private final double hedgeOptionStrike;
	
	private final HedgeStrategy hedgeStrategy;
	
	/**
	 * Construction of a hedge portfolio assuming a Black-Scholes model for the hedge ratios.
	 * 
	 * @param maturity		Maturity of the option we wish to replicate.
	 * @param strike		Strike of the option we wish to replicate.
	 * @param riskFreeRate	Model riskFreeRate assumption for our delta hedge.
	 * @param volatility	Model volatility assumption for our delta hedge.
	 */
	public BlackScholesHedgedPortfolio(double maturity, double strike, double riskFreeRate, double volatility) {
		super();
		this.maturity = maturity;
		this.strike = strike;
		this.riskFreeRate = riskFreeRate;
		this.volatility = volatility;

		// Do not apply gamma hedge
		this.hedgeOptionMaturity	= 0.0;
		this.hedgeOptionStrike	= 0.0;
		this.hedgeStrategy = HedgeStrategy.deltaHedge;
	}

	
	/**
	 * Construction of a delta-gamma hedge portfolio assuming a Black-Scholes model.
	 *
	 * @param maturity		Maturity of the option we wish to replicate.
	 * @param strike		Strike of the option we wish to replicate.
	 * @param riskFreeRate	Model riskFreeRate assumption for our delta hedge.
	 * @param volatility	Model volatility assumption for our delta hedge.
	 * @param hedgeOptionMaturity	Maturity of the option used in the hedge portfolio (to hedge gamma).
	 * @param hedgeOptionStrike		Strike of the option used in the hedge portfolio (to hedge gamma).
	 * @param hedgeStrategy			Specification of the hedge strategy to be used (delta, delta-gamma, etc.).
	 */
	public BlackScholesHedgedPortfolio(double maturity, double strike, double riskFreeRate, double volatility,
			double hedgeOptionMaturity, double hedgeOptionStrike, HedgeStrategy hedgeStrategy) {
		super();
		this.maturity				= maturity;
		this.strike					= strike;
		this.riskFreeRate			= riskFreeRate;
		this.volatility				= volatility;
		this.hedgeOptionMaturity	= hedgeOptionMaturity;
		this.hedgeOptionStrike		= hedgeOptionStrike;
		this.hedgeStrategy			= hedgeStrategy;
	}
	
	@Override
	public RandomVariableInterface getValue(double evaluationTime, AssetModelMonteCarloSimulationInterface model) throws CalculationException {
		
		// Ask the model for its discretization
		int timeIndexEvaluationTime	= model.getTimeIndex(evaluationTime);
		int numberOfPath			= model.getNumberOfPaths();

		/*
		 *  Going forward in time we monitor the hedge portfolio on each path.
		 */
		
		// We store the composition of the hedge portfolio (depending on the path)
		double[] amountOfUderlyingAsset		= new double[numberOfPath];
		double[] amountOfNumeraireAsset		= new double[numberOfPath];
		
		// In case of a gamma hedge, the hedge portfolio consist of additional options
		double[] amountOfHedgeOptions		= new double[numberOfPath];


		
		/*
		 *  Initialize the portfolio to zero stocks and as much cash as the Black-Scholes Model predicts we need.
		 */
		RandomVariableInterface underlyingToday = model.getAssetValue(0.0,0);
		double initialValue = underlyingToday.get(0);

		double valueOfOptionAccordingBlackScholes = 	AnalyticFormulas.blackScholesOptionValue(
				initialValue,
				riskFreeRate,
				volatility,
				maturity,
				strike);
		
		Arrays.fill(amountOfNumeraireAsset,valueOfOptionAccordingBlackScholes);
		Arrays.fill(amountOfUderlyingAsset,0.0);
		Arrays.fill(amountOfHedgeOptions,0.0);
		
		for(int timeIndex = 0; timeIndex 

Ads help maintain this website.