Skip to content

Commit

Permalink
update time component, TWAP checker
Browse files Browse the repository at this point in the history
  • Loading branch information
vince-taoshi committed Feb 24, 2025
1 parent 35865fe commit 9d0f3cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
21 changes: 10 additions & 11 deletions vali_objects/utils/risk_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,23 @@ def risk_assessment_leverage_advancement_criteria(position: Position) -> bool:
@staticmethod
def risk_assessment_time_utilization(position: Position) -> float:
"""Flags the position if the time based criteria is not met"""
# First filter for all orders that are stepping into a losing position
time_decay = ValiConfig.RISK_PROFILING_TIME_DECAY
time_cycle = ValiConfig.RISK_PROFILING_TIME_CYCLE

# First make a determination on the entry and exit times
open_time = position.orders[0].processed_ms
close_time = position.orders[-1].processed_ms
position_orders = position.orders
if len(position_orders) < 2:
return 0 # less than two steps will never flag the position

# Now determine all suspect orders
# TWAP orders are monatome_orders
monatome_position = RiskProfiling.monatome_positions(position)
monatome_orders = monatome_position.orders

# now look at the time criteria between orders
# now look at the time deltas between orders
order_times = [order.processed_ms for order in monatome_orders]
time_deltas = np.diff(order_times) / time_cycle # convert to hours
if position.is_closed_position:
order_times = order_times[:-1] # excluding the last TP/SL order
time_deltas = np.diff(order_times) / 1000 # convert ms to s
time_deltas_var = float(np.var(time_deltas))

# now apply the time decay
return 0
return time_deltas_var

@staticmethod
def risk_assessment_time_criteria(position: Position) -> bool:
Expand Down
8 changes: 4 additions & 4 deletions vali_objects/vali_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ class ValiConfig:
RISK_PROFILING_SCOPING_MECHANIC = 100
RISK_PROFILING_SIGMOID_SHIFT = 0.1
RISK_PROFILING_SIGMOID_SPREAD = 50
RISK_PROFILING_TIME_DECAY = 5
RISK_PROFILING_TIME_CYCLE = POSITIONAL_EQUIVALENCE_WINDOW_MS
RISK_PROFILING_TIME_CRITERIA = 0.5
# RISK_PROFILING_TIME_DECAY = 5
# RISK_PROFILING_TIME_CYCLE = POSITIONAL_EQUIVALENCE_WINDOW_MS
RISK_PROFILING_TIME_CRITERIA = 300 # in seconds, threshold for variance of order time intervals

PLAGIARISM_MATCHING_TIME_RESOLUTION_MS = 60 * 1000 * 2 # 2 minutes
PLAGIARISM_MAX_LAGS = 60
PLAGIARISM_LOOKBACK_RANGE_MS = 10 * 24 * 60 * 60 * 1000 # 10 days
PLAGIARISM_FOLLOWER_TIMELAG_THRESHOLD = 1.0005
PLAGIARISM_FOLLOWER_TIMELAG_THRESHOLD = 1.0005
PLAGIARISM_FOLLOWER_SIMILARITY_THRESHOLD = 0.75
PLAGIARISM_REPORTING_THRESHOLD = 0.8
PLAGIARISM_REFRESH_TIME_MS = 1000 * 60 * 60 * 24 # 1 day
Expand Down

0 comments on commit 9d0f3cc

Please sign in to comment.