-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPS_Kelly.py
40 lines (31 loc) · 1.57 KB
/
PS_Kelly.py
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
def calculate_rr(entry, tp, sl):
return abs((tp - entry) / (entry - sl))
def kelly_criterion(win_probability, reward_risk_ratio):
return win_probability - ((1 - win_probability) / reward_risk_ratio)
def main():
trading_stack = float(input("Enter your trading stack: "))
trades = []
while True:
entry = float(input("\nEnter entry price: "))
tp = float(input("Enter take profit (TP) price: "))
sl = float(input("Enter stop loss (SL) price: "))
win_probability = float(input("Enter win probability (as a decimal, e.g., 0.5 for 50%): "))
rr = calculate_rr(entry, tp, sl)
trades.append((entry, tp, sl, rr, win_probability))
another_trade = input("Do you want to input another trade? (y/n): ")
if another_trade.lower() != 'y':
break
kelly_values = [kelly_criterion(win_probability, rr) for entry, tp, sl, rr, win_probability in trades]
if sum(kelly_values) < 1:
adjusted_trading_sizes = [kelly_value * trading_stack for kelly_value in kelly_values]
else:
total_kelly_value = sum(kelly_values)
adjusted_trading_sizes = [kv * trading_stack / total_kelly_value for kv in kelly_values]
for i, (entry, tp, sl, rr, win_probability) in enumerate(trades, start=1):
print(f"\nTrade {i}:")
print(f"Risk-Reward Ratio: {rr:.2f}")
print(f"Win Probability: {win_probability * 100:.2f}%")
print(f"Kelly Criteria: {kelly_values[i-1]:.2f}")
print(f"Adjusted Trading Size: {adjusted_trading_sizes[i-1]:.2f}")
if __name__ == "__main__":
main()