c++ - int variable initialization failed in function -
i have function wants return vector, inside of function setup int counter (seasoning), increase 1 after each loop. when debug function, see counter not initialize, , correspondingly first 29 calculations (seasoning < 30) got 0 value.
please see code, thanks!
vector<float> richardrollprepayment::computingcpr( float maturity, float settledtime, float frequencypreyear, float couponrate, vector<float> mortgagerate ) { vector<float> cprvector(ceil((maturity-settledtime) * frequencypreyear)); float seasonality[] = { .94, .76, .73, .96, .98, .92, .99, 1.1, 1.18, 1.21, 1.23, .97 }; int seasoning = int(settledtime) * 12; (int = 0; < cprvector.size(); i++) { if (seasoning < 30) { cprvector[i] = (.2406 - .1389 * atan(5.952*(1.089 - couponrate/mortgagerate[i]))) * (seasoning/30) * seasonality[seasoning%12]; seasoning++; } else { cprvector[i] = (.2406 - .1389 * atan(5.952*(1.089 - couponrate/mortgagerate[i]))) * 1 * seasonality[seasoning%12]; seasoning++; } } return cprvector; }
when seasoning
less 30, you're multiplying seasoning/30
, 0 since seasoning
integer.
replace seasoning / 30.0f
.
Comments
Post a Comment