private void pricingModelCB_SelectionChanged(object sender, SelectionChangedEventArgs e) { var modelParam = pricingModelCB.SelectedItem as ModelParamsVM; if (modelParam != null) { riskFree_Interest.DataContext = modelParam; var option = CallPutTDOptionVMCollection.FirstOrDefault(); if (option?.CallStrategyVM == null || option.CallStrategyVM.PricingModel == modelParam.InstanceName) { return; } option.CallStrategyVM.PricingModel = modelParam.InstanceName; _otcOptionHandler.UpdateStrategyModel(option.CallStrategyVM, StrategyVM.Model.PM); option.PutStrategyVM.PricingModel = modelParam.InstanceName; _otcOptionHandler.UpdateStrategyModel(option.PutStrategyVM, StrategyVM.Model.PM); } }
private void Adjustment_ValueChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { if (e.OldValue != null) { if (_otcOptionHandler != null) { var callPutTDOptionVM = CallPutTDOptionVMCollection.FirstOrDefault(); if (callPutTDOptionVM != null) { var strategyVM = callPutTDOptionVM.CallStrategyVM; if (strategyVM != null) { var pricingContract = strategyVM.PricingContractParams.FirstOrDefault(); if (pricingContract != null) { pricingContract.Adjust = (double)e.NewValue; _otcOptionHandler.UpdateStrategyPricingContracts(strategyVM, StrategyVM.Model.PM); } } } } } }
private async void expireDateCB_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (AutoOrder_CheckBox.IsChecked.Value) { AutoOrderUpdate(false); } var exchange = exchangeCB.SelectedValue?.ToString(); if (exchange != null) { if (expireDateCB.SelectedValue != null) { var ed = expireDateCB.SelectedValue.ToString(); var uc = underlyingContractCB.SelectedValue.ToString(); var optionList = (from c in _contractList where c.Exchange == exchange && c.UnderlyingContract == uc && c.ExpireDate == ed select c).ToList(); var strikeList = (from o in optionList orderby o.StrikePrice descending select o.StrikePrice).Distinct().ToList(); var callList = (from o in optionList where o.ContractType == (int)ContractType.CONTRACTTYPE_CALL_OPTION orderby o.StrikePrice descending select new ContractKeyVM(exchange, o.Contract)).ToList(); var putList = (from o in optionList where o.ContractType == (int)ContractType.CONTRACTTYPE_PUT_OPTION orderby o.StrikePrice descending select new ContractKeyVM(exchange, o.Contract)).ToList(); var marketDataList = await _marketdataHandler.SubMarketDataAsync(optionList.Select(c => new ContractKeyVM(c.Exchange, c.Contract))); var retList = _otcOptionHandler.MakeCallPutTDOptionData(strikeList, callList, putList, marketDataList); _subbedContracts = await _otcOptionHandler.SubTradingDeskDataAsync(optionList.Select(c => new ContractKeyVM(c.Exchange, c.Contract))); CallPutTDOptionVMCollection.Clear(); foreach (var vm in retList) { CallPutTDOptionVMCollection.Add(vm); var CallPositionLong = 0; var CallPositionShort = 0; var PutPositionLong = 0; var PutPositionShort = 0; var CallPositionVMLong = _tradeExHandler.PositionVMCollection.FirstOrDefault(c => c.Contract == vm.CallOptionVM.Contract && c.Direction == PositionDirectionType.PD_LONG); var PutPositionVMLong = _tradeExHandler.PositionVMCollection.FirstOrDefault(c => c.Contract == vm.PutOptionVM.Contract && c.Direction == PositionDirectionType.PD_LONG); var CallPositionVMShort = _tradeExHandler.PositionVMCollection.FirstOrDefault(c => c.Contract == vm.CallOptionVM.Contract && c.Direction == PositionDirectionType.PD_SHORT); var PutPositionVMShort = _tradeExHandler.PositionVMCollection.FirstOrDefault(c => c.Contract == vm.PutOptionVM.Contract && c.Direction == PositionDirectionType.PD_SHORT); if (CallPositionVMLong != null) { CallPositionLong = CallPositionVMLong.Position; } if (CallPositionVMShort != null) { CallPositionShort = CallPositionVMShort.Position; } if (PutPositionVMLong != null) { PutPositionLong = PutPositionVMLong.Position; } if (PutPositionVMShort != null) { PutPositionShort = PutPositionVMShort.Position; } vm.PutOptionVM.Position = PutPositionLong - PutPositionShort; vm.CallOptionVM.Position = CallPositionLong - CallPositionShort; } var strategyVM = CallPutTDOptionVMCollection.FirstOrDefault().CallStrategyVM ?? CallPutTDOptionVMCollection.LastOrDefault().CallStrategyVM; if (strategyVM != null) { pricingModelCB.ItemsSource = null; volModelLB.Content = null; riskFree_Interest.DataContext = null; adjustment.DataContext = null; AutoOrder_CheckBox.DataContext = null; underlyingEX1.ItemsSource = null; underlyingCB1.ItemsSource = null; orderConditionCombo.SelectedValue = null; underlyingContractCB1.ItemsSource = null; underlyingEX1.ItemsSource = _futurecontractList.Select(c => c.Exchange).Distinct(); pricingModelCB.ItemsSource = _otcOptionHandler.GetModelParamsVMCollection("pm"); if (strategyVM != null) { var pricingContractParamVM = strategyVM.PricingContractParams?.FirstOrDefault(); if (pricingContractParamVM != null) { var futureexchange = pricingContractParamVM.Exchange; var futurecontract = pricingContractParamVM.Contract; var futureunderlying = _futurecontractList.FirstOrDefault(c => c.Exchange == futureexchange && c.Contract == futurecontract)?.ProductID; var adjust = pricingContractParamVM.Adjust; var pricingmodel = strategyVM.PricingModel; var volmodel = strategyVM.VolModel; pricingModelCB.SelectedValue = pricingmodel; underlyingEX1.SelectedValue = futureexchange; underlyingCB1.SelectedValue = futureunderlying; underlyingContractCB1.SelectedValue = futurecontract; volModelLB.Content = volmodel; adjustment.Value = adjust; AutoOrder_CheckBox.DataContext = strategyVM; CountertextBox.DataContext = strategyVM; AutoMaxTradeUpdate((int)CountertextBox.Value); TickSizeIUD.DataContext = strategyVM; orderConditionCombo.SelectedValue = OrderConditionType.LIMIT; var modelVM = pricingModelCB.SelectedItem as ModelParamsVM; if (modelVM != null) { riskFree_Interest.DataContext = modelVM; } } } } } } }