Spaces:
Sleeping
Sleeping
File size: 1,787 Bytes
459d15e cbdae8d 459d15e cbdae8d 459d15e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | import plotly.graph_objects as go
from plotly.subplots import make_subplots
from data.schema import Out
def plot_returns(returns):
fig = go.Figure()
for column in returns.columns:
fig.add_trace(
go.Scatter(
x=returns.index,
y=returns[column],
mode="lines",
name=column,
)
)
fig.update_layout(
title="Historical Returns",
xaxis_title="Date",
yaxis_title="Return",
template="plotly_white",
hovermode="x unified",
)
return fig
def plot_return_distributions(returns):
fig = go.Figure()
for column in returns.columns:
fig.add_trace(
go.Histogram(
x=returns[column],
name=column,
opacity=0.55,
nbinsx=80,
)
)
fig.update_layout(
title="Return Distributions",
xaxis_title="Return",
yaxis_title="Frequency",
barmode="overlay",
template="plotly_white",
)
return fig
def return_statistics(returns):
statistics = returns.agg(
[
"mean",
"std",
"min",
"max",
]
).T
statistics["skew"] = returns.skew()
statistics["kurtosis"] = returns.kurtosis()
statistics = statistics.reset_index()
statistics = statistics.rename(
columns={
"index": Out.FACTOR,
"mean": "Mean",
"std": "Std",
"min": "Min",
"max": "Max",
"skew": "Skewness",
"kurtosis": "Kurtosis",
}
)
return statistics |