Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
tschm committed Aug 16, 2023
1 parent 806aeb9 commit 9cfe01f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
1 change: 0 additions & 1 deletion tests/test_portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ def test_metrics(portfolio):

pd.testing.assert_series_equal(pd.Series(portfolio.metrics()), target)

from tinycta.plot import plot

def test_plot(portfolio):
fig = portfolio.plot()
Expand Down
28 changes: 21 additions & 7 deletions tinycta/port.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import numpy as np
import pandas as pd

pd.options.plotting.backend = "plotly"

from plotly.subplots import make_subplots
import plotly.graph_objects as go

from tinycta.month import monthlytable, Aggregate

pd.options.plotting.backend = "plotly"


def build_portfolio(prices, cashposition=None, aum=1e6):
"""
Expand Down Expand Up @@ -167,10 +167,24 @@ def metrics(self, days=252):
def plot(self, com=100, **kwargs):
fig = make_subplots(rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.02)

#fig.append_trace(
fig.add_trace(go.Scatter(x=self.nav_accum.index, y=self.nav_accum, name="NAV accumulated"), row=1, col=1)
fig.add_trace(go.Scatter(x=self.nav_accum.index, y=self.returns.ewm(com=com).std(), name="Volatility"), row=2, col=1)
#portfolio.nav_accum.plot(), row=1, col=1)
# fig.append_trace(
fig.add_trace(
go.Scatter(
x=self.nav_accum.index, y=self.nav_accum, name="NAV accumulated"
),
row=1,
col=1,
)
fig.add_trace(
go.Scatter(
x=self.nav_accum.index,
y=self.returns.ewm(com=com).std(),
name="Volatility",
),
row=2,
col=1,
)
# portfolio.nav_accum.plot(), row=1, col=1)

fig.update_layout(
{
Expand All @@ -181,4 +195,4 @@ def plot(self, com=100, **kwargs):
}
)

return fig
return fig

0 comments on commit 9cfe01f

Please sign in to comment.