Skip to content

Commit

Permalink
Union
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Schmelzer committed Dec 10, 2023
1 parent 5cb95f6 commit 4541bb1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cvx/simulator/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class State:
cash: float = 1e6
input_data: dict[str, Any] = field(default_factory=dict)
model: TradingCostModel = None
time: datetime | None = None
time: datetime = None
days: int = 1

@property
Expand Down
10 changes: 9 additions & 1 deletion tests/test_reference/test_markowitz.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ def test_markowitz(builder, feasible, covariance, means):
"""
Test the markowitz portfolio complete with interest on cash and borrowing fees.
"""
# We loop over the entire history the builder
for t, state in builder:
# the very first and the very last elements are ignored
if t[-1] in feasible:
# State is exposing numerous quantities
print(state.cash_interest)
print(state.borrow_fees)
print(state.cash)
Expand All @@ -61,16 +64,21 @@ def test_markowitz(builder, feasible, covariance, means):
print(state.nav)
print(state.assets)

# We define the input needed for the optimizer
_input = OptimizationInput(
mean=means.loc[t[-1]],
covariance=covariance[t[-1]],
risk_target=0.01,
)

# optimize portfolio
w, _ = basic_markowitz(_input)

# update weights in builder
builder.weights = w

# makes only sense to address now
# the builder keeps also track of the state
# some quanties are only post-trading interesting
print(state.trades)
print(state.trading_costs)
print(state.cash)
Expand Down

0 comments on commit 4541bb1

Please sign in to comment.