March 24th, 2006, 6:01 am
Hi Aaron and Stylz,thanks for your answers.Aaron:You're right - I assign the interval 0.3125 to 0.6875 to the value 0. But my real problem is: what is the x-value belonging to a randomly sampled cumulative probability of - lets say 0.4000 (I want to use 0-1 distributed numbers to generate random samples from the used discrete density)? At the moment I'm doing this the following way: The probability assigned to the x-value of -1 is centered on 0.1875 (wrong!?), the one assigned to 0 is centered on 0.5000. Then I use linear interpolation to get the x-value belonging to 0.4000. Even though my distribution has 512 points, the resulting random numbers still don't get the desired variance of one.If it helps - here is the source code that I use to compute the distribution and the one for generating random numbers (see arrows):void Binomial_Distribution::Compute_Distribution() { if (changed_parameters_) { Matrix<double> interpolation_data_cdf_inverse; distribution_data_.Resize(tree_steps_ + 1, 3); for (unsigned int k = 0; k <= tree_steps_; k++) { distribution_data_(k, Defaults::MATRIX_X_VALUES) = (2 * k - double(tree_steps_)) / sqrt(tree_steps_); distribution_data_(k, Defaults::MATRIX_PDF) = Get_Value(tree_steps_, k, p_, Defaults::RETURN_PDF); ==> distribution_data_(k, Defaults::MATRIX_CDF) = distribution_data_(k, Defaults::MATRIX_PDF) / 2; ==> if (k != 0) ==> distribution_data_(k, Defaults::MATRIX_CDF) += distribution_data_(k - 1, Defaults::MATRIX_CDF) + distribution_data_(k - 1, Defaults::MATRIX_PDF) / 2; } interpolation_data_cdf_inverse.Resize(tree_steps_ + 1, 2); Matrix<double>::Copy_Column(&distribution_data_, &interpolation_data_cdf_inverse, Defaults::MATRIX_X_VALUES, 1); Matrix<double>::Copy_Column(&distribution_data_, &interpolation_data_cdf_inverse, Defaults::MATRIX_CDF, 0); interpolation_cdf_inverse_.Set_Data_Points(&interpolation_data_cdf_inverse, true); changed_parameters_ = false; }}double Binomial_Distribution::Get_Random() { Compute_Distribution(); double random = mt_random_.rand(); return interpolation_cdf_inverse_.Get_Data_Point(random);}( with the member variables:bool changed_parameters_;MTRand mt_random_;Interpolation_Linear interpolation_cdf_inverse_; )Here are the results from 10 times running 10 Mio. samples [mean] / [variance]:-0.000098 / 1.002778-0.000487 / 1.0016850.000173 / 1.0022560.000079 / 1.002803-0.000228 / 1.002739-0.000146 / 1.0023760.000316 / 1.0023280.000003 / 1.002504-0.000280 / 1.0026580.000401 / 1.002630While the mean looks good, the variance is always to high. That's why all the option prices I'm calculating with these numbers are a little bit too high too. The reason is, that I just divide the probability assigned to one point by two (see arrows in the source code) and don't consider that the distribution is upward sloping for negative x-values and downward sloping for positive ones.Sorry for the confusing notation - I'm not a mathematician..
Last edited by
PointerLover on March 23rd, 2006, 11:00 pm, edited 1 time in total.