-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic_parameter_engine.py
More file actions
116 lines (105 loc) · 3.8 KB
/
Copy pathdynamic_parameter_engine.py
File metadata and controls
116 lines (105 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python3
"""
Dynamic Parameter Engine v6.10 - More Conservative Short-Term Calls
"""
from datetime import datetime, timedelta
def get_next_friday(target_date):
days_ahead = 4 - target_date.weekday()
if days_ahead < 0:
days_ahead += 7
return target_date + timedelta(days=days_ahead)
def get_expiration(dte):
today = datetime(2026, 5, 12)
target = today + timedelta(days=dte)
exp = get_next_friday(target)
return exp.strftime("%Y-%m-%d")
def estimate_credit(strike, delta, dte, current_price):
base_credit_pct = 0.008 + (delta - 0.18) * 0.015
dte_factor = min(dte / 30, 1.0)
credit = round(strike * base_credit_pct * dte_factor, 2)
return credit
def estimate_strike(current_price, delta, dte, iv_rank, direction, ticker='TSLA'):
is_call = 'CALL' in direction.upper()
if dte <= 7:
base_otm = 0.055 # Wider for safety on short DTE
elif dte <= 15:
base_otm = 0.06
else:
base_otm = 0.065
otm_pct = base_otm + (delta - 0.20) * 0.10
if iv_rank > 50:
otm_pct *= 0.85
if is_call:
strike = round(current_price * (1 + otm_pct), 0)
else:
strike = round(current_price * (1 - otm_pct), 0)
if ticker == 'TSLL':
strike = round(strike * 0.97, 0)
return int(strike)
def get_dynamic_params(features, ticker='TSLA', current_price=445):
iv = features.get('iv_rank', 13)
ret_14d = features.get('recent_14d_return', 11.2)
bias = features.get('bias', 'bullish')
intraday_return = features.get('intraday_return', 0.0)
volume_surge = features.get('volume_surge', 1.0)
reversal = intraday_return < -3.0 and volume_surge > 1.5
high_iv = iv > 50
use_short_term_calls = reversal or high_iv
if ticker == 'TSLA':
if use_short_term_calls:
direction = 'SELL SHORT-TERM CALLS'
delta = 0.17 # More conservative for short DTE
dte = 5
profit_target = 0.45
size_note = "0.6% risk - tight management"
elif reversal:
direction = 'DEFENSIVE - SELL CALLS or IRON CONDOR'
delta = 0.20
dte = 22
profit_target = 0.45
size_note = "0.8% risk max"
elif bias == 'bullish' and ret_14d > 5 and iv < 40:
direction = 'SELL PUTS'
delta = 0.24
dte = 30
profit_target = 0.55
size_note = "1-2% risk"
else:
direction = 'SELL PUTS (reduced)'
delta = 0.22
dte = 26
profit_target = 0.50
size_note = "1% risk"
else:
if use_short_term_calls:
direction = 'SELL SHORT-TERM CALLS (small)'
delta = 0.16
dte = 4
profit_target = 0.40
size_note = "0.4% risk max"
else:
direction = 'SELL PUTS (conservative)'
delta = 0.18
dte = 22
profit_target = 0.45
size_note = "0.5% max"
exp_date = get_expiration(dte)
strike = estimate_strike(current_price, delta, dte, iv, direction, ticker)
credit = estimate_credit(strike, delta, dte, current_price)
return {
'ticker': ticker,
'direction': direction,
'delta': delta,
'dte': dte,
'expiration': exp_date,
'strike': strike,
'profit_target': profit_target,
'size_note': size_note,
'estimated_credit': credit,
'short_term_calls_active': use_short_term_calls,
'reason': f"Reversal={reversal}, HighIV={high_iv}"
}
if __name__ == "__main__":
current = {'iv_rank': 13, 'recent_14d_return': 11.2, 'intraday_return': -4.4, 'volume_surge': 1.8, 'bias': 'bullish'}
print(get_dynamic_params(current, 'TSLA', 425))
print(get_dynamic_params(current, 'TSLL', 14.5))