diff --git a/src/client/spark/AW2/UISettings/VolSurfaceGraphAxisRetension.cs b/src/client/spark/AW2/UISettings/VolSurfaceGraphAxisRetension.cs
new file mode 100644
index 000000000..767732aba
--- /dev/null
+++ b/src/client/spark/AW2/UISettings/VolSurfaceGraphAxisRetension.cs
@@ -0,0 +1,23 @@
+namespace mbts.spark {
+ using System.ComponentModel;
+
+ enum VolSurfaceGraphAxisRetension {
+ ///
+ /// When an expiration is selected, the zoom level and scroll position do not change (i.e.,
+ /// these values are 'shared' across expirations)
+ ///
+ None,
+ ///
+ /// When an expiration is selected, the zoom level and scroll position are adjusted to fit all
+ /// points in the expiration series (plus a bit of padding).
+ ///
+ [Description("Refit when selection changes")]
+ AutoFit,
+ ///
+ /// When an expiration is selected, the zoom level and scroll position are reset to the values
+ /// they held when the expiration was last selected
+ ///
+ [Description("Restore when selection changes")]
+ Expiration,
+ }
+}
diff --git a/src/client/spark/AW2/UISettings/VolSurfaceGraphSettings.cs b/src/client/spark/AW2/UISettings/VolSurfaceGraphSettings.cs
index 3e7437700..e3e963c57 100644
--- a/src/client/spark/AW2/UISettings/VolSurfaceGraphSettings.cs
+++ b/src/client/spark/AW2/UISettings/VolSurfaceGraphSettings.cs
@@ -57,7 +57,8 @@ namespace mbts.spark {
color = BTSColors.VolSurfaceGraph.implied_call
},
vol_path = get_default_vol_path_settings(),
- exp_bounds = new ExpGraphBounds[0]
+ exp_bounds = Array.Empty(),
+ axis_scale_retension = VolSurfaceGraphAxisRetension.None,
};
}
@@ -96,6 +97,8 @@ namespace mbts.spark {
[ProtoMember(11)]
public ExpGraphBounds[] exp_bounds;
+ [ProtoMember(12)]
+ public VolSurfaceGraphAxisRetension axis_scale_retension { get; set; }
//private LineSeriesSettings _vol_path;
//public LineSeriesSettings vol_path {
// get {
@@ -121,7 +124,8 @@ namespace mbts.spark {
atm.safe_equals(other.atm) &&
implied_atm.safe_equals(other.implied_atm) &&
vol_path.safe_equals(other.vol_path) &&
- exp_bounds.safe_sequence_equals(other.exp_bounds);
+ exp_bounds.safe_sequence_equals(other.exp_bounds) &&
+ axis_scale_retension == other.axis_scale_retension;
public override bool Equals(object obj) =>
Equals(obj as VolSurfaceGraphSettings);
diff --git a/src/client/spark/AW2/View/VolSurfaceView.xaml b/src/client/spark/AW2/View/VolSurfaceView.xaml
index 4ad0dd1ba..d3b24bbd7 100644
--- a/src/client/spark/AW2/View/VolSurfaceView.xaml
+++ b/src/client/spark/AW2/View/VolSurfaceView.xaml
@@ -11,6 +11,7 @@
xmlns:cv="clr-namespace:mbts.ui.converters"
xmlns:shell="clr-namespace:mbts.ui.shell"
xmlns:graph="clr-namespace:mbts.ui.controls.graph"
+ xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
Background="{StaticResource CommonBackground}"
@@ -203,6 +204,11 @@
+
+
+
@@ -476,12 +482,29 @@
Show Legend
-
+ MouseDoubleClick="_on_graph_mouse_double_click">
+
+
+
+
+
+
+
+
diff --git a/src/client/spark/AW2/View/VolSurfaceView.xaml.cs b/src/client/spark/AW2/View/VolSurfaceView.xaml.cs
index 236119a35..714d3efc7 100644
--- a/src/client/spark/AW2/View/VolSurfaceView.xaml.cs
+++ b/src/client/spark/AW2/View/VolSurfaceView.xaml.cs
@@ -4,11 +4,8 @@
using mbts.ui.controls;
using mbts.ui.controls.adorners;
using mbts.ui.converters;
- using mbts.ui.extensions;
using System;
- using System.Collections.Generic;
- using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
@@ -56,45 +53,8 @@
}
#endregion
- public void fit_axes_to_series() {
- if (_vol_curve_graph_vm?.axes?.Count != 2) {
- return;
- }
-
- var vis_series = _vol_curve_graph_vm.flat_visible_series.Where(s => s.points.Any()).ToList();
- if (!vis_series.Any()) {
- return;
- }
-
- Type tx = vis_series.Select(s => s.points.First().x.GetType()).Distinct().SingleOrDefault();
- if (tx != typeof(double)) {
- return;
- }
- Type ty = vis_series.Select(s => s.points.First().y.GetType()).Distinct().SingleOrDefault();
- if (ty != typeof(double)) {
- return;
- }
-
- if (_vol_curve_graph_vm.axes.TryGetFirst(a => a.position.is_horizontal(), out var x_axis) &&
- _vol_curve_graph_vm.axes.TryGetFirst(a => a.position.is_vertical(), out var y_axis)) {
- var points = vis_series.SelectMany(vs => vs.points);
- var x_points = points.Select(p => (double)p.x);
- if (x_points.Except(double.NaN).MinMax(out var x_min, out var x_max) && x_min < x_max) {
- double padding = (x_max - x_min) * 0.05;
- x_axis.minimum = x_min - padding;
- x_axis.maximum = x_max + padding;
- }
-
- var y_points = points.Select(p => (double)p.y);
- if (y_points.Except(double.NaN).MinMax(out var y_min, out var y_max) && y_min < y_max) {
- double padding = (y_max - y_min) * 0.05;
- y_axis.minimum = y_min - padding;
- y_axis.maximum = y_max + padding;
- }
- }
-
- _vol_curve_graph_vm?.reset_all_axes();
- }
+ public void fit_axes_to_series() =>
+ _vol_curve_graph_vm?.fit_axes_to_bounds();
void _on_is_legend_visible_changed(bool value) {
Disposable.dispose(ref _legend_popup);
diff --git a/src/client/spark/AW2/ViewModel/Graph/VolSurfaceGraphVM.cs b/src/client/spark/AW2/ViewModel/Graph/VolSurfaceGraphVM.cs
index d0e6eb254..250b8615d 100644
--- a/src/client/spark/AW2/ViewModel/Graph/VolSurfaceGraphVM.cs
+++ b/src/client/spark/AW2/ViewModel/Graph/VolSurfaceGraphVM.cs
@@ -24,8 +24,8 @@ namespace mbts.spark {
readonly VolSurfaceDisplayModel _model;
readonly VolSurfaceEventDemux _demux;
readonly Action _publish_show_implied_vol;
- readonly LinearAxisVM _x_axis = new();
- readonly LinearAxisVM _y_axis = new();
+ readonly LinearAxisVM _x_axis = new() { position = AxisPosition.BottomLeftToRight };
+ readonly LinearAxisVM _y_axis = new() { position = AxisPosition.LeftBottomToTop };
readonly Dictionary _expiration_graph_bounds;
readonly VolSurfaceGraphSettings _settings;
readonly ObservableCollection _expirations = new();
@@ -136,6 +136,13 @@ namespace mbts.spark {
public bool show_vol_path { get { return _show_vol_path; } set { _show_vol_path = value; _show_vol_path_changed(); } }
public IDialogCommand settings_command { get; private set; }
public VolSurfaceDisplayGridExpiration earliest_selected_expiration { get; set; }
+ public VolSurfaceGraphAxisRetension axis_retension {
+ get => _settings.axis_scale_retension;
+ set {
+ using var _ = detect_property_change();
+ _settings.axis_scale_retension = value;
+ }
+ }
public void set_visible_expiration(VolSurfaceDisplayGridExpiration expiration) {
_earliest_selected_expiration = expiration;
@@ -215,97 +222,69 @@ namespace mbts.spark {
}
IEnumerable _get_points(VolSurfaceDisplayGridExpiration exp, VolSurfaceGraphSeriesType type) {
- if (type == VolSurfaceGraphSeriesType.CandidateCallWing
- || type == VolSurfaceGraphSeriesType.CandidatePutWing
- || type == VolSurfaceGraphSeriesType.CandidateInnerCurve
- || type == VolSurfaceGraphSeriesType.CandidateControlPoints
- || type == VolSurfaceGraphSeriesType.CandidateSpecialCalls
- || type == VolSurfaceGraphSeriesType.CandidateSpecialPuts
- || type == VolSurfaceGraphSeriesType.CandidateATM) {
- var disp_graph = _model.get_candidate_exp_vol_graph(exp);
- if (disp_graph != null) {
- return type switch {
- VolSurfaceGraphSeriesType.CandidateCallWing => disp_graph.all_points
- .Where(t => t.Item1 >= disp_graph.call_wing_start)
- .Select(t => new GraphPointVM(t.Item1, t.Item2))
- .ToList(),
- VolSurfaceGraphSeriesType.CandidatePutWing => disp_graph.all_points
- .Where(t => t.Item1 <= disp_graph.put_wing_start)
- .Select(t => new GraphPointVM(t.Item1, t.Item2))
- .ToList(),
- VolSurfaceGraphSeriesType.CandidateInnerCurve => disp_graph.all_points
- .Where(t => t.Item1.is_within_range(disp_graph.put_wing_start, disp_graph.call_wing_start))
- .Select(t => new GraphPointVM(t.Item1, t.Item2))
- .ToList(),
- VolSurfaceGraphSeriesType.CandidateControlPoints => Enumerable.Empty(),
- VolSurfaceGraphSeriesType.CandidateSpecialCalls => disp_graph.special_call_points
- .Select(t => new GraphPointVM(t.Item1, t.Item2))
- .ToList(),
- VolSurfaceGraphSeriesType.CandidateSpecialPuts => disp_graph.special_put_points
- .Select(t => new GraphPointVM(t.Item1, t.Item2))
- .ToList(),
- VolSurfaceGraphSeriesType.CandidateATM => new GraphPointVM[] {
- new(disp_graph.atm_point.Item1, disp_graph.atm_point.Item2)
+ InvalidOperationException _unexpected_series_type_ex() =>
+ new($"Unexpected graph series type '{type}'");
+
+ if (type.is_vol_path()) {
+ return type switch {
+ VolSurfaceGraphSeriesType.CommittedVolPath =>
+ _model.get_committed_volpath(exp).Select(tup => new GraphPointVM(tup.Item1, tup.Item2)),
+ VolSurfaceGraphSeriesType.CandidateVolPath =>
+ _model.get_candidate_volpath(exp).Select(tup => new GraphPointVM(tup.Item1, tup.Item2)),
+ _ => throw _unexpected_series_type_ex(),
+ };
+ }
+
+ if (type.is_candidate()) {
+ var graph = _model.get_candidate_exp_vol_graph(exp);
+ if (graph is not null) {
+ var pts = type switch {
+ VolSurfaceGraphSeriesType.CandidateCallWing => graph.real_call_wing_points(),
+ VolSurfaceGraphSeriesType.CandidatePutWing => graph.real_put_wing_points(),
+ VolSurfaceGraphSeriesType.CandidateInnerCurve => graph.real_inner_curve_points(),
+ VolSurfaceGraphSeriesType.CandidateControlPoints => graph.real_control_points(),
+ VolSurfaceGraphSeriesType.CandidateSpecialCalls => graph.real_special_call_points(),
+ VolSurfaceGraphSeriesType.CandidateSpecialPuts => graph.real_special_put_points(),
+ VolSurfaceGraphSeriesType.CandidateATM => new (double x, double y)[] {
+ new(graph.atm_point.Item1, graph.atm_point.Item2)
},
- _ => Enumerable.Empty(),
+ _ => throw _unexpected_series_type_ex(),
};
+ return pts.Select(pt => new GraphPointVM(pt.x, pt.y)).ToList();
}
}
- if (type == VolSurfaceGraphSeriesType.CommittedCallWing
- || type == VolSurfaceGraphSeriesType.CommittedPutWing
- || type == VolSurfaceGraphSeriesType.CommittedInnerCurve
- || type == VolSurfaceGraphSeriesType.CommittedControlPoints
- || type == VolSurfaceGraphSeriesType.CommittedSpecialCalls
- || type == VolSurfaceGraphSeriesType.CommittedSpecialPuts
- || type == VolSurfaceGraphSeriesType.CommittedATM) {
- var disp_graph = _model.get_committed_exp_vol_graph(exp);
- if (disp_graph != null) {
- return type switch {
- VolSurfaceGraphSeriesType.CommittedCallWing => disp_graph.all_points
- .Where(t => t.Item1 >= disp_graph.call_wing_start)
- .Select(t => new GraphPointVM(t.Item1, t.Item2))
- .ToList(),
- VolSurfaceGraphSeriesType.CommittedPutWing => disp_graph.all_points
- .Where(t => t.Item1 <= disp_graph.put_wing_start)
- .Select(t => new GraphPointVM(t.Item1, t.Item2))
- .ToList(),
- VolSurfaceGraphSeriesType.CommittedInnerCurve => disp_graph.all_points
- .Where(t => t.Item1.is_within_range(disp_graph.put_wing_start, disp_graph.call_wing_start))
- .Select(t => new GraphPointVM(t.Item1, t.Item2))
- .ToList(),
- VolSurfaceGraphSeriesType.CommittedControlPoints => Enumerable.Empty(),
- VolSurfaceGraphSeriesType.CommittedSpecialCalls => disp_graph.special_call_points
- .Select(t => new GraphPointVM(t.Item1, t.Item2)).ToList(),
- VolSurfaceGraphSeriesType.CommittedSpecialPuts => disp_graph.special_put_points
- .Select(t => new GraphPointVM(t.Item1, t.Item2)).ToList(),
- VolSurfaceGraphSeriesType.CommittedATM => new GraphPointVM[] {
- new(disp_graph.atm_point.Item1, disp_graph.atm_point.Item2)
+ if (type.is_committed()) {
+ var graph = _model.get_committed_exp_vol_graph(exp);
+ if (graph is not null) {
+ var pts = type switch {
+ VolSurfaceGraphSeriesType.CommittedCallWing => graph.real_call_wing_points(),
+ VolSurfaceGraphSeriesType.CommittedPutWing => graph.real_put_wing_points(),
+ VolSurfaceGraphSeriesType.CommittedInnerCurve => graph.real_inner_curve_points(),
+ VolSurfaceGraphSeriesType.CommittedControlPoints => graph.real_control_points(),
+ VolSurfaceGraphSeriesType.CommittedSpecialCalls => graph.real_special_call_points(),
+ VolSurfaceGraphSeriesType.CommittedSpecialPuts => graph.real_special_put_points(),
+ VolSurfaceGraphSeriesType.CommittedATM => new (double x, double y)[] {
+ new(graph.atm_point.Item1, graph.atm_point.Item2)
},
- _ => Enumerable.Empty(),
+ _ => throw _unexpected_series_type_ex(),
};
+ return pts.Select(pt => new GraphPointVM(pt.x, pt.y)).ToList();
}
}
- if (type == VolSurfaceGraphSeriesType.ImpliedVolATM
- || type == VolSurfaceGraphSeriesType.ImpliedVolCalls
- || type == VolSurfaceGraphSeriesType.ImpliedVolPuts) {
+ if (type.is_implied()) {
var implied_vol_data = _model.get_market_market_implied_vols(exp);
- if (implied_vol_data != null) {
- switch (type) {
- case VolSurfaceGraphSeriesType.ImpliedVolATM: return new GraphPointVM[] { new(implied_vol_data.atm_strike, implied_vol_data.atm_vol) };
- case VolSurfaceGraphSeriesType.ImpliedVolCalls: return implied_vol_data.call_rawk_vols.Select(kvp => new GraphPointVM(kvp.Key, kvp.Value)).ToList();
- case VolSurfaceGraphSeriesType.ImpliedVolPuts: return implied_vol_data.put_rawk_vols.Select(kvp => new GraphPointVM(kvp.Key, kvp.Value)).ToList();
- }
+ if (implied_vol_data is not null) {
+ return type switch {
+ VolSurfaceGraphSeriesType.ImpliedVolATM => new GraphPointVM[] { new(implied_vol_data.atm_strike, implied_vol_data.atm_vol) },
+ VolSurfaceGraphSeriesType.ImpliedVolCalls => implied_vol_data.call_rawk_vols.Select(kvp => new GraphPointVM(kvp.Key, kvp.Value)).ToList(),
+ VolSurfaceGraphSeriesType.ImpliedVolPuts => implied_vol_data.put_rawk_vols.Select(kvp => new GraphPointVM(kvp.Key, kvp.Value)).ToList(),
+ _ => throw _unexpected_series_type_ex(),
+ };
}
}
- if (type == VolSurfaceGraphSeriesType.CommittedVolPath) {
- return _model.get_committed_volpath(exp).Select(tup => new GraphPointVM(tup.Item1, tup.Item2));
- }
- if (type == VolSurfaceGraphSeriesType.CandidateVolPath) {
- return _model.get_candidate_volpath(exp).Select(tup => new GraphPointVM(tup.Item1, tup.Item2));
- }
return Enumerable.Empty();
}
@@ -328,8 +307,14 @@ namespace mbts.spark {
var sec_exp = vsd_exp.ToSecurityExp();
_expiration_graph_bounds[sec_exp] = new ExpGraphBounds {
exp = new SecurityExpirationProto { security = sec_exp.security_tuple, expiration_oa_date = sec_exp.expiration.ToOADate() },
- x_bounds = new AxisBounds { min = _x_axis.minimum, max = _x_axis.maximum },
- y_bounds = new AxisBounds { min = _y_axis.minimum, max = _y_axis.maximum }
+ x_bounds = new AxisBounds {
+ min = _x_axis.minimum,
+ max = _x_axis.maximum,
+ },
+ y_bounds = new AxisBounds {
+ min = _y_axis.minimum,
+ max = _y_axis.maximum,
+ },
};
}
}
@@ -339,12 +324,20 @@ namespace mbts.spark {
foreach (var ss in graph_vm.series_sets) {
ss.is_visible = exp_to_make_visible.Equals(ss.args);
}
- if (_expiration_graph_bounds.TryGetValue(exp_to_make_visible.ToSecurityExp(), out var egb)) {
- _x_axis.minimum = egb.x_bounds.min;
- _x_axis.maximum = egb.x_bounds.max;
- _y_axis.minimum = egb.y_bounds.min;
- _y_axis.maximum = egb.y_bounds.max;
- graph_vm.reset_all_axes();
+ switch (axis_retension) {
+ case VolSurfaceGraphAxisRetension.Expiration:
+ if (_expiration_graph_bounds.TryGetValue(exp_to_make_visible.ToSecurityExp(), out var egb)) {
+ _x_axis.minimum = egb.x_bounds.min;
+ _x_axis.maximum = egb.x_bounds.max;
+ _y_axis.minimum = egb.y_bounds.min;
+ _y_axis.maximum = egb.y_bounds.max;
+ graph_vm.plot_model.ResetAllAxes();
+ graph_vm.plot_model.InvalidatePlot(false);
+ }
+ break;
+ case VolSurfaceGraphAxisRetension.AutoFit:
+ graph_vm.fit_axes_to_bounds();
+ break;
}
}
diff --git a/src/client/spark/AW2/VolSurfaceExtensions.cs b/src/client/spark/AW2/VolSurfaceExtensions.cs
index acbd0e428..ef5b17df8 100644
--- a/src/client/spark/AW2/VolSurfaceExtensions.cs
+++ b/src/client/spark/AW2/VolSurfaceExtensions.cs
@@ -1,11 +1,13 @@
namespace mbts.spark {
using bts.api;
using bts.api.analytics;
+ using bts.utils;
using mbts.analytics;
using mbts.spark.VolSurface;
using mbts.ui.controls;
+ using System;
using System.Collections.Generic;
using System.Linq;
@@ -68,6 +70,12 @@
_ => false,
};
+ public static bool is_vol_path(this VolSurfaceGraphSeriesType series_type) =>
+ series_type switch {
+ VolSurfaceGraphSeriesType.CandidateVolPath or VolSurfaceGraphSeriesType.CommittedVolPath => true,
+ _ => false,
+ };
+
public static IEnumerable select_exp(this IEnumerable rows) =>
rows.Select(r => r.expiration.ToVSExp());
@@ -79,5 +87,29 @@
public static IEnumerable where_slave(this IEnumerable rows) =>
rows.Where(r => !r.is_slave);
+
+ public static IEnumerable<(double x, double y)> real_call_wing_points(this VolCurveDisplayGraph graph) =>
+ graph.real_all_points().Where(pt => pt.x >= graph.call_wing_start);
+
+ public static IEnumerable<(double x, double y)> real_put_wing_points(this VolCurveDisplayGraph graph) =>
+ graph.real_all_points().Where(pt => pt.x <= graph.put_wing_start);
+
+ public static IEnumerable<(double x, double y)> real_inner_curve_points(this VolCurveDisplayGraph graph) =>
+ graph.real_all_points().Where(pt => pt.x.is_within_range(graph.put_wing_start, graph.call_wing_start));
+
+ public static IEnumerable<(double x, double y)> real_control_points(this VolCurveDisplayGraph graph) =>
+ Enumerable.Empty<(double x, double y)>();
+
+ public static IEnumerable<(double x, double y)> real_special_call_points(this VolCurveDisplayGraph graph) =>
+ _select_real_points(graph.special_call_points);
+
+ public static IEnumerable<(double x, double y)> real_special_put_points(this VolCurveDisplayGraph graph) =>
+ _select_real_points(graph.special_put_points);
+
+ public static IEnumerable<(double x, double y)> real_all_points(this VolCurveDisplayGraph graph) =>
+ _select_real_points(graph.all_points);
+
+ static IEnumerable<(double x, double y)> _select_real_points(IEnumerable> points) =>
+ points.Where(pt => pt.Item1.is_real() && pt.Item2.is_real()).Select(t => (t.Item1, t.Item2));
}
}
diff --git a/src/client/spark/view/Controls/Graph/AxisVM.cs b/src/client/spark/view/Controls/Graph/AxisVM.cs
index 757f75a89..ede1a970a 100644
--- a/src/client/spark/view/Controls/Graph/AxisVM.cs
+++ b/src/client/spark/view/Controls/Graph/AxisVM.cs
@@ -128,7 +128,7 @@ namespace mbts.spark {
}
public double minimum {
- get => _model.Minimum;
+ get => _model.ActualMinimum;
set {
using var _ = detect_property_change();
_model.Minimum = value;
@@ -136,7 +136,7 @@ namespace mbts.spark {
}
public double maximum {
- get => _model.Maximum;
+ get => _model.ActualMaximum;
set {
using var _ = detect_property_change();
_model.Maximum = value;
diff --git a/src/client/spark/view/Controls/Graph/BTSGraphVM.cs b/src/client/spark/view/Controls/Graph/BTSGraphVM.cs
index 3e3cc2a57..42c5341cb 100644
--- a/src/client/spark/view/Controls/Graph/BTSGraphVM.cs
+++ b/src/client/spark/view/Controls/Graph/BTSGraphVM.cs
@@ -1,6 +1,7 @@
namespace mbts.spark {
using mbts.ui.controls;
using mbts.ui.controls.graph;
+ using mbts.ui.extensions;
using mbts.ui.shell;
using mbts.ui.utility;
@@ -66,6 +67,67 @@
public IEnumerable