Skip to content

Commit

Permalink
Merge pull request #202 from cvxgrp/201-inputdata-in-state
Browse files Browse the repository at this point in the history
input_data test
  • Loading branch information
tschm authored Nov 20, 2023
2 parents 3dc3c79 + 0efa7e5 commit 471d52b
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 79 deletions.
5 changes: 5 additions & 0 deletions cvx/simulator/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class _State:
prices: pd.Series = None
position: pd.Series = None
cash: float = 1e6
input_data: dict[str, Any] = field(default_factory=dict)

@property
def value(self) -> float:
Expand Down Expand Up @@ -331,6 +332,10 @@ def __iter__(self) -> Generator[tuple[pd.DatetimeIndex, _State], None, None]:
for t in self.index:
# valuation of the current position
self._state.prices = self.prices.loc[t]
self._state.input_data = {key: data.loc[t] for key, data in self.input_data.items()}



yield self.index[self.index <= t], self._state

def __setitem__(self, time: datetime, position: pd.Series) -> None:
Expand Down
Loading

0 comments on commit 471d52b

Please sign in to comment.