Used monitoring_threshold to calculate status.

This commit is contained in:
Jamie Cash
2021-03-15 11:30:08 +00:00
parent 21ea7eb809
commit 4fdf4bedc7
4 changed files with 43 additions and 30 deletions
+23 -8
View File
@@ -59,10 +59,10 @@ class CorrelationStatus:
# All status's for symbol pair from monitoring. Status set from assessing coefficient for all timeframes from last run.
STATUS_NOT_CALCULATED = CorrelationStatus(-1, 'NOT CALC', 'Coefficient could not be calculated')
STATUS_ABOVE_MONITORING_THRESHOLD = CorrelationStatus(1, 'ABOVE', 'All coefficients equal to or above the monitoring '
STATUS_ABOVE_DIVERGENCE_THRESHOLD = CorrelationStatus(1, 'ABOVE', 'All coefficients equal to or above the divergence '
'threshold')
STATUS_BELOW_MONITORING_THRESHOLD = CorrelationStatus(2, 'BELOW', 'All coefficients below the monitoring threshold')
STATUS_INCONSISTENT = CorrelationStatus(3, 'INCONSISTENT', 'Coefficients not consistently above or below monitoring '
STATUS_BELOW_DIVERGENCE_THRESHOLD = CorrelationStatus(2, 'BELOW', 'All coefficients below the divergence threshold')
STATUS_INCONSISTENT = CorrelationStatus(3, 'INCONSISTENT', 'Coefficients not consistently above or below divergence '
'threshold')
@@ -78,6 +78,10 @@ class Correlation:
# coefficient than ths won't be monitored.
monitoring_threshold = 0.9
# Threshold for divergence. Correlation coefficients that were previously above the monitoring_threshold and fall
# below this threshold will be considered as having diverged
divergence_threshold = 0.8
# Toggle on whether we are monitoring or not. Set through start_monitor and stop_monitor
__monitoring = False
@@ -102,7 +106,14 @@ class Correlation:
# Dict: {Symbol: [retrieved datetime, ticks dataframe]}
__monitor_tick_data = {}
def __init__(self):
def __init__(self, monitoring_threshold=0.9, divergence_threshold=0.8):
"""
Initialises the Correlation class.
:param monitoring_threshold: Only correlations that are greater than or equal to this threshold will be
monitored.
:param divergence_threshold: Correlations that are being monitored and fall below this threshold are considered
to have diverged.
"""
# Logger
self.__log = logging.getLogger(__name__)
@@ -115,6 +126,10 @@ class Correlation:
# Create timer for continuous monitoring
self.__scheduler = sched.scheduler(time.time, time.sleep)
# Set thresholds
self.monitoring_threshold = monitoring_threshold
self.divergence_threshold = divergence_threshold
@property
def filtered_coefficient_data(self):
"""
@@ -672,10 +687,10 @@ class Correlation:
if None in values:
status = STATUS_NOT_CALCULATED
elif all(i >= self.monitoring_threshold for i in values):
status = STATUS_ABOVE_MONITORING_THRESHOLD
elif all(i < self.monitoring_threshold for i in values):
status = STATUS_BELOW_MONITORING_THRESHOLD
elif all(i >= self.divergence_threshold for i in values):
status = STATUS_ABOVE_DIVERGENCE_THRESHOLD
elif all(i < self.divergence_threshold for i in values):
status = STATUS_BELOW_DIVERGENCE_THRESHOLD
else:
status = STATUS_INCONSISTENT
+7 -7
View File
@@ -6,8 +6,7 @@ import matplotlib.dates
import matplotlib
import matplotlib.ticker as mticker
from mt5_correlation import correlation
from mt5_correlation.correlation import Correlation
from mt5_correlation import correlation as cor
from mt5_correlation.config import Config, SettingsDialog
from datetime import datetime, timedelta
import pytz
@@ -52,8 +51,8 @@ class MonitorFrame(wx.Frame):
self.__config = Config()
# Create correlation instance to maintain state of calculated coefficients. Set min coefficient from config
self.__cor = Correlation()
self.__cor.monitoring_threshold = self.__config.get("monitor.monitoring_threshold")
self.__cor = cor.Correlation(monitoring_threshold=self.__config.get("monitor.monitoring_threshold"),
divergence_threshold=self.__config.get("monitor.divergence_threshold"))
# Status bar. 2 fields, one for monitoring status and one for general status. On open, monitoring status is not
# monitoring. SetBackgroundColour will change colour of both. Couldn't find a way to set on single field only.
@@ -512,7 +511,7 @@ class DataTable(wx.grid.GridTableBase):
# Is status one of interest
value = self.GetValue(row, col)
if value != "":
if value in [correlation.STATUS_BELOW_MONITORING_THRESHOLD]:
if value in [cor.STATUS_BELOW_DIVERGENCE_THRESHOLD]:
attr.SetBackgroundColour(wx.YELLOW)
else:
attr.SetBackgroundColour(wx.WHITE)
@@ -565,8 +564,9 @@ class GraphPanel(wx.Panel):
# Check what data we have available
price_data_available = prices is not None and len(prices) == 2 and \
prices[0] is not None and prices[1] is not None
tick_data_available = ticks is not None and len(ticks) == 2 and ticks[0] is not None and ticks[1] is not None
prices[0] is not None and prices[1] is not None and len(prices[0]) > 0 and len(prices[1]) > 0
tick_data_available = ticks is not None and len(ticks) == 2 and ticks[0] is not None and ticks[1] is not None \
and len(ticks[0]) > 0 and len(ticks[1]) > 0
history_data_available = history is not None and len(history) > 0
symbols_selected = symbols is not None and len(symbols) == 2