Click or drag to resize

Option desk

The OptionDesk - graphic component is the table for option desk display. It shows “Greeks”, implied volatility, the theoretical price, the best offer and bid for Put and Call options.

Below is the OptionCalculator example, which uses this component. The source code of the example can be found in the Samples/Options/OptionCalculator folder.

option desk

OptionCalculator example

  1. The OptionDesk element is added to the XAML code and the Desk name is assigned to it.

    XAML
    <Window x:Class="OptionCalculator.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:loc="clr-namespace:StockSharp.Localization;assembly=StockSharp.Localization"
            xmlns:xaml="http://schemas.stocksharp.com/xaml"
            xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
            Title="{x:Static loc:LocalizedStrings.XamlStr396}" Height="400" Width="1030">
        <Grid Margin="5,5,5,5">
    
          .........................................................
    
          <xaml:OptionDesk x:Name="Desk" Grid.Row="6" Grid.ColumnSpan="3" Grid.Column="0" />
    
      </Grid>
    </Window>
  2. The connection is created in the C# code. Depending on the type of connector an instance OpenECryTrader or RithmicTrader is initialized.

    C#
    if (_connector == null)
    {
        if (IsOpenECry.IsChecked == true)
        {
            var trader = new OpenECryTrader
            {
                // ... initialization
            };
    
            _connector = trader;
        }
        else
        {
            var trader = new RithmicTrader
            {
                // ... initialization
            };
    
            _connector = trader;
        }
    }
  3. The messages provider for market data and instruments is specified.

    C#
    Desk.MarketDataProvider = _connector;
    Desk.SecurityProvider = _connector;
    Desk.CurrentTime = null;
  4. Upon getting the instruments:

    1. To fill the futures collection for the drop-down list;
    2. To initialize the selected instrument by the first element of this collection;
    3. To fill the array by the options chain, where selected instrument acts as underlying asset;
    4. To assign this array to the OptionDesk.Options property;
    5. To update optiondesk values using the OptionDesk.RefreshOptions method.
    C#
    _connector.NewSecurities += securities =>
        this.GuiAsync(() =>
        {
            _assets.AddRange(securities.Where(s => s.Type == SecurityTypes.Future));
    
            if (SelectedAsset == null && _assets.Count > 0)
                SelectedAsset = _assets.First();
    
            if (SelectedAsset != null)
            {
                var newStrikes = securities
                    .Where(s => s.Type == SecurityTypes.Option && s.UnderlyingSecurityId.CompareIgnoreCase(SelectedAsset.Id))
                    .ToArray();
    
                if (newStrikes.Length > 0)
                {
                    _options.AddRange(newStrikes);
                    Desk.Options = _options;
                    Desk.RefreshOptions();
                }
            }
        });
  5. Upon options parameters change:

    1. To fill the array by options that have not been previously added to the control options collection;
    2. If new options added, to update the OptionDesk.Options property value;
    3. If new options added or parameters of the previously added options changed, then to update option desk OptionDesk.RefreshOptions.
    C#
    _connector.SecuritiesChanged += securities =>
    {
        this.GuiAsync(() =>
        {
            if (SelectedAsset == null)
                return;
    
            var newStrikes = securities
                    .Where(s => s.Type == SecurityTypes.Option && s.UnderlyingSecurityId.CompareIgnoreCase(SelectedAsset.Id))
                    .Where(s => !_options.Contains(s))
                    .ToArray();
    
            if (newStrikes.Length > 0)
            {
                _options.AddRange(newStrikes);
                Desk.Options = _options;
                Desk.RefreshOptions();
            }
    
            if (Desk.Options.Intersect(securities).Any())
                Desk.RefreshOptions();
        });
    };
See Also

Other Resources