Subject:Computational financing We have to do validatin test for given function.
ID: 3714919 • Letter: S
Question
Subject:Computational financing
We have to do validatin test for given function. implied volatility
10.4 Implied volatility 10.4.1 Summar The function signature is as follows, int BinomialTree: :ImpliedVolatility(int n, const Derivative * p_derivative, const Database * p db, double S, double to, double target, double & implied vol, int & num_iter); . Review the calculation of the 'yield from price for a bond » Many of the same ideas of data validaton and iteration will be employed below . The calculation procedure is basically the same the 'yield from bond price' calculation. . As opposed to the bond calculation, we shall internally set some limits. We do this because implied volatility is a computationally expensive function and we do not want users to set unnecessar rily small tolerances, etc const double tol1.0e-6 const int max_iter 100 » Initialize implied vol - 0 and num iter0 Perform some validation tests I. Set a low value for the volatility sigma low 0.01 (= 1%) (a) Call FairValue using the input sigma low to calculate a fair value FV low FairValue(n, p_derivative, p_db, S, sigma low, to, FV_lo); (b) Define double diff FV-low- FV-low- target; (c) If std: :abs(diff FV_low)Explanation / Answer
#ifndef __INTERVAL_BISECTION_H
#define __INTERVAL_BISECTION_H
#include <cmath>
// Creating a function template
// Trying to find an x such that |g(x) - y| < tol
// starting with the interval (m, n).
template<typename T>
double interval_bisection(double y_target, // Target y value
double m, // Left interval value
double n, // Right interval value
double tol , // Tolerance
T g) { // Function object of type T, named g
// Create the initial x mid-point value
// Find the mapped y value of g(x)
double x = 0.5 * (m + n);
double y = g(x);
// here y is fair value and y_target is target
// While the difference between y and the y_target
// value is greater than tol, keep subdividing
// the interval into successively smaller halves
// and re-evaluate the new y.
int c=0;
do {
if (y < y_target) {
m = x;
}
if (y > y_target) {
n = x;
}
x = 0.5 * (m + n);
y = g(x);
c++;
} while (fabs(y-y_target) > tol);
if(x== low_vol && c<max_iter)
return 0;
// check that if we havent bracketed the solution
if(m*n>0)
{
x=0;
return 1;
}
}
#endif
#ifndef __MAIN_CPP
#define __MAIN_CPP
#include "black_scholes.h"
#include "interval_bisection.h"
#include <iostream>
int main(int argc, char **argv) {
// First we create the parameter list
double S = 100.0; // Underlying spot price
double K = 100.0; // Strike price
double r = 0.05; // Risk-free rate (5%)
double T = 1.0; // One year until expiry
double C_M = 10.5; // Option market price
// Create the Black-Scholes Call functor
BlackScholesCall bsc(S, K, r, T);
// Interval Bisection parameters
double low_vol = 0.01;
double high_vol = 0.35;
double tol = 0.000001;
// Calculate the implied volatility
double sigma = interval_bisection(C_M, low_vol, high_vol, episilon, bsc);
// Output the values
std::cout << "Implied Vol: " << sigma << std::endl;
return 0;
}
#endif