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);

            _model     = new OptionDeskModel();
            Desk.Model = _model;

            _putBidSmile   = SmileChart.CreateSmile("Put (B)", Colors.DarkRed);
            _putAskSmile   = SmileChart.CreateSmile("Put (A)", Colors.Red);
            _putLastSmile  = SmileChart.CreateSmile("Put (L)", Colors.OrangeRed);
            _callBidSmile  = SmileChart.CreateSmile("Call (B)", Colors.GreenYellow);
            _callAskSmile  = SmileChart.CreateSmile("Call (A)", Colors.DarkGreen);
            _callLastSmile = SmileChart.CreateSmile("Call (L)", Colors.DarkOliveGreen);

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

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

                _isDirty = false;

                RefreshSmile();
                RefreshChart();
            };
            timer.Start();

            Level1FieldsCtrl.ItemsSource = new[]
            {
                Level1Fields.ImpliedVolatility,
                Level1Fields.Delta,
                Level1Fields.Gamma,
                Level1Fields.Vega,
                Level1Fields.Theta,
                Level1Fields.Rho,
            }.ToDictionary(t => t, t => t.GetDisplayName());
            Level1FieldsCtrl.SelectedFields = _model.EvaluateFildes.ToArray();

            Instance = this;

            DrawTestData();
            InitConnector();
        }
        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();
        }
Exemple #3
0
        public MainWindow()
        {
            InitializeComponent();

            _assets  = new ObservableCollection <Security>();
            _options = new ObservableCollection <Security>();

            Assets.ItemsSource  = _assets;
            Options.ItemsSource = _options;

            _model     = new OptionDeskModel();
            Desk.Model = _model;

            _putBidSmile   = SmileChart.CreateSmile("Put (B)", Colors.DarkRed);
            _putAskSmile   = SmileChart.CreateSmile("Put (A)", Colors.Red);
            _putLastSmile  = SmileChart.CreateSmile("Put (L)", Colors.OrangeRed);
            _callBidSmile  = SmileChart.CreateSmile("Call (B)", Colors.GreenYellow);
            _callAskSmile  = SmileChart.CreateSmile("Call (A)", Colors.DarkGreen);
            _callLastSmile = SmileChart.CreateSmile("Call (L)", Colors.DarkOliveGreen);

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

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

                _isDirty = false;

                try
                {
                    RefreshSmile();
                    RefreshChart();
                }
                catch (Exception excp)
                {
                    excp.LogError();
                }
            };
            timer.Start();

            Level1FieldsCtrl.SetItemsSource(new[]
            {
                Level1Fields.ImpliedVolatility,
                Level1Fields.Delta,
                Level1Fields.Gamma,
                Level1Fields.Vega,
                Level1Fields.Theta,
                Level1Fields.Rho,
            });
            Level1FieldsCtrl.SetSelected(_model.EvaluateFields.ToArray());

            Instance = this;

            var loaded = false;

            Loaded += (sender, args) =>
            {
                if (loaded)
                {
                    return;
                }

                loaded = true;

                DrawTestData();
                InitConnector();
            };
        }