private void optionTypeComboBox_SelectedIndexChanted(object sender, EventArgs e) { int index = optionTypeComboBox.SelectedIndex; switch (index) { case 2: amountLabel.Text = "Barrier Price"; amountTextBox.Visible = true; outputDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; outputDataGridView.DataSource = BarrierOption.SetDataTable(); break; case 3: amountLabel.Text = "Rebate Price"; amountTextBox.Visible = true; outputDataGridView.DataSource = DigitalOption.SetDataTable(); break; case 5: outputDataGridView.DataSource = RangeOption.SetDataTable(); break; default: amountLabel.Text = ""; amountTextBox.Visible = false; outputDataGridView.DataSource = EuropeanOption.SetDataTable(); break; } }
public Range(Sign Sign, RangeOption Option, string LowValue, string HighValue) { this._LowValue = ""; this._HighValue = ""; this.Sign = Sign; this.Option = Option; this.LowValue = LowValue; this.HighValue = HighValue; }
public TextStyle(string label, TextStyle baseStyle, int size, int sizeMin, int sizeMax, int height, int heightMin, int heightMax, Action <TextStyle> onChange = null) { _baseStyle = baseStyle; _onChange = onChange; Label = label; Size = new RangeOption(size, sizeMin, sizeMax, Lang.Get("TextStyle.Size"), value => ((baseStyle != null) && (Size.Value > 0) ? "+" : null) + value, onChange: _ => UpdateStyle()); Height = new RangeOption(height, heightMin, heightMax, Lang.Get("TextStyle.Height"), value => value + "%", onChange: _ => UpdateStyle()); UpdateStyle(); }
public static bool IsInRange(this float self, float min, float max, RangeOption opt = RangeOption.InEx) { switch (opt) { case RangeOption.InEx: return(min <= self && self < max); case RangeOption.InIn: return(min <= self && self <= max); case RangeOption.ExIn: return(min < self && self <= max); case RangeOption.ExEx: return(min < self && self < max); default: throw new ArgumentOutOfRangeException("opt", opt, null); } }
public void RangeSlider(RangeOption range, bool enabled = true) { GUIPlus.SetEnabledColor(enabled); var grid = GetRect(Text.LineHeight).GetHGrid(ElementPadding, LabelWidth, ValueWidth, -1f); GUIPlus.DrawText(grid[1], range.Label); GUIPlus.DrawText(grid[2], range.ToString()); var value = Mathf.RoundToInt(Widgets.HorizontalSlider(grid[3], range.Value, range.Min, range.Max, true)); if (enabled) { range.Value = value; } GUIPlus.DrawTooltip(grid[0], range.Tooltip, true); Gap(verticalSpacing); GUIPlus.ResetColor(); }
public void RangeSliderEntry(RangeOption range, ref string text, int id, bool enabled = true) { GUIPlus.SetEnabledColor(enabled); var grid = GetRect(Text.LineHeight).GetHGrid(ElementPadding, LabelWidth, ValueWidth, -1f); GUIPlus.DrawText(grid[1], range.Label); var entryName = "RangeSliderEntry_Text" + id; var isFocused = GUI.GetNameOfFocusedControl() == entryName; if (!isFocused) { text = range.Value.ToString(); } GUI.SetNextControlName(entryName); var newText = Widgets.TextField(grid[2], text, 5, RangeSliderEntryRegex); if (enabled) { text = newText; } var textValue = text.ToInt(); if (textValue.HasValue) { if (textValue.Value < range.Min) { range.Value = range.Min; } else if (textValue.Value > range.Max) { range.Value = range.Max; } else { range.Value = textValue.Value; } } var sliderName = "RangeSliderEntry_Slider" + id; GUI.SetNextControlName(sliderName); var sliderValue = Mathf.RoundToInt(Widgets.HorizontalSlider(grid[3], range.Value, range.Min, range.Max, true)); if (enabled && range.Value != sliderValue) { range.Value = sliderValue; text = range.Value.ToString(); } if (Widgets.ButtonInvisible(grid[3])) { GUI.FocusControl(sliderName); } GUIPlus.DrawTooltip(grid[0], range.Tooltip, true); Gap(verticalSpacing); GUIPlus.ResetColor(); }
public virtual void AddRange(Sign Sign, RangeOption Option, string LowValue, string HighValue) { this._Ranges.Add(Sign, Option, LowValue, HighValue); }
public virtual void AddRange(Sign Sign, RangeOption Option, string Value) { this._Ranges.Add(Sign, Option, Value, ""); }
public virtual void Add(Sign Sign, RangeOption Option, string Value) { base.List.Add(new Range(Sign, Option, Value, "")); }
public virtual void Add(Sign Sign, RangeOption Option, string LowValue, string HighValue) { base.List.Add(new Range(Sign, Option, LowValue, HighValue)); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; object[] parameters = e.Argument as object[]; int steps = Convert.ToInt16(parameters[5]); int trials = Convert.ToInt32(parameters[6]); double s = Convert.ToDouble(parameters[0]); double k = Convert.ToDouble(parameters[1]); double t = Convert.ToDouble(parameters[2]); double sig = Convert.ToDouble(parameters[3]); double r = Convert.ToDouble(parameters[4]); string type = parameters[7].ToString(); double exoticAmount = Convert.ToDouble(parameters[8]); try { for (int i = 1; i <= 1; i++) { if (worker.CancellationPending == true) { e.Cancel = true; break; } else { switch (type) { case "None": e.Result = EuropeanOption.GetDataSet(steps, trials, s, k, t, sig, r); break; case "Asian": e.Result = AsianOption.GetDataSet(steps, trials, s, k, t, sig, r); break; case "Barrier": e.Result = BarrierOption.GetDataSet(steps, trials, s, k, t, sig, r, exoticAmount); break; case "Digital": e.Result = DigitalOption.GetDataSet(steps, trials, s, k, t, sig, r, exoticAmount); break; case "Lookback": e.Result = LookBackOption.GetDataSet(steps, trials, s, k, t, sig, r, exoticAmount); break; case "Range": e.Result = RangeOption.GetDataSet(steps, trials, s, k, t, sig, r, exoticAmount); break; default: break; } // Perform a time consuming operation and report progress. Thread.Sleep(100); worker.ReportProgress(i * 100); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void bPriceOptionBook_Click(object sender, RoutedEventArgs e) { graphPlot = new GraphPlotting(); graphs.DataContext = graphPlot; Task work = Task.Factory.StartNew(() => { var orderBook = model.OrderBookDBs.ToList(); foreach (var trade in orderBook) { if (trade.InstrumentsDB.SecurityTypeDB.TypeName.Equals("Stocks")) { var instrument = model.StockDBs.Where(x => x.Symbol == trade.InstrumentsDB.Symbol).First(); trade.FairPrice = trade.Price; trade.Delta = trade.Position == "BUY" ? trade.Quantity : -1 * trade.Quantity; trade.ProfitLoss = 0; trade.Theta = 0; trade.Gamma = 0; trade.Vega = 0; trade.Rho = 0; lock (lck) { model.SaveChanges(); } } else if (trade.InstrumentsDB.SecurityTypeDB.TypeName.Equals("Options")) { var instrument = model.OptionsDBs.Where(x => x.Symbol == trade.InstrumentsDB.Symbol).First(); Options option = null; ISecurity underlying = new Stock(instrument.StockDB.LastTradedPrice); switch (instrument.OptionKindDB.OptionKindName) { case "Asian Option": option = new AsianOption(instrument.Symbol, underlying, instrument.MaturityDate, (Double)instrument.StrikePrice, instrument.StockDB.HistoricalVolatility, instrument.OptionType == "CALL" ? OptionType.CALL : OptionType.PUT, OptionKind.ASIAN); break; case "Barrier Option": option = new BarrierOption(instrument.Symbol, underlying, instrument.MaturityDate, (Double)instrument.StrikePrice, instrument.StockDB.HistoricalVolatility, instrument.OptionType == "CALL" ? OptionType.CALL : OptionType.PUT, OptionKind.BARRIER, (Double)instrument.Barrier, (instrument.BarrierOptionType == "downout" ? BarrierOptionType.DOWNOUT : (instrument.BarrierOptionType == "downin" ? BarrierOptionType.DOWNIN : (instrument.BarrierOptionType == "upout" ? BarrierOptionType.UPOUT : BarrierOptionType.UPIN)))); break; case "Digital Option": option = new DigitalOption(instrument.Symbol, underlying, instrument.MaturityDate, (Double)instrument.StrikePrice, instrument.StockDB.HistoricalVolatility, instrument.OptionType == "CALL" ? OptionType.CALL : OptionType.PUT, OptionKind.DIGITAL, (Double)instrument.Rebate); break; case "European Option": option = new EuropeanOption(instrument.Symbol, underlying, instrument.MaturityDate, (Double)instrument.StrikePrice, instrument.StockDB.HistoricalVolatility, instrument.OptionType == "CALL" ? OptionType.CALL : OptionType.PUT, OptionKind.EUROPEAN); break; case "Lookback Option": option = new LookbackOption(instrument.Symbol, underlying, instrument.MaturityDate, (Double)instrument.StrikePrice, instrument.StockDB.HistoricalVolatility, instrument.OptionType == "CALL" ? OptionType.CALL : OptionType.PUT, OptionKind.LOOKBACK); break; case "Range Option": option = new RangeOption(instrument.Symbol, underlying, instrument.MaturityDate, (Double)instrument.StrikePrice, instrument.StockDB.HistoricalVolatility, instrument.OptionType == "CALL" ? OptionType.CALL : OptionType.PUT, OptionKind.RANGE); break; default: break; } try { option.calulateOptionPriceAndGreeks(1000, 0.05, (option.ExpiryDate - DateTime.Now).Days, true, option.OptionKind == OptionKind.EUROPEAN ? true : false, true, plot: graphPlot); trade.FairPrice = Math.Round(option.Price, 4); trade.ProfitLoss = Math.Round((Double)trade.FairPrice - (Double)trade.Price, 4) * (trade.Position == "BUY" ? trade.Quantity : -1 * trade.Quantity); trade.Delta = Math.Round(option.Greeks.Delta, 4) * (trade.Position == "BUY" ? trade.Quantity : -1 * trade.Quantity); trade.Theta = Math.Round(option.Greeks.Theta, 4) * (trade.Position == "BUY" ? trade.Quantity : -1 * trade.Quantity); trade.Gamma = Math.Round(option.Greeks.Gamma, 4) * (trade.Position == "BUY" ? trade.Quantity : -1 * trade.Quantity); trade.Vega = Math.Round(option.Greeks.Vega, 4) * (trade.Position == "BUY" ? trade.Quantity : -1 * trade.Quantity); trade.Rho = Math.Round(option.Greeks.Rho, 4) * (trade.Position == "BUY" ? trade.Quantity : -1 * trade.Quantity); lock (lck) { model.SaveChanges(); } } catch (Exception message) { MessageBox.Show(message.Message.ToString() + "\n" + message.StackTrace.ToString()); } } } this.Dispatcher.Invoke(() => { dataGrid.DataContext = orderBook; }); }); }
private void calculate_Click(object sender, RoutedEventArgs e) { this.sw.Reset(); this.sw.Start(); graphPlot = new GraphPlotting(); this.DataContext = graphPlot; this.graphs.IsEnabled = true; if (this.simulationNumber > 500 && this.steps > 500) { this.graphs.ToolTip = "Graph may take time to load "; } else { this.graphs.ToolTip = ""; } ISecurity underlying = new Stock(this.underlyingPrice); Options option = null; switch (this.kind) { case OptionKind.ASIAN: option = new AsianOption(underlying.Symbol, underlying, this.maturityDate, this.strike, this.vol, this.type, this.kind); break; case OptionKind.BARRIER: option = new BarrierOption(underlying.Symbol, underlying, this.maturityDate, this.strike, this.vol, this.type, this.kind, this.rebate, this.barrierOptiont); break; case OptionKind.DIGITAL: option = new DigitalOption(underlying.Symbol, underlying, this.maturityDate, this.strike, this.vol, this.type, this.kind, this.rebate); break; case OptionKind.EUROPEAN: option = new EuropeanOption(underlying.Symbol, underlying, this.maturityDate, this.strike, this.vol, this.type, this.kind); break; case OptionKind.LOOKBACK: option = new LookbackOption(underlying.Symbol, underlying, this.maturityDate, this.strike, this.vol, this.type, this.kind); break; case OptionKind.RANGE: option = new RangeOption(underlying.Symbol, underlying, this.maturityDate, this.strike, this.vol, this.type, this.kind); break; default: option = new EuropeanOption(underlying.Symbol, underlying, this.maturityDate, this.strike, this.vol, this.type, this.kind); break; } try { Task work = Task.Factory.StartNew(() => { this.Dispatcher.Invoke(() => this.progress.IsActive = true); option.calulateOptionPriceAndGreeks(this.simulationNumber, this.rate, this.steps, this.anitheticReductionEnabled, this.controlVariateEnabled, this.multithreadingEnabled, plot: this.graphPlot); this.sw.Stop(); this.Dispatcher.Invoke(() => { display(option); this.progress.IsActive = false; }); }); } catch (Exception message) { MessageBox.Show(message.Message.ToString() + "\n" + message.StackTrace.ToString()); } }
public SearchComponentPage(Assembly assembly, ComponentTypeEnumeration type, IEnumerable <Firm> firms, IEnumerable <Lookup> lookups, GetUnitVM unitModel) { InitializeComponent(); Assembly = assembly; ComponentTypeEnumeration = type; Search.Text = $"Search {type.GetDescription()}"; Search.Clicked += Search_Clicked; foreach (var unit in unitModel.Units) { switch (unit.UnitType) { case UnitType.CheckboxGroup: var checkboxGroupOption = new CheckboxGroupOption(unit); UnitList.Children.Add(checkboxGroupOption); break; case UnitType.RadiobuttonGroup: var radioButtonOption = new RadiobuttonGroupOption(unit); UnitList.Children.Add(radioButtonOption); break; case UnitType.Range: var rangeOption = new RangeOption(unit); UnitList.Children.Add(rangeOption); break; case UnitType.Text: foreach (var option in unit.Options) { var textInput = new TextOption(unit, option); UnitList.Children.Add(textInput); } break; default: break; } } var firmUnit = new Unit { Name = "Firms", Key = "firms", UnitType = UnitType.CheckboxGroup, Options = firms.Select(x => new Option { Key = "firms", Text = $"{x.Name} ({x.Country})", Value = x.Id }) }; var firmsOption = new CheckboxGroupOption(firmUnit); UnitList.Children.Add(firmsOption); foreach (var lookup in lookups) { var lookupUnit = new Unit { Name = lookup.Name, Key = lookup.Key, UnitType = UnitType.CheckboxGroup, Options = lookup.LookupValues.Select(x => new Option { Key = lookup.Key, Text = x.DisplayText, Value = x.Id }) }; var lookupOption = new CheckboxGroupOption(lookupUnit); UnitList.Children.Add(lookupOption); } }
private void priceTradeBookToolStripMenuItem_Click(object sender, EventArgs e) { foreach (ListViewItem i in ListTrade.Items) { Int32 tmp = Convert.ToInt32(i.Text); Trade tt = (from q in AppEntities.Trades where q.Id == tmp select q).FirstOrDefault(); double s = getLatestPrice(tt.Instrument); double k = Convert.ToDouble(tt.Instrument.Strike); double t = (double)tt.Instrument.Tenor; double r = getInterestRate(tt.Instrument); double sig = Convert.ToDouble(textBoxVol.Text) / 100.0; int instrumentTypeId = (Int32)tt.Instrument.InstrumentTypeId; int barrierTypeId = (Int32)tt.Instrument.BarrierTypeId; double barrier = (double)tt.Instrument.Barrier; double rebate = (double)tt.Instrument.Rebate; int steps = 100, trials = 10000; DataSet result = new DataSet(); Dictionary <String, double> stockMetric = new Dictionary <string, double>(); stockMetric.Add("Delta", 1); switch (instrumentTypeId) { case 1: stockMetric.Add("Delta", 1); break; case 2: result = AsianOption.GetDataSet(steps, trials, s, k, t, sig, r); break; case 3: result = EuropeanOption.GetDataSet(steps, trials, s, k, t, sig, r); break; case 4: result = BarrierOption.GetDataSet(steps, trials, s, k, t, sig, r, barrier); break; case 5: result = RangeOption.GetDataSet(steps, trials, s, k, t, sig, r, rebate); break; case 6: result = LookBackOption.GetDataSet(steps, trials, s, k, t, sig, r, 0); break; default: break; } ListViewItem i2; i2 = new ListViewItem(); i2.Text = tt.Id.ToString(); i2.SubItems.Add(tt.Instrument.Ticker); i2.SubItems.Add(tt.Instrument.InstrumentType.TypeName); i2.SubItems.Add(tt.IsBuy ? "BUY" : "SELL"); i2.SubItems.Add(tt.Quantity.ToString()); i2.SubItems.Add(tt.Price.ToString()); i2.SubItems.Add("10"); i2.SubItems.Add("10"); i2.SubItems.Add("10"); i2.SubItems.Add("10"); i2.SubItems.Add("10"); i2.SubItems.Add("10"); i2.SubItems.Add("10"); ListTrade.Items.Add(i2); } }