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
|
@property
|
||||||
def current_value(self) -> float:
|
def current_value(self) -> float:
|
||||||
# TODO: Implement real-time price fetching
|
# 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
|
return self.shares * self.entry_price
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def potential_profit(self) -> float:
|
def potential_profit(self) -> float:
|
||||||
"""Calculate potential profit at target price"""
|
"""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
|
return (self.target_price - self.entry_price) * self.shares
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def potential_loss(self) -> float:
|
def potential_loss(self) -> float:
|
||||||
"""Calculate potential loss at stop loss"""
|
"""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
|
return (self.stop_loss - self.entry_price) * self.shares
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def risk_reward_ratio(self) -> float:
|
def risk_reward_ratio(self) -> float:
|
||||||
"""Calculate risk/reward ratio"""
|
"""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_gain = self.target_price - self.entry_price
|
||||||
potential_risk = self.entry_price - self.stop_loss
|
potential_risk = self.entry_price - self.stop_loss
|
||||||
return abs(potential_gain / potential_risk) if potential_risk != 0 else 0
|
return abs(potential_gain / potential_risk) if potential_risk != 0 else 0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user