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="SampleOptionQuoting.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.XamlStr539}" Height="430" Width="630">
      <Grid Margin="5">
    
          .........................................................
    
          <xaml:OptionDesk x:Name="Desk" />
    
      </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#
    ...                 
    public readonly Connector Connector = new Connector();
    ...                 
    // subscribe on connection successfully event
    Connector.Connected += () =>
    {
        // update gui labels
        this.GuiAsync(() => ChangeConnectStatus(true));
    };
    
    // subscribe on disconnection event
    Connector.Disconnected += () =>
    {
        // update gui labels
        this.GuiAsync(() => ChangeConnectStatus(false));
    };
    
    // subscribe on connection error event
    Connector.ConnectionError += error => this.GuiAsync(() =>
    {
        // update gui labels
        ChangeConnectStatus(false);
    
        MessageBox.Show(this, error.ToString(), LocalizedStrings.Str2959);
    });
    
    // fill underlying asset's list
    Connector.NewSecurity += security =>
    {
        if (security.Type == SecurityTypes.Future)
            _assets.Add(security);
    };
    
    Connector.SecurityChanged += security =>
    {
        if (_model.UnderlyingAsset == security || _model.UnderlyingAsset.Id == security.UnderlyingSecurityId)
            _isDirty = true;
    };
    
    // subscribing on tick prices and updating asset price
    Connector.NewTrade += trade =>
    {
        if (_model.UnderlyingAsset == trade.Security || _model.UnderlyingAsset.Id == trade.Security.UnderlyingSecurityId)
            _isDirty = true;
    };
    
    Connector.NewPosition += position => this.GuiAsync(() =>
    {
        var asset = SelectedAsset;
    
        if (asset == null)
            return;
    
        var assetPos = position.Security == asset;
        var newPos = position.Security.UnderlyingSecurityId == asset.Id;
    
        if (!assetPos && !newPos)
            return;
    
        if (assetPos)
            PosChart.AssetPosition = position;
    
        if (newPos)
            PosChart.Positions.Add(position);
    
        RefreshChart();
    });
    
    Connector.PositionChanged += position => this.GuiAsync(() =>
    {
        if ((PosChart.AssetPosition != null && PosChart.AssetPosition == position) || PosChart.Positions.Cache.Contains(position))
            RefreshChart();
    });
    
    try
    {
        if (File.Exists(_settingsFile))
            Connector.Load(new XmlSerializer<SettingsStorage>().Deserialize(_settingsFile));
    }
    ...
  3. The messages provider for market data and instruments is specified.

    C#
    private void ConnectClick(object sender, RoutedEventArgs e)
    {
        if (!_isConnected)
        {
            ConnectBtn.IsEnabled = false;
    
            _model.Clear();
            _model.MarketDataProvider = Connector;
    ...
            Connector.Connect();
        }
        else
            Connector.Disconnect();
    }
  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#
    // fill underlying asset's list
    Connector.NewSecurity += security =>
    {
        if (security.Type == SecurityTypes.Future)
            _assets.Add(security);
    };
  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#
    private void Assets_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var asset = SelectedAsset;
    
        _model.UnderlyingAsset = asset;
    
        _model.Clear();
        _options.Clear();
    
        var options = asset.GetDerivatives(Connector);
    
        foreach (var security in options)
        {
            _model.Add(security);
            _options.Add(security);
        }
    
        ProcessPositions();
    }
See Also

Other Resources