void testTreePricer2()
{
std::cout << "\n------------------------ Accuracy of Adjusted BTM versus CRR BTM-------------------\n";
std::ifstream fin("simpleMkt.dat");
if (fin) {
Market mkt;
fin >> mkt;
mkt.Print();
for (int T = 100; T < 103; T++)
{
CRRBinomialTreePricer crrBTreePricer(T);
EuropeanOption euroCall(Call, 90, Date(2016, 1, 1));
std::cout << "crrPrice for option with strike=90, timestep=" << T << "is" << crrBTreePricer.Price(mkt, euroCall) << std::endl;
double cPrice = crrBTreePricer.Price(mkt, euroCall);
AdjustedBinomialTreePricer adjustBTreePricer(T);
double AdjustPrice = crrBTreePricer.Price(mkt, euroCall);
std::cout << "adjustedproce for option with strike=90, timestep" << T << "is" << adjustBTreePricer.Price(mkt, euroCall) << std::endl;
double accuracy = AdjustPrice - cPrice;
std::cout << "The accuracy of Adjusted BTM versus CRR BTM with timestep" << T << "is" << accuracy<< endl;
}
}
else
std::cerr << "no simpleMkt.dat found" << std::endl;
}
結果為
------------------------ Accuracy of Adjusted BTM versus CRR BTM-------------------
market asof: 2015 1 1
stock price: 100
volatility: 0.1
interestRate: 0.03
crrPrice for option with strike=90, timestep=100is13.0406
adjustedproce for option with strike=90, timestep100is13.7135
The accuracy of Adjusted BTM versus CRR BTM with timestep100is0
crrPrice for option with strike=90, timestep=101is13.0403
adjustedproce for option with strike=90, timestep101is13.7133
The accuracy of Adjusted BTM versus CRR BTM with timestep101is0
crrPrice for option with strike=90, timestep=102is13.0413
adjustedproce for option with strike=90, timestep102is13.7131
The accuracy of Adjusted BTM versus CRR BTM with timestep102is0
這里為什么兩個double型別的不同數值相減結果為0呢?
應該怎么得到準確的數值呢?
uj5u.com熱心網友回復:
開斷點看看唄,監視一下變數看看是哪錯了uj5u.com熱心網友回復:
抱歉,這代碼我無能為力。我攤牌了,放棄了。
uj5u.com熱心網友回復:
斷點一下,應該很快就找到原因了。轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/104464.html
標籤:C++ 語言
上一篇:請教各路大神佇列問題,跪謝
