refactor: Add None checks to Position class property methods
This commit is contained in:
parent
3a962fb685
commit
0cb11574a3
@ -14,21 +14,30 @@ class Position:
|
||||
@property
|
||||
def current_value(self) -> float:
|
||||
# TODO: Implement real-time price fetching
|
||||
if self.entry_price is None or self.shares is None:
|
||||
return 0.0
|
||||
return self.shares * self.entry_price
|
||||
|
||||
@property
|
||||
def potential_profit(self) -> float:
|
||||
"""Calculate potential profit at target price"""
|
||||
if self.target_price is None or self.entry_price is None or self.shares is None:
|
||||
return 0.0
|
||||
return (self.target_price - self.entry_price) * self.shares
|
||||
|
||||
@property
|
||||
def potential_loss(self) -> float:
|
||||
"""Calculate potential loss at stop loss"""
|
||||
if self.stop_loss is None or self.entry_price is None or self.shares is None:
|
||||
return 0.0
|
||||
return (self.stop_loss - self.entry_price) * self.shares
|
||||
|
||||
@property
|
||||
def risk_reward_ratio(self) -> float:
|
||||
"""Calculate risk/reward ratio"""
|
||||
if (self.target_price is None or self.entry_price is None or
|
||||
self.stop_loss is None):
|
||||
return 0.0
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user