feat: Add potential profit, loss, and risk/reward ratio calculations to positions
This commit is contained in:
parent
8740ccf9eb
commit
5f7c02a470
@ -38,6 +38,7 @@ def main():
|
||||
print(f"Position Value: ${position['position_value']:.2f}")
|
||||
print(f"Risk Amount: ${position['risk_amount']:.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
|
||||
|
||||
except ValueError as e:
|
||||
print(f"Error: {e}")
|
||||
@ -79,6 +80,9 @@ def main():
|
||||
print(f"Current Value: ${pos['current_value']:.2f}")
|
||||
print(f"Stop Loss: ${pos['stop_loss']:.2f}")
|
||||
print(f"Target: ${pos['target_price']:.2f}")
|
||||
print(f"Potential Profit: ${pos['potential_profit']:.2f}")
|
||||
print(f"Potential Loss: ${pos['potential_loss']:.2f}")
|
||||
print(f"Risk/Reward Ratio: {pos['risk_reward_ratio']:.2f}")
|
||||
|
||||
elif choice == "4":
|
||||
symbol = input("Enter symbol to remove: ")
|
||||
|
||||
@ -16,6 +16,23 @@ class Position:
|
||||
# TODO: Implement real-time price fetching
|
||||
return self.shares * self.entry_price
|
||||
|
||||
@property
|
||||
def potential_profit(self) -> float:
|
||||
"""Calculate potential profit at target price"""
|
||||
return (self.target_price - self.entry_price) * self.shares
|
||||
|
||||
@property
|
||||
def potential_loss(self) -> float:
|
||||
"""Calculate potential loss at stop loss"""
|
||||
return (self.stop_loss - self.entry_price) * self.shares
|
||||
|
||||
@property
|
||||
def risk_reward_ratio(self) -> float:
|
||||
"""Calculate risk/reward ratio"""
|
||||
potential_gain = self.target_price - self.entry_price
|
||||
potential_risk = self.entry_price - self.stop_loss
|
||||
return abs(potential_gain / potential_risk) if potential_risk != 0 else 0
|
||||
|
||||
class Portfolio:
|
||||
def __init__(self):
|
||||
self.positions: List[Position] = []
|
||||
@ -38,7 +55,10 @@ class Portfolio:
|
||||
"shares": p.shares,
|
||||
"current_value": p.current_value,
|
||||
"stop_loss": p.stop_loss,
|
||||
"target_price": p.target_price
|
||||
"target_price": p.target_price,
|
||||
"potential_profit": p.potential_profit,
|
||||
"potential_loss": p.potential_loss,
|
||||
"risk_reward_ratio": p.risk_reward_ratio
|
||||
}
|
||||
for p in self.positions
|
||||
]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user