(* :Title: Monte Carlo *) (* :Context: QuantLib`MonteCarlo` *) (* :Author: Niels Elken Sønderby *) (* :Mathematica Version: 4.0 *) (* :Copyright: Copyright (C) 2003 Niels Elken Sønderby *) (* :License: This file is part of QuantLib for Mathematica, a Mathematica extension for QuantLib, a free-software/open-source financial C++ library - http://www.nielses.dk/quantlib/mma/ - http://quantlib.org/ QuantLib for Mathematica 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 ferdinando@ametrano.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. *) BeginPackage["QuantLib`MonteCarlo`", "QuantLib`Options`" (* Needs models from `Options` *) ] (* Usage messages *) MonteCarloPath::usage = "MonteCarloPath[model, length, timesteps] gives a simulated path for the given model under the risk neutral measure." Begin["`Private`"] (* Give access to QuantLib`Private` context as LinkPatterns for external program are there. Does a more elegant solution exist? *) AppendTo[$ContextPath, "QuantLib`Private`"] MonteCarloPath[model_] := MonteCarloPath[model, 1, 1000] MonteCarloPath[BlackScholesModel[s0_, riskFreeRate_, dividendYield_, volatility_], length_, timeSteps_, opts___?OptionQ] ^:= Module[{antithetic = AntitheticPaths /. {opts} /. Options[MonteCarloPath]}, qlMonteCarloPathBlackScholes[s0, riskFreeRate, dividendYield, volatility, length, timeSteps, If[antithetic,1,0]] ] MonteCarloPath[SVJDModel[underlying_, riskFreeRate_, dividendYield_, volatility_, volatilityOfVolatility_, steadyStateVolatility_, meanReversionRate_, correlationUnderlyingVolatility_, jumpIntensity_, jumpMean_, jumpStandardDeviation_], length_, timeSteps_, opts___?OptionQ] ^:= Module[{antithetic = AntitheticPaths /. {opts} /. Options[MonteCarloPath]}, nqMonteCarloPathSVJD[underlying, riskFreeRate, dividendYield, volatility, volatilityOfVolatility, steadyStateVolatility, meanReversionRate, correlationUnderlyingVolatility, jumpIntensity, jumpMean, jumpStandardDeviation, length, timeSteps, If[antithetic,1,0]] ] Options[MonteCarloPath] := { AntitheticPaths -> False } End[] EndPackage[]