private void updateContractInfo(object sender, EventArgs e) { if (this.comboBoxOrderType.Text == "期权") { var cur_contract = this.dataset.Tables["options_contracts"].Rows.Find(this.comboBoxContractCode.Text); underlying_code = cur_contract.Field <string>("标的代码"); strike = cur_contract.Field <decimal>("执行价"); var exp_date = cur_contract.Field <DateTime>("到期日"); var dtm = this.dataset.GetDTM(exp_date); T = dtm / 256d; vol = cur_contract.Field <double>("波动率"); option_type = cur_contract.Field <string>("认购认沽")[0]; var spot_price = double.Parse(this.redis_db.HashGet(underlying_code, "LastPrice").ToString()); this.textBoxUnderlyingPrice.Text = spot_price.ToString("N2"); var option_price = OptionsCalculator.GetBlsPrice(spot_price, (double)strike, T, vol, this.r, option_type); this.numericUpDownPrice.Value = Math.Max(this.comboBoxLongShort.Text == "买入" ? decimal.Ceiling(new decimal(option_price) * 100m) / 100m : decimal.Floor(new decimal(option_price) * 100m) / 100m, 0.0001m); } else if (this.comboBoxOrderType.Text == "期货") { var spot_price = double.Parse(this.redis_db.HashGet(this.comboBoxContractCode.Text, "LastPrice").ToString()); this.numericUpDownPrice.Value = new decimal(spot_price); } }
private void timerTicked(object sender, EventArgs e) { if (!(strike_valid && maturity_valid && rate_valid && volatility_valid && underlying_valid && yield_valid && buysell_valid && callput_valid && quantity_valid)) { timer_quote.Stop(); textBoxPrice.Text = ""; textBoxDelta.Text = ""; return; } if (double.TryParse(redis_conn.HashGet(underlying_code, "LastPrice"), out underlying_price)) { double spread_value = checkBoxSpreadQuote.Checked?((call_put == 'c' ? 1 : -1) * (buy_sell == 'b' ? 1 : -1) * (double)numericUpDownSpreadValue.Value):0; textBoxPrice.Text = OptionsCalculator.GetBlsPrice(underlying_price + spread_value, strike, T, volatility, r, call_put).ToString("N2"); textBoxDelta.Text = OptionsCalculator.GetBlsDelta(underlying_price, strike, T, volatility, r, call_put).ToString("N2"); textBoxValue.Text = (decimal.Parse(textBoxPrice.Text) * decimal.Parse(textBoxQuantity.Text)).ToString(); textBoxTotalDelta.Text = (decimal.Parse(textBoxDelta.Text) * decimal.Parse(textBoxQuantity.Text)).ToString(); textBoxRemainBalance.Text = (decimal.Parse(textBoxBalance.Text) - decimal.Parse(textBoxValue.Text)).ToString(); } else { textBoxPrice.Text = ""; textBoxDelta.Text = ""; } }
private void updatePrice() { if (this.comboBoxOrderType.Text == "期权" && this.underlying_code != null && this.underlying_code != "") { var spot_price = double.Parse(this.redis_db.HashGet(underlying_code, "LastPrice").ToString()); if (this.checkBoxMarketPriceFuture.Checked) { this.textBoxUnderlyingPrice.Text = spot_price.ToString("N2"); } var option_price = OptionsCalculator.GetBlsPrice(spot_price, (double)strike, T, vol, this.r, option_type); if (this.checkBoxMarketPriceOption.Checked) { this.numericUpDownPrice.Value = this.comboBoxLongShort.Text == "买入" ? decimal.Ceiling(new decimal(option_price) * 100m) / 100m : decimal.Floor(new decimal(option_price) * 100m) / 100m; } } else if (this.comboBoxOrderType.Text == "期货" && this.underlying_code != null && this.underlying_code != "") { var spot_price = double.Parse(this.redis_db.HashGet(underlying_code, "LastPrice").ToString()); if (this.checkBoxMarketPriceOption.Checked) { this.numericUpDownPrice.Value = new decimal(spot_price); } } }