コード例 #1
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();
        }
コード例 #2
0
        private void DrawTestData()
        {
            //
            // prepare test data

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

            asset.LastTrade = new Trade
            {
                Security = asset,
                Price    = 130000,
            };

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

            var securities = new List <Security>
            {
                asset,

                CreateStrike(105000, 10, 60, OptionTypes.Call, expiryDate, asset, 100),
                CreateStrike(110000, 10, 53, OptionTypes.Call, expiryDate, asset, 343),
                CreateStrike(115000, 10, 47, OptionTypes.Call, expiryDate, asset, 3454),
                CreateStrike(120000, 78, 42, OptionTypes.Call, expiryDate, asset, null),
                CreateStrike(125000, 32, 35, OptionTypes.Call, expiryDate, asset, 100),
                CreateStrike(130000, 3245, 32, OptionTypes.Call, expiryDate, asset, 55),
                CreateStrike(135000, 3454, 37, OptionTypes.Call, expiryDate, asset, 456),
                CreateStrike(140000, 34, 45, OptionTypes.Call, expiryDate, asset, 4),
                CreateStrike(145000, 3566, 51, OptionTypes.Call, expiryDate, asset, 67),
                CreateStrike(150000, 454, 57, OptionTypes.Call, expiryDate, asset, null),
                CreateStrike(155000, 10, 59, OptionTypes.Call, expiryDate, asset, 334),

                CreateStrike(105000, 10, 50, OptionTypes.Put, expiryDate, asset, 100),
                CreateStrike(110000, 10, 47, OptionTypes.Put, expiryDate, asset, 343),
                CreateStrike(115000, 6788, 42, OptionTypes.Put, expiryDate, asset, 3454),
                CreateStrike(120000, 10, 37, OptionTypes.Put, expiryDate, asset, null),
                CreateStrike(125000, 567, 32, OptionTypes.Put, expiryDate, asset, 100),
                CreateStrike(130000, 4577, 30, OptionTypes.Put, expiryDate, asset, 55),
                CreateStrike(135000, 67835, 32, OptionTypes.Put, expiryDate, asset, 456),
                CreateStrike(140000, 13245, 35, OptionTypes.Put, expiryDate, asset, 4),
                CreateStrike(145000, 10, 37, OptionTypes.Put, expiryDate, asset, 67),
                CreateStrike(150000, 454, 39, OptionTypes.Put, expiryDate, asset, null),
                CreateStrike(155000, 10, 41, OptionTypes.Put, expiryDate, asset, 334)
            };

            var dummyProvider = new DummyProvider(securities, new[]
            {
                new Position
                {
                    Security     = asset,
                    CurrentValue = -1,
                },

                new Position
                {
                    Security     = securities.First(s => s.OptionType == OptionTypes.Call),
                    CurrentValue = 10,
                },

                new Position
                {
                    Security     = securities.First(s => s.OptionType == OptionTypes.Put),
                    CurrentValue = -3,
                }
            });

            //
            // draw test data on the pos chart

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

            PosChart.UnderlyingAsset = asset;
            PosChart.Options.Add(securities.First(s => s.OptionType == OptionTypes.Call));
            PosChart.Options.Add(securities.First(s => s.OptionType == OptionTypes.Put));

            PosChart.Refresh(null, currDate, expiryDate);

            //
            // draw test data on the desk

            _model.MarketDataProvider = dummyProvider;
            _model.UnderlyingAsset    = asset;

            foreach (var option in securities.Where(s => s.Type == SecurityTypes.Option))
            {
                _model.Add(option);
            }

            //
            // draw test data on the smile chart

            RefreshSmile(currDate);
        }
コード例 #3
0
        private void DrawTestData()
        {
            //
            // 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);

            _model.MarketDataProvider = dummyProvider;
            _model.UnderlyingAsset    = asset;

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

            //
            // draw test data on the smile chart

            RefreshSmile(new DateTime(2014, 08, 15));
        }