Skip to content

Commit

Permalink
Merge pull request #226 from cvxgrp/225-fix-portfolio-weight-issue
Browse files Browse the repository at this point in the history
little cash bug
  • Loading branch information
tschm authored Dec 1, 2023
2 parents f07e5df + fa7a309 commit 09c9824
Show file tree
Hide file tree
Showing 5 changed files with 641,456 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cvx/simulator/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def __getitem__(self, time: datetime) -> pd.Series:
"""
return self.stocks.loc[time]

def build(self) -> EquityPortfolio:
def build(self, extra=0) -> EquityPortfolio:
"""A function that creates a new instance of the EquityPortfolio
class based on the internal state of the Portfolio builder object.
Expand All @@ -365,6 +365,6 @@ class with the attributes (prices, stocks, initial_cash, trading_cost_model) equ
return EquityPortfolio(
prices=self.prices,
stocks=self.stocks,
initial_cash=self.initial_cash,
initial_cash=self.initial_cash, # - (self.prices.iloc[0]*self.stocks.iloc[0]).sum(),
trading_cost_model=self.trading_cost_model,
)
2 changes: 1 addition & 1 deletion cvx/simulator/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def trades_stocks(self) -> pd.DataFrame:
bought or sold by the portfolio at each point in time.
The resulting dataframe will have the same dimensions
as the stocks dataframe, with NaN values filled with zeros."""
t = self.stocks.diff()
t = self.stocks.fillna(0.0).diff()
t.loc[self.index[0]] = self.stocks.loc[self.index[0]]
return t.fillna(0.0)

Expand Down
634,310 changes: 634,310 additions & 0 deletions experiments/data.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 09c9824

Please sign in to comment.