Skip to content

Commit

Permalink
Changed signature for features
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaron committed Jul 31, 2024
1 parent a2c10e9 commit 92edd01
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions roboquant/ml/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@

class Feature(ABC):
"""Features allows to:
- extract features from an event and/or account.
- extract features from an event or account.
- transform other features.
"""

@abstractmethod
def calc(self, evt: Event, account: Account | None) -> NDArray:
def calc(self, evt: Event, account: Account) -> NDArray:
"""
Return the result as a 1-dimensional NDArray.
The result should always be the same size. If a value cannot be calculated at a certain
tiem, it should return a float NaN.
item, it should return a float NaN.
"""

@abstractmethod
Expand Down Expand Up @@ -167,7 +167,7 @@ def calc(self, evt, account):
equity = account.equity_value()
for idx, asset in enumerate(self.assets):
position = account.positions.get(asset)
if position:
if position and position.size:
value = asset.contract_amount(position.size, position.mkt_price).convert(account.base_currency, evt.time)
pos_size = value / equity - 1.0
result[idx] = pos_size
Expand Down

0 comments on commit 92edd01

Please sign in to comment.