feat: Add target price and risk/reward calculations to position sizing
This commit is contained in:
parent
5f7c02a470
commit
a536ec5e15
@ -30,15 +30,21 @@ def main():
|
||||
if choice == "1":
|
||||
try:
|
||||
entry_price = get_float_input("Enter entry price: $")
|
||||
target_price = get_float_input("Enter target price: $")
|
||||
|
||||
position = calculator.calculate_position_size(entry_price)
|
||||
position = calculator.calculate_position_size(entry_price, target_price)
|
||||
|
||||
print("\nPosition Details:")
|
||||
print(f"Shares: {position['shares']}")
|
||||
print(f"Position Value: ${position['position_value']:.2f}")
|
||||
print(f"Risk Amount: ${position['risk_amount']:.2f}")
|
||||
print(f"Entry Price: ${entry_price:.2f}")
|
||||
print(f"Stop Loss Price: ${position['stop_loss']:.2f}")
|
||||
print(f"Max Loss at Stop: ${position['risk_amount']:.2f}") # This is your 1% risk
|
||||
print(f"Target Price: ${position['target_price']:.2f}")
|
||||
print(f"\nRisk Analysis:")
|
||||
print(f"Risk Amount (1%): ${position['risk_amount']:.2f}")
|
||||
print(f"Potential Loss: ${position['potential_loss']:.2f}")
|
||||
print(f"Potential Profit: ${position['potential_profit']:.2f}")
|
||||
print(f"Risk/Reward Ratio: {position['risk_reward_ratio']:.2f}")
|
||||
|
||||
except ValueError as e:
|
||||
print(f"Error: {e}")
|
||||
|
||||
@ -12,12 +12,13 @@ class PositionCalculator:
|
||||
self.risk_percentage = risk_percentage / 100.0 # Convert to decimal
|
||||
self.stop_loss_percentage = stop_loss_percentage / 100.0 # Convert to decimal
|
||||
|
||||
def calculate_position_size(self, entry_price: float) -> dict:
|
||||
def calculate_position_size(self, entry_price: float, target_price: float = None) -> dict:
|
||||
"""
|
||||
Calculate position size based on risk parameters
|
||||
|
||||
Args:
|
||||
entry_price (float): Planned entry price
|
||||
target_price (float, optional): Target price for the trade
|
||||
|
||||
Returns:
|
||||
dict: Position details including shares and dollar amounts
|
||||
@ -40,10 +41,21 @@ class PositionCalculator:
|
||||
# Calculate total position value
|
||||
position_value = shares * entry_price
|
||||
|
||||
return {
|
||||
result = {
|
||||
"shares": shares,
|
||||
"position_value": position_value,
|
||||
"risk_amount": risk_amount,
|
||||
"risk_per_share": risk_per_share,
|
||||
"stop_loss": stop_loss
|
||||
"stop_loss": stop_loss,
|
||||
"potential_loss": shares * (stop_loss - entry_price)
|
||||
}
|
||||
|
||||
# Add target price calculations if provided
|
||||
if target_price:
|
||||
result.update({
|
||||
"target_price": target_price,
|
||||
"potential_profit": shares * (target_price - entry_price),
|
||||
"risk_reward_ratio": abs((target_price - entry_price) / (entry_price - stop_loss))
|
||||
})
|
||||
|
||||
return result
|
||||
|
||||
Loading…
Reference in New Issue
Block a user