这种新镇 - 拉夫森实施对黑人学位的效率暗示着波动?
我已经实施了一种用于计算隐含波动率的算法(如下所示),并正在寻找有关如何改进代码的反馈,无论是速度,组织等。走到任何不良习惯的面前。
请假设最佳编写“ BS_OPTION_PRICE_ANALYTICE”和“ VEGA_BS”的实现。这些用于第一个导数计算。
double newton_raphson_implied_vol(char type, double mkt_price, double S, double K, double T, double sigma0, double r, double q, double tol)
{
// Initialize variables
double bs_price_old{bs_option_price_analytical(type, S, K, T, sigma0, r, q)};
double bs_mkt_diff{bs_price_old - mkt_price}; // To avoid repeated calculations in While condition
double sigma_new{-bs_price_old/vega_bs(S, K, T, sigma0, r, q) + sigma0}; // First new value (to be updated iteratively later)
// Iterate using Newton-Raphson method
while (abs(bs_mkt_diff/mkt_price) > tol)
{
bs_price_old = bs_option_price_analytical(type, S, K, T, sigma_new, r, q);
bs_mkt_diff = bs_price_old - mkt_price;
sigma_new = -bs_mkt_diff/vega_bs(S, K, T, sigma_new, r, q) + sigma_new;
}
return sigma_new;
}
I've implemented an algorithm for calculating the implied volatility (shown below), and was looking for feedback on how I could improve my code, whether it's speed, organization, etc. I'm very new to C++ so I'm looking to get in front of any bad habits.
Please assume the implementation for "bs_option_price_analytical" and "vega_bs" are optimally written. These are used in the first derivative calculation.
double newton_raphson_implied_vol(char type, double mkt_price, double S, double K, double T, double sigma0, double r, double q, double tol)
{
// Initialize variables
double bs_price_old{bs_option_price_analytical(type, S, K, T, sigma0, r, q)};
double bs_mkt_diff{bs_price_old - mkt_price}; // To avoid repeated calculations in While condition
double sigma_new{-bs_price_old/vega_bs(S, K, T, sigma0, r, q) + sigma0}; // First new value (to be updated iteratively later)
// Iterate using Newton-Raphson method
while (abs(bs_mkt_diff/mkt_price) > tol)
{
bs_price_old = bs_option_price_analytical(type, S, K, T, sigma_new, r, q);
bs_mkt_diff = bs_price_old - mkt_price;
sigma_new = -bs_mkt_diff/vega_bs(S, K, T, sigma_new, r, q) + sigma_new;
}
return sigma_new;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论