Home > Back-end >  Why two different numerical type double subtraction result is 0; How should adjust?
Why two different numerical type double subtraction result is 0; How should adjust?

Time:10-02

Void testTreePricer2 ()
{
STD: : cout & lt; <"\ n -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Accuracy of Adjusted BTM versus CRR BTM -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n";
STD: : ifstream fin (" simpleMkt. Dat ");
If (fin) {
Market MKT.
Fin & gt;> MKT.
MKT. Print ();
For (int T=100; T & lt; 103; T++)
{
CRRBinomialTreePricer crrBTreePricer (T);
EuropeanOption euroCall (Call, 90, the Date (2016, 1, 1));
STD: : cout & lt; <"CrrPrice for option with strike=90, timestep within=" & lt; Double cPrice=crrBTreePricer. Price (MKT, euroCall);
AdjustedBinomialTreePricer adjustBTreePricer (T);
Double AdjustPrice=crrBTreePricer. Price (MKT, euroCall);
STD: : cout & lt; <"Adjustedproce for option with strike=90, timestep within" & lt; Double accuracy=AdjustPrice - cPrice;
STD: : cout & lt; <"The accuracy of Adjusted BTM versus CRR BTM with timestep within" & lt; }

}
The else
STD: : cerr & lt; <"No simpleMkt. Dat found" & lt; }






The results for the
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 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 within=100 is13. 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 within=101 is13. 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 within=102 is13. 0413
Adjustedproce for option with strike=90, timestep102is13. 7131
The accuracy of Adjusted BTM versus CRR BTM with timestep102is0

Why two different numerical type double subtraction results of 0?
How to get accurate numerical?

CodePudding user response:

A breakpoint see bai, monitor the variables to see what was wrong

CodePudding user response:

There is nothing I can do, I'm sorry, but this code, I showdown, gave up,

CodePudding user response:

A breakpoint, should soon find out why,
  • Related