public void calculation() { label_pro.Text = "Input"; //create objects RandomNumber randomnumber = new RandomNumber(); Value value = new Value(); //Define the inputs value.S = Convert.ToDouble(textBoxS0.Text); value.K = Convert.ToDouble(textBoxK.Text); value.T = Convert.ToDouble(textBoxT.Text); value.R = Convert.ToDouble(textBoxr.Text); value.Sigma = Convert.ToDouble(textBoxsigma.Text); value.Trials = Convert.ToInt32(textBoxN.Text); value.N = Convert.ToInt32(textBoxsteps.Text); value.Type = Convert.ToBoolean(Radio_call.Checked); value.An = Convert.ToBoolean(checkBox_An.Checked); value.CV = Convert.ToBoolean(checkBox_CV.Checked); value.MT = Convert.ToBoolean(checkBox_MT.Checked); label_pro.Text = "Reading Your Data"; inprogress(10); double[,] Rn = randomnumber.Rand(value.Trials, value.N, value.MT); value.Rn = Rn; label_pro.Text = "Creating Random Number Array"; inprogress(20); //Outputs if (radioButton_European.Checked) { value.Rb = 0; value.Bt = 0; value.Br = 0; European european = new European(); label_pro.Text = "Calculate Price"; textBoxPrice.Text = Convert.ToString(european.OptionPrice(value)[0]); inprogress(30); label_pro.Text = "Calculate Std"; textBoxStd.Text = Convert.ToString(european.OptionPrice(value)[1]); inprogress(40); label_pro.Text = "Calculate Delta"; textBoxDelta.Text = Convert.ToString(european.Delta(value)); inprogress(50); label_pro.Text = "Calculate Gamma"; textBoxGamma.Text = Convert.ToString(european.Gamma(value)); inprogress(60); label_pro.Text = "Calculate Vega"; textBoxVega.Text = Convert.ToString(european.Vega(value)); inprogress(70); label_pro.Text = "Calculate Theta"; textBoxTheta.Text = Convert.ToString(european.Theta(value)); inprogress(80); label_pro.Text = "Calculate Rho"; textBoxRho.Text = Convert.ToString(european.Rho(value)); inprogress(90); } if (radioButton_Asian.Checked) { value.Rb = 0; value.Bt = 0; value.Br = 0; Asian asian = new Asian(); label_pro.Text = "Calculate Price"; textBoxPrice.Text = Convert.ToString(asian.OptionPrice(value)[0]); inprogress(30); label_pro.Text = "Calculate Std"; textBoxStd.Text = Convert.ToString(asian.OptionPrice(value)[1]); inprogress(40); label_pro.Text = "Calculate Delta"; textBoxDelta.Text = Convert.ToString(asian.Delta(value)); inprogress(50); label_pro.Text = "Calculate Gamma"; textBoxGamma.Text = Convert.ToString(asian.Gamma(value)); inprogress(60); label_pro.Text = "Calculate Vega"; textBoxVega.Text = Convert.ToString(asian.Vega(value)); inprogress(70); label_pro.Text = "Calculate Theta"; textBoxTheta.Text = Convert.ToString(asian.Theta(value)); inprogress(80); label_pro.Text = "Calculate Rho"; textBoxRho.Text = Convert.ToString(asian.Rho(value)); inprogress(90); } if (radioButton_Digital.Checked) { if (textBox_Rebate.Text == string.Empty) { textBox_Rebate.BackColor = Color.Pink; } else { value.Rb = Convert.ToDouble(textBox_Rebate.Text); value.Bt = 0; value.Br = 0; Digital digital = new Digital(); label_pro.Text = "Calculate Price"; textBoxPrice.Text = Convert.ToString(digital.OptionPrice(value)[0]); inprogress(30); label_pro.Text = "Calculate Std"; textBoxStd.Text = Convert.ToString(digital.OptionPrice(value)[1]); inprogress(40); label_pro.Text = "Calculate Delta"; textBoxDelta.Text = Convert.ToString(digital.Delta(value)); inprogress(50); label_pro.Text = "Calculate Gamma"; textBoxGamma.Text = Convert.ToString(digital.Gamma(value)); inprogress(60); label_pro.Text = "Calculate Vega"; textBoxVega.Text = Convert.ToString(digital.Vega(value)); inprogress(70); label_pro.Text = "Calculate Theta"; textBoxTheta.Text = Convert.ToString(digital.Theta(value)); inprogress(80); label_pro.Text = "Calculate Rho"; textBoxRho.Text = Convert.ToString(digital.Rho(value)); inprogress(90); } } if (radioButton_Barrier.Checked) { if (textBox_Barrier.Text == string.Empty) { textBox_Barrier.BackColor = Color.Pink; } else { value.Rb = 0; value.Br = Convert.ToDouble(textBox_Barrier.Text); if (radioButton_DO.Checked) { value.Bt = 0; } if (radioButton_UO.Checked) { value.Bt = 1; } if (radioButton_DI.Checked) { value.Bt = 2; } if (radioButton_UI.Checked) { value.Bt = 3; } Barrier barrier = new Barrier(); label_pro.Text = "Calculate Price"; textBoxPrice.Text = Convert.ToString(barrier.OptionPrice(value)[0]); inprogress(30); label_pro.Text = "Calculate Std"; textBoxStd.Text = Convert.ToString(barrier.OptionPrice(value)[1]); inprogress(40); label_pro.Text = "Calculate Delta"; textBoxDelta.Text = Convert.ToString(barrier.Delta(value)); inprogress(50); label_pro.Text = "Calculate Gamma"; textBoxGamma.Text = Convert.ToString(barrier.Gamma(value)); inprogress(60); label_pro.Text = "Calculate Vega"; textBoxVega.Text = Convert.ToString(barrier.Vega(value)); inprogress(70); label_pro.Text = "Calculate Theta"; textBoxTheta.Text = Convert.ToString(barrier.Theta(value)); inprogress(80); label_pro.Text = "Calculate Rho"; textBoxRho.Text = Convert.ToString(barrier.Rho(value)); inprogress(90); } } if (radioButton_Lookback.Checked) { value.Rb = 0; value.Bt = 0; value.Br = 0; Lookback lookback = new Lookback(); label_pro.Text = "Calculate Price"; textBoxPrice.Text = Convert.ToString(lookback.OptionPrice(value)[0]); inprogress(30); label_pro.Text = "Calculate Std"; textBoxStd.Text = Convert.ToString(lookback.OptionPrice(value)[1]); inprogress(40); label_pro.Text = "Calculate Delta"; textBoxDelta.Text = Convert.ToString(lookback.Delta(value)); inprogress(50); label_pro.Text = "Calculate Gamma"; textBoxGamma.Text = Convert.ToString(lookback.Gamma(value)); inprogress(60); label_pro.Text = "Calculate Vega"; textBoxVega.Text = Convert.ToString(lookback.Vega(value)); inprogress(70); label_pro.Text = "Calculate Theta"; textBoxTheta.Text = Convert.ToString(lookback.Theta(value)); inprogress(80); label_pro.Text = "Calculate Rho"; textBoxRho.Text = Convert.ToString(lookback.Rho(value)); inprogress(90); } if (radioButton_Range.Checked) { value.Rb = 0; value.Bt = 0; value.Br = 0; Range range = new Range(); label_pro.Text = "Calculate Price"; textBoxPrice.Text = Convert.ToString(range.OptionPrice(value)[0]); inprogress(30); label_pro.Text = "Calculate Std"; textBoxStd.Text = Convert.ToString(range.OptionPrice(value)[1]); inprogress(40); label_pro.Text = "Calculate Delta"; textBoxDelta.Text = Convert.ToString(range.Delta(value)); inprogress(50); label_pro.Text = "Calculate Gamma"; textBoxGamma.Text = Convert.ToString(range.Gamma(value)); inprogress(60); label_pro.Text = "Calculate Vega"; textBoxVega.Text = Convert.ToString(range.Vega(value)); inprogress(70); label_pro.Text = "Calculate Theta"; textBoxTheta.Text = Convert.ToString(range.Theta(value)); inprogress(80); label_pro.Text = "Calculate Rho"; textBoxRho.Text = Convert.ToString(range.Rho(value)); inprogress(90); } int core_num; if (value.MT == true) { core_num = System.Environment.ProcessorCount; } else { core_num = 1; } TextBoxCore.Text = Convert.ToString(core_num); }
//The main body private void button1_Click(object sender, EventArgs e) { DateTime beforDT = System.DateTime.Now; //开始监视代码运行时间 //create objects RandomNumber randomnumber = new RandomNumber(); Value value = new Value(); Price price = new Price(); Greeks greeks = new Greeks(); //Define the inputs value.S = Convert.ToDouble(textBoxS0.Text); value.K = Convert.ToDouble(textBoxK.Text); value.T = Convert.ToDouble(textBoxT.Text); value.R = Convert.ToDouble(textBoxr.Text); value.Sigma = Convert.ToDouble(textBoxsigma.Text); value.Trials = Convert.ToInt32(textBoxN.Text); value.N = Convert.ToInt32(textBoxsteps.Text); if (call.Checked) { value.Type = true; } else if (put.Checked) { value.Type = false; } else { MessageBox.Show("Please select either call or put"); return; } if (normal.Checked) { value.An = false; } else if (antithetic.Checked) { value.An = true; } else { MessageBox.Show("Please select method"); return; } if (CV.Checked) { value.CV = true; } else { value.CV = false; } double[,] Rn = randomnumber.Rand(value.Trials, value.N); value.Rn = Rn; //Outputs textBoxPrice.Text = Convert.ToString(price.Oprice(value)[0]); textBoxStd.Text = Convert.ToString(price.Oprice(value)[1]); textBoxDelta.Text = Convert.ToString(greeks.Delta(value)); textBoxGamma.Text = Convert.ToString(greeks.Gamma(value)); textBoxVega.Text = Convert.ToString(greeks.Vega(value)); textBoxTheta.Text = Convert.ToString(greeks.Theta(value)); textBoxRho.Text = Convert.ToString(greeks.Rho(value)); DateTime afterDT = System.DateTime.Now; //停止监视 //从afterDT中减去beforDT的时间 TimeSpan ts = afterDT.Subtract(beforDT); textBoxTime.Text = Convert.ToString(ts); }
//The main body private void button1_Click(object sender, EventArgs e) { label_pro.Text = "Input"; DateTime beforDT = System.DateTime.Now; //开始监视代码运行时间 //create objects RandomNumber randomnumber = new RandomNumber(); Value value = new Value(); Price price = new Price(); Greeks greeks = new Greeks(); //Define the inputs value.S = Convert.ToDouble(textBoxS0.Text); value.K = Convert.ToDouble(textBoxK.Text); value.T = Convert.ToDouble(textBoxT.Text); value.R = Convert.ToDouble(textBoxr.Text); value.Sigma = Convert.ToDouble(textBoxsigma.Text); value.Trials = Convert.ToInt32(textBoxN.Text); value.N = Convert.ToInt32(textBoxsteps.Text); if (call.Checked) { value.Type = true; } else if (put.Checked) { value.Type = false; } else { MessageBox.Show("Please select either call or put"); return; } if (normal.Checked) { value.An = false; } else if (antithetic.Checked) { value.An = true; } else { MessageBox.Show("Please select method"); return; } if (CV.Checked) { value.CV = true; } else { value.CV = false; } if (CVNO.Checked) { value.CV = false; } else { value.CV = true; } if (MT.Checked) { value.MT = true; } else { value.MT = false; } if (Nouse.Checked) { value.MT = false; } else { value.MT = true; } label_pro.Text = "Reading Your Data"; inprogress(10); double[,] Rn = randomnumber.Rand(value.Trials, value.N, value.MT); value.Rn = Rn; label_pro.Text = "Creating Random Number Array"; inprogress(20); //Outputs textBoxPrice.Text = Convert.ToString(price.Oprice(value)[0]); label_pro.Text = "Calculate Price"; inprogress(30); textBoxStd.Text = Convert.ToString(price.Oprice(value)[1]); label_pro.Text = "Calculate Std"; inprogress(40); textBoxDelta.Text = Convert.ToString(greeks.Delta(value)); label_pro.Text = "Calculate Delta"; inprogress(50); textBoxGamma.Text = Convert.ToString(greeks.Gamma(value)); label_pro.Text = "Calculate Gamma"; inprogress(60); textBoxVega.Text = Convert.ToString(greeks.Vega(value)); label_pro.Text = "Calculate Vega"; inprogress(70); textBoxTheta.Text = Convert.ToString(greeks.Theta(value)); label_pro.Text = "Calculate Theta"; inprogress(80); textBoxRho.Text = Convert.ToString(greeks.Rho(value)); label_pro.Text = "Calculate Rho"; inprogress(90); DateTime afterDT = System.DateTime.Now; //停止监视 //从afterDT中减去beforDT的时间 TimeSpan ts = afterDT.Subtract(beforDT); textBoxTime.Text = Convert.ToString(ts); label_pro.Text = "Calculate Time"; inprogress(100); int core_num; if (value.MT == true) { core_num = System.Environment.ProcessorCount; } else { core_num = 1; } TextBoxCore.Text = Convert.ToString(core_num); }