|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object Statistics.FinMath
This class contains static methods to compute functions or solve eqations * useful in basic financial mathematics. * * @author Michael J. Meyer
Constructor Summary | |
FinMath()
|
Method Summary | |
static double |
BisectionSolveBSF(double Q,
double k,
double y)
Same as NewtonSolveBSF(double, double, double) but uses continued bisection instead of
* Newton's algorithm. |
static double |
blackScholesFunction(double Q,
double k,
double Sigma)
Computes the function QN(h_+)-kN(h_-). |
static double |
bsDiscountedCallPrice(double S,
double K,
double tau,
double sigma,
double B)
Discounted Black-Scholes call price (note that current time may * not be zero). |
static double |
bsDiscountedPutPrice(double S,
double K,
double tau,
double sigma,
double B)
Discounted Black-Scholes put price (note that current time may * not be zero). |
static void |
CholeskyRoot(double[][] C,
double[][] L)
Let C be symmetric positive definite n by n matrix. |
static double |
d_minus(double Q,
double k,
double Sigma)
The quantity d_- in Margrabe's formula for the option to * exchange assets. |
static double |
d_plus(double Q,
double k,
double Sigma)
The quantity d_+ in Margrabe's formula for the option to * exchange assets S_1, S_2 (receive S_1 for kS_2). |
static double |
dBSF(double Q,
double k,
double Sigma)
Derivative of the Black-Scholes function QN(h_+)-kN(h_-) with * respect to Sigma. |
static double |
dN(double x)
Derivative of N'(x) of N(double) . |
static cern.colt.matrix.DoubleMatrix1D |
linearSystemSolution(cern.colt.matrix.DoubleMatrix2D A,
cern.colt.matrix.DoubleMatrix1D y)
Returns cern.colt.matrix.impl.DenseDoubleMatrix1D solution vector x * of the linear equation Ax=y. |
static void |
main(java.lang.String[] args)
TEST PROGRAM |
static double |
N_Inverse(double x)
The Inverse of the cumulative normal distribution function N(x). |
static double |
N_Solve(double y)
Solves the equation N(x)=y for x=x(y) using Newton's algorithm. |
static double |
N_Solve1(double y)
Solves the equation N(x)=y for x=x(y) using continued bisection. |
static double |
N(double x)
The cumulative distribution function N(x)=Prob(X<=x) of a standard normal * variable X. |
static double |
NewtonSolveBSF(double Q,
double k,
double y)
Given b > 0 solves the equation * bLackScholesFunction(Q,k,Sigma)=y for
* Sigma > 0 using Newton's algorithm. |
double |
normalDensity(double[] z)
The density of the standard multinormal distribution N(0,I). |
static void |
PlusEquals(cern.colt.matrix.DoubleMatrix1D w,
double k,
cern.colt.matrix.DoubleMatrix2D A,
boolean transposeA,
cern.colt.matrix.DoubleMatrix1D z)
Implements the vector operation w+=kAz, or w+=kA'z, * where z,w are vectors and A a matrix. |
static double |
round(double x,
int n)
rounds off the double x to n decimals. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public FinMath()
Method Detail |
public static double round(double x, int n)
rounds off the double x to n decimals.
* * @param x number to be rounded off * @param n number of decimals
public double normalDensity(double[] z)
public static double N(double x)
The cumulative distribution function N(x)=Prob(X<=x) of a standard normal * variable X.
* *It is derived from the error function erf(x)=Prob(-sqrt(2)x<=X<=sqrt(2)x) * included in the class VisualNumerics.math.Sfun.
* * @param x Any real number.
public static double d_plus(double Q, double k, double Sigma)
The quantity d_+ in Margrabe's formula for the option to * exchange assets S_1, S_2 (receive S_1 for kS_2). In this context:
* *and Sigma is the aggregate volatility of log(Q) from current * time t to the horizon T, that is, the quadratic variation
* *If Q has constant annual volatility sigma this becomes
* *where tau=T-t is time to expiry. In the case of the European call on * S_1 with strike k the asset S_2 * is the zero coupon bond maturing at call expiration.
* * @param Q The quotient S_1(t)/S_2(t) * @param k Ratio of exchange between assets (receive S_1 for kS_2). * @param Sigma Quadratic variation log(Q) _[t,T].
public static double d_minus(double Q, double k, double Sigma)
The quantity d_- in Margrabe's formula for the option to * exchange assets.
*See d_plus(double, double, double)
and replace "+Sigma/2" with "-Sigma/2".
public static double blackScholesFunction(double Q, double k, double Sigma)
Computes the function QN(h_+)-kN(h_-).
* *Useful in application of the Black-Scholes formula or Margrabe's formula * to price calls or options to exchange assets. For the option to * exchange assets S_1,S_2 we have Q=S_1(t)/S_2(t) and
* * See d_plus(double, double, double)
for information on the parameter Sigma.
* In the special case of a call on S we have S_1=S, S_2 is the zero coupon
* bond maturing at call expiry, Q the forward price of S and the forward price
* of the call can be written as
public static double dBSF(double Q, double k, double Sigma)
Derivative of the Black-Scholes function QN(h_+)-kN(h_-) with * respect to Sigma.
* * @param Q The quotient S_1(t)/S_2(t) * @param k Ratio of exchange between assets (receive S_1 for kS_2). * @param Sigma Quadratic variation log(Q) _[t,T].
public static double bsDiscountedCallPrice(double S, double K, double tau, double sigma, double B)
Discounted Black-Scholes call price (note that current time may
* not be zero). Both the current time t
and the time
* T
to expiry (from time zero) are needed since the formula
* will be applied at time other than time zero and S
.
* @param K strike price
* @param tau time to expiration
* @param sigma annual asset volatility
* @param B risk free bond B_T at expiry
public static double bsDiscountedPutPrice(double S, double K, double tau, double sigma, double B)
Discounted Black-Scholes put price (note that current time may
* not be zero). Here we need the interest rate, the current time
* t
and the time T
of expiration explicitly.
* The formula will be applied at times other than time zero.
T
.
* @param K strike price
* @param tau time to expiry
* @param sigma annual asset volatility
* @param B risk free bond B_T at expiry
public static double NewtonSolveBSF(double Q, double k, double y) throws NoSolutionException
Given b > 0 solves the equation
* bLackScholesFunction(Q,k,Sigma)=y
for
* Sigma
> 0 using Newton's algorithm.
A solution Sigma=Sigma(Q,k,y) exists if and only if b < Q. * To be used to compute implied * volatilities from call forward prices y. Note that the solution Sigma * is not the implied annual volatility sigma, indeed these are related as * Sigma=sigma*sqrt(tau), where tau=T-t is time to expiry.
* *Since Newton's algorithm often fails to converge it is better to rely * on the method using continued bisection below.
NoSolutionException
public static double BisectionSolveBSF(double Q, double k, double y) throws NoSolutionException
Same as NewtonSolveBSF(double, double, double)
but uses continued bisection instead of
* Newton's algorithm.
NoSolutionException
public static double dN(double x)
N(double)
.
public static double N_Solve(double y)
Solves the equation N(x)=y for x=x(y) using Newton's algorithm.
* *Application: confidence intervals for normal variables.
* Newton's algorithm often fails to converge. Better rely on continued
* bisection N_Solve1(double)
below.
public static double N_Solve1(double y) throws NoSolutionException
Solves the equation N(x)=y for x=x(y) using continued bisection.
* * Search restricted to [-100000,+100000], smaller or larger solutions * throw NoSolutionException (irrelevant anyway). Solution x(y) keeps error in * equation N(x)=y smaller than 0.000001.
NoSolutionException
public static double N_Inverse(double x)
The Inverse of the cumulative normal distribution function N(x). * Algorithm of Peter J. Acklam * http://www.math.uio.no/~jacklam/notes/invnorm.
* *Adapted from from: Peter Jaeckel, "Monte Carlom Methods in Finance", Wiley * ISBN 0-471-497-41-X
* * @param x must be in the interval (0,1).
public static void CholeskyRoot(double[][] C, double[][] L)
Let C be symmetric positive definite n by n matrix. The routine computes * the lower triangular matrix L satisfying LL'=C. Routine writes to the * memory referenced by L. Does not handle the positive semidefinite case * (all diagonal elements of C must be > 0). Only the lower triangular half * of C is used and only the lower triangular half of L is written.
public static void PlusEquals(cern.colt.matrix.DoubleMatrix1D w, double k, cern.colt.matrix.DoubleMatrix2D A, boolean transposeA, cern.colt.matrix.DoubleMatrix1D z)
Implements the vector operation w+=kAz, or w+=kA'z, * where z,w are vectors and A a matrix.
* * @param w,k,A,z the players in w+=kAz. * @param wether A should be transposed or not.
public static cern.colt.matrix.DoubleMatrix1D linearSystemSolution(cern.colt.matrix.DoubleMatrix2D A, cern.colt.matrix.DoubleMatrix1D y)
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |