tailieunhanh - Financial Applications Using Excel Add-in Development in C/C++Second Edition phần 9

Các mẫu mã sau đây cho thấy làm thế nào để làm điều này. Lưu ý rằng các chức năng bảng tính xuất khẩu chấp nhận và trả về ngày, tháng, là số nguyên 32-bit, gõ J. Lưu ý rằng nhà nước của Excel sẽ không thay đổi trong một cuộc gọi duy nhất một chức năng, nhưng sẽ cần phải được kiểm tra trên mỗi cuộc gọi đến siêu an toàn. | Miscellaneous Topics 439 if m_Vol return false double dl log m_Fwd m_Strike m_vRootT m_vRootT double N1 ndist d1 ndist x N x double N2 ndist d1 - m_vRootT m_Call m_Fwd N1 - m_Strike N2 m_Put m_Call m_Intrinsic m_Straddle m_Call m_Put if calc_derivs return true Hedge calculations assume constant volatility double n1 n d1 n dN x dx m_PutDelta m_CallDelta N1 - m_Gamma n1 m_vRootT m_Fwd m_Vol m_Vega n1 m_vRootT m_Fwd return true The following XLL-exportable function shows a simple example of its use. It is also used in the example implementation of CMS derivative pricing see section on page 513 . xloper __stdcall BlackOpt double t_exp double fwd double strike double vol BlackOption Opt t_exp fwd strike vol true true calc greeks define NUM_BLACK_RTN_VALS 6 double ret_vals NUM_BLACK_RTN_VALS Return a single row array cpp_xloper RetVal RW 1 COL NUM_BLACK_RTN_VALS ret_vals return C class construction iteratively and implicitly calls the constructor of any contained class. Consider the following example class A public A m_iVal 0 A int i m_iVal i void SetVal int i m_iVal i int GetVal void const return m_iVal 440 Excel Add-in Development in C C private int m_iVal class B public B int i i int GetVal void const return private A m_Ainstance class C public C int i m_Ainstance i int GetVal void const return private A m_Ainstance When an instance of class B is created the contained instance of class A s member variable m_iVal is first initialised to zero in an implicit call to A s default constructor and then is reset with an explicit call to SetVal . In class C on the other hand A s second constructor is called explicitly and m_iVal is set only once. This is a trivial example of something that experienced C programmers will be well aware of but with more complex objects such things can .