Example #1
0
        private void RefreshSmile(DateTimeOffset?time = null)
        {
            _model.Refresh(time);

            ClearSmiles();

            foreach (var row in _model.Rows)
            {
                var strike = row.Strike;

                if (strike == null)
                {
                    continue;
                }

                if (_callBidSmile != null)
                {
                    TryAddSmileItem(_callBidSmile, strike.Value, row.Call?.ImpliedVolatilityBestBid);
                }
                if (_callAskSmile != null)
                {
                    TryAddSmileItem(_callAskSmile, strike.Value, row.Call?.ImpliedVolatilityBestAsk);
                }
                if (_callLastSmile != null)
                {
                    TryAddSmileItem(_callLastSmile, strike.Value, row.Call?.ImpliedVolatilityLastTrade);
                }

                if (_putBidSmile != null)
                {
                    TryAddSmileItem(_putBidSmile, strike.Value, row.Put?.ImpliedVolatilityBestBid);
                }
                if (_putAskSmile != null)
                {
                    TryAddSmileItem(_putAskSmile, strike.Value, row.Put?.ImpliedVolatilityBestAsk);
                }
                if (_putLastSmile != null)
                {
                    TryAddSmileItem(_putLastSmile, strike.Value, row.Put?.ImpliedVolatilityLastTrade);
                }
            }
        }
Example #2
0
        public MainWindow()
        {
            InitializeComponent();

            var assetsSource  = new ObservableCollectionEx <Security>();
            var optionsSource = new ObservableCollectionEx <Security>();

            Options.ItemsSource = optionsSource;
            Assets.ItemsSource  = assetsSource;

            _assets  = new ThreadSafeObservableCollection <Security>(assetsSource);
            _options = new ThreadSafeObservableCollection <Security>(optionsSource);

            var timer = new DispatcherTimer {
                Interval = TimeSpan.FromSeconds(5)
            };

            timer.Tick += (sender, args) =>
            {
                if (!_isDirty)
                {
                    return;
                }

                _isDirty = false;
                RefreshChart();
            };
            timer.Start();

            //
            // draw test data on the pos chart

            var asset = new Security {
                Id = "RIM4@FORTS"
            };

            var dummyProvider = new DummyProvider(new[] { asset });

            PosChart.AssetPosition = new Position
            {
                Security     = asset,
                CurrentValue = -1,
            };

            PosChart.MarketDataProvider = dummyProvider;
            PosChart.SecurityProvider   = dummyProvider;

            var expDate = new DateTime(2014, 6, 14);

            PosChart.Positions.Add(new Position
            {
                Security = new Security {
                    Code = "RI C 110000", Strike = 110000, ImpliedVolatility = 45, OptionType = OptionTypes.Call, ExpiryDate = expDate, Board = ExchangeBoard.Forts, UnderlyingSecurityId = asset.Id
                },
                CurrentValue = 10,
            });
            PosChart.Positions.Add(new Position
            {
                Security = new Security {
                    Code = "RI P 95000", Strike = 95000, ImpliedVolatility = 30, OptionType = OptionTypes.Put, ExpiryDate = expDate, Board = ExchangeBoard.Forts, UnderlyingSecurityId = asset.Id
                },
                CurrentValue = -3,
            });

            PosChart.Refresh(100000, 10, new DateTime(2014, 5, 5), expDate);

            //
            // draw test data on the desk

            var expiryDate = new DateTime(2014, 09, 15);

            var model = new OptionDeskModel
            {
                MarketDataProvider = dummyProvider,
                UnderlyingAsset    = asset,
            };

            Desk.Model = model;

            model.Add(CreateStrike(05000, 10, 60, OptionTypes.Call, expiryDate, asset, 100));
            model.Add(CreateStrike(10000, 10, 53, OptionTypes.Call, expiryDate, asset, 343));
            model.Add(CreateStrike(15000, 10, 47, OptionTypes.Call, expiryDate, asset, 3454));
            model.Add(CreateStrike(20000, 78, 42, OptionTypes.Call, expiryDate, asset, null));
            model.Add(CreateStrike(25000, 32, 35, OptionTypes.Call, expiryDate, asset, 100));
            model.Add(CreateStrike(30000, 3245, 32, OptionTypes.Call, expiryDate, asset, 55));
            model.Add(CreateStrike(35000, 3454, 37, OptionTypes.Call, expiryDate, asset, 456));
            model.Add(CreateStrike(40000, 34, 45, OptionTypes.Call, expiryDate, asset, 4));
            model.Add(CreateStrike(45000, 3566, 51, OptionTypes.Call, expiryDate, asset, 67));
            model.Add(CreateStrike(50000, 454, 57, OptionTypes.Call, expiryDate, asset, null));
            model.Add(CreateStrike(55000, 10, 59, OptionTypes.Call, expiryDate, asset, 334));

            model.Add(CreateStrike(05000, 10, 50, OptionTypes.Put, expiryDate, asset, 100));
            model.Add(CreateStrike(10000, 10, 47, OptionTypes.Put, expiryDate, asset, 343));
            model.Add(CreateStrike(15000, 6788, 42, OptionTypes.Put, expiryDate, asset, 3454));
            model.Add(CreateStrike(20000, 10, 37, OptionTypes.Put, expiryDate, asset, null));
            model.Add(CreateStrike(25000, 567, 32, OptionTypes.Put, expiryDate, asset, 100));
            model.Add(CreateStrike(30000, 4577, 30, OptionTypes.Put, expiryDate, asset, 55));
            model.Add(CreateStrike(35000, 67835, 32, OptionTypes.Put, expiryDate, asset, 456));
            model.Add(CreateStrike(40000, 13245, 35, OptionTypes.Put, expiryDate, asset, 4));
            model.Add(CreateStrike(45000, 10, 37, OptionTypes.Put, expiryDate, asset, 67));
            model.Add(CreateStrike(50000, 454, 39, OptionTypes.Put, expiryDate, asset, null));
            model.Add(CreateStrike(55000, 10, 41, OptionTypes.Put, expiryDate, asset, 334));

            model.Refresh(new DateTime(2014, 08, 15));

            //
            // draw test data on the smile chart

            var puts  = SmileChart.CreateSmile("RIM4 (Put)", Colors.DarkRed);
            var calls = SmileChart.CreateSmile("RIM4 (Call)", Colors.DarkGreen);

            foreach (var option in model.Options)
            {
                if (option.Strike == null || option.ImpliedVolatility == null)
                {
                    continue;
                }

                (option.OptionType == OptionTypes.Put ? puts : calls).Add(new LineData <double> {
                    X = (double)option.Strike.Value, Y = option.ImpliedVolatility.Value
                });
            }

            Instance = this;

            InitConnector();
        }