Spaces:
Runtime error
Runtime error
huggingface112
commited on
Commit
•
bd05e46
1
Parent(s):
c121d97
restyling index
Browse files- appComponents.py +44 -16
- index_page.py +57 -19
- styling.py +4 -1
appComponents.py
CHANGED
@@ -24,7 +24,6 @@ class TotalReturnCard(Viewer):
|
|
24 |
|
25 |
start_date = param.Parameter()
|
26 |
end_date = param.Parameter()
|
27 |
-
|
28 |
b_stock_df = param.Parameter()
|
29 |
p_stock_df = param.Parameter()
|
30 |
|
@@ -192,8 +191,9 @@ class TotalReturnCard(Viewer):
|
|
192 |
self.report.object = report
|
193 |
self.plot_pane.object = fig
|
194 |
|
195 |
-
def __init__(self, b_stock_df, p_stock_df, **params):
|
196 |
-
|
|
|
197 |
self.b_stock_df = b_stock_df
|
198 |
self.p_stock_df = p_stock_df
|
199 |
self._date_range = pn.widgets.DateRangeSlider(
|
@@ -214,9 +214,14 @@ class TotalReturnCard(Viewer):
|
|
214 |
# self._sync_widgets()
|
215 |
|
216 |
def __panel__(self):
|
217 |
-
self._layout = pn.Card(self._date_range,
|
218 |
-
|
219 |
-
|
|
|
|
|
|
|
|
|
|
|
220 |
return self._layout
|
221 |
|
222 |
# @param.depends('value', 'width', watch=True)
|
@@ -233,7 +238,9 @@ class DrawDownCard(Viewer):
|
|
233 |
selected_key_column = param.Parameter()
|
234 |
calcualted_p_stock = param.Parameter()
|
235 |
|
236 |
-
def __init__(self, calculated_p_stock, **params):
|
|
|
|
|
237 |
self.select = pn.widgets.Select(
|
238 |
name='Select', value='盈利', options=['盈利', '回报'])
|
239 |
self.calculated_p_stock = calculated_p_stock
|
@@ -298,7 +305,9 @@ class DrawDownCard(Viewer):
|
|
298 |
self.select,
|
299 |
self.drawdown_plot,
|
300 |
header=pn.Row(pn.pane.Str('回撤分析')),
|
301 |
-
|
|
|
|
|
302 |
)
|
303 |
return self._layout
|
304 |
|
@@ -416,7 +425,9 @@ class HistReturnCard(Viewer):
|
|
416 |
agg_bhb['period_str'] = agg_bhb.index.map(lambda x: str(x))
|
417 |
return agg_bhb
|
418 |
|
419 |
-
def __init__(self, calculated_p_stock, calculated_b_stock, **params):
|
|
|
|
|
420 |
self.calculated_p_stock = calculated_p_stock
|
421 |
self.calculated_b_stock = calculated_b_stock
|
422 |
|
@@ -434,8 +445,13 @@ class HistReturnCard(Viewer):
|
|
434 |
|
435 |
def __panel__(self):
|
436 |
self._layout = pn.Card(pn.Param(self.param.select_resolution, name='选择周期'),
|
437 |
-
self.return_barplot,
|
438 |
-
|
|
|
|
|
|
|
|
|
|
|
439 |
return self._layout
|
440 |
|
441 |
|
@@ -524,7 +540,9 @@ class PortfolioComposationCard(Viewer):
|
|
524 |
# ))
|
525 |
return fig.to_dict()
|
526 |
|
527 |
-
def __init__(self, analytic_df, **params):
|
|
|
|
|
528 |
self.p_stock_df = analytic_df
|
529 |
self.p_stock_df = processing.calculate_weighted_return(self.p_stock_df,
|
530 |
start=self.p_stock_df.time.min(),
|
@@ -553,8 +571,14 @@ class PortfolioComposationCard(Viewer):
|
|
553 |
super().__init__(**params)
|
554 |
|
555 |
def __panel__(self):
|
556 |
-
self._layout = pn.Card(self.datetime_picker,
|
557 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
558 |
return self._layout
|
559 |
|
560 |
@param.depends('datetime_picker.value', 'p_stock_df', watch=True)
|
@@ -629,7 +653,9 @@ class BestAndWorstStocks(Viewer):
|
|
629 |
df = self._get_cum_return(df)
|
630 |
return df.sort_values(by='cum_pnl', ascending=False)
|
631 |
|
632 |
-
def __init__(self, analytic_df, **params):
|
|
|
|
|
633 |
self.analytic_df = analytic_df
|
634 |
self._date_range = pn.widgets.DateRangeSlider(
|
635 |
name='选择计算回报的时间区间',
|
@@ -657,7 +683,9 @@ class BestAndWorstStocks(Viewer):
|
|
657 |
self.best_5_tabulator,
|
658 |
pn.pane.Str('加权回报率最低回报5只股票'),
|
659 |
self.worst_5_tabulator,
|
660 |
-
max_width=
|
|
|
|
|
661 |
header=pn.Row(
|
662 |
pn.pane.Str(self.description),
|
663 |
pn.widgets.TooltipIcon(value=self.tooltip)
|
|
|
24 |
|
25 |
start_date = param.Parameter()
|
26 |
end_date = param.Parameter()
|
|
|
27 |
b_stock_df = param.Parameter()
|
28 |
p_stock_df = param.Parameter()
|
29 |
|
|
|
191 |
self.report.object = report
|
192 |
self.plot_pane.object = fig
|
193 |
|
194 |
+
def __init__(self, b_stock_df, p_stock_df, max_width, min_width, **params):
|
195 |
+
self.max_width = max_width
|
196 |
+
self.min_width = min_width
|
197 |
self.b_stock_df = b_stock_df
|
198 |
self.p_stock_df = p_stock_df
|
199 |
self._date_range = pn.widgets.DateRangeSlider(
|
|
|
214 |
# self._sync_widgets()
|
215 |
|
216 |
def __panel__(self):
|
217 |
+
self._layout = pn.Card(self._date_range,
|
218 |
+
self.report,
|
219 |
+
self.plot_pane,
|
220 |
+
max_width=self.max_width,
|
221 |
+
min_width=self.min_width,
|
222 |
+
styles=styling.card_style,
|
223 |
+
header=pn.Row(pn.pane.Str('投资组合总结'),
|
224 |
+
pn.widgets.TooltipIcon(value=description.summary_card)))
|
225 |
return self._layout
|
226 |
|
227 |
# @param.depends('value', 'width', watch=True)
|
|
|
238 |
selected_key_column = param.Parameter()
|
239 |
calcualted_p_stock = param.Parameter()
|
240 |
|
241 |
+
def __init__(self, calculated_p_stock, max_width, min_width, **params):
|
242 |
+
self.max_width = max_width
|
243 |
+
self.min_width = min_width
|
244 |
self.select = pn.widgets.Select(
|
245 |
name='Select', value='盈利', options=['盈利', '回报'])
|
246 |
self.calculated_p_stock = calculated_p_stock
|
|
|
305 |
self.select,
|
306 |
self.drawdown_plot,
|
307 |
header=pn.Row(pn.pane.Str('回撤分析')),
|
308 |
+
max_width=self.max_width,
|
309 |
+
min_width=self.min_width,
|
310 |
+
styles=styling.card_style,
|
311 |
)
|
312 |
return self._layout
|
313 |
|
|
|
425 |
agg_bhb['period_str'] = agg_bhb.index.map(lambda x: str(x))
|
426 |
return agg_bhb
|
427 |
|
428 |
+
def __init__(self, calculated_p_stock, calculated_b_stock, max_width, min_width, **params):
|
429 |
+
self.max_width = max_width
|
430 |
+
self.min_width = min_width
|
431 |
self.calculated_p_stock = calculated_p_stock
|
432 |
self.calculated_b_stock = calculated_b_stock
|
433 |
|
|
|
445 |
|
446 |
def __panel__(self):
|
447 |
self._layout = pn.Card(pn.Param(self.param.select_resolution, name='选择周期'),
|
448 |
+
self.return_barplot,
|
449 |
+
self.attribute_barplot,
|
450 |
+
max_width=self.max_width,
|
451 |
+
min_width=self.min_width,
|
452 |
+
styles=styling.card_style,
|
453 |
+
header=pn.Row(pn.pane.Str('周期回报'),
|
454 |
+
pn.widgets.TooltipIcon(value=description.periodic_return_report)))
|
455 |
return self._layout
|
456 |
|
457 |
|
|
|
540 |
# ))
|
541 |
return fig.to_dict()
|
542 |
|
543 |
+
def __init__(self, analytic_df, max_width, min_width, **params):
|
544 |
+
self.max_width = max_width
|
545 |
+
self.min_width = min_width
|
546 |
self.p_stock_df = analytic_df
|
547 |
self.p_stock_df = processing.calculate_weighted_return(self.p_stock_df,
|
548 |
start=self.p_stock_df.time.min(),
|
|
|
571 |
super().__init__(**params)
|
572 |
|
573 |
def __panel__(self):
|
574 |
+
self._layout = pn.Card(self.datetime_picker,
|
575 |
+
self.tree_plot,
|
576 |
+
self.date_range,
|
577 |
+
self.trend_plot,
|
578 |
+
max_width=self.max_width,
|
579 |
+
min_width=self.min_width,
|
580 |
+
styles=styling.card_style,
|
581 |
+
header=pn.pane.Str('资金分布'))
|
582 |
return self._layout
|
583 |
|
584 |
@param.depends('datetime_picker.value', 'p_stock_df', watch=True)
|
|
|
653 |
df = self._get_cum_return(df)
|
654 |
return df.sort_values(by='cum_pnl', ascending=False)
|
655 |
|
656 |
+
def __init__(self, analytic_df, max_width, min_width, **params):
|
657 |
+
self.max_width = max_width
|
658 |
+
self.min_width = min_width
|
659 |
self.analytic_df = analytic_df
|
660 |
self._date_range = pn.widgets.DateRangeSlider(
|
661 |
name='选择计算回报的时间区间',
|
|
|
683 |
self.best_5_tabulator,
|
684 |
pn.pane.Str('加权回报率最低回报5只股票'),
|
685 |
self.worst_5_tabulator,
|
686 |
+
max_width=self.max_width,
|
687 |
+
min_width=self.min_width,
|
688 |
+
styles=styling.card_style,
|
689 |
header=pn.Row(
|
690 |
pn.pane.Str(self.description),
|
691 |
pn.widgets.TooltipIcon(value=self.tooltip)
|
index_page.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import panel as pn
|
2 |
from sidebar import SideNavBar
|
3 |
-
from sqlalchemy import create_engine
|
4 |
import appComponents
|
5 |
import db_operation as db
|
6 |
|
@@ -18,38 +17,77 @@ if len(analytic_p) == 0:
|
|
18 |
|
19 |
|
20 |
else:
|
21 |
-
|
|
|
|
|
22 |
stock_overview = appComponents.BestAndWorstStocks(
|
23 |
-
analytic_df=analytic_p
|
|
|
|
|
24 |
composation_card = appComponents.PortfolioComposationCard(
|
25 |
-
analytic_p
|
|
|
|
|
|
|
|
|
26 |
monthly_return_card = appComponents.HistReturnCard(
|
27 |
-
calculated_p_stock=analytic_p,
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
drawdown_card = appComponents.DrawDownCard(
|
33 |
-
calculated_p_stock=analytic_p
|
|
|
|
|
|
|
34 |
|
35 |
top_header = appComponents.TopHeader(
|
36 |
eval_df=analytic_p,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
)
|
38 |
-
app = [pn.Row(top_header),
|
39 |
-
pn.Row(
|
40 |
-
pn.Column(monthly_return_card, stock_overview,
|
41 |
-
width=500, margin=(10, 10, 10, 10)),
|
42 |
-
pn.Column(total_return_card, drawdown_card, margin=(10, 10, 10, 10)),
|
43 |
-
pn.Column(composation_card, margin=(10, 10, 10, 10)),
|
44 |
-
)]
|
45 |
|
46 |
template = pn.template.FastListTemplate(
|
47 |
title="Portfolio一览",
|
48 |
side_bar_width=200,
|
49 |
-
collapsed_sidebar
|
50 |
# sidebar=[freq, phase],
|
51 |
)
|
52 |
template.sidebar.append(SideNavBar())
|
53 |
# template.main.extend([drawdown_card, stock_overview, composation_card, monthly_return_card, total_return_card])
|
54 |
-
template.main.
|
55 |
template.servable()
|
|
|
1 |
import panel as pn
|
2 |
from sidebar import SideNavBar
|
|
|
3 |
import appComponents
|
4 |
import db_operation as db
|
5 |
|
|
|
17 |
|
18 |
|
19 |
else:
|
20 |
+
# a large number to let flex-basis takes full width
|
21 |
+
max_width = 4000
|
22 |
+
min_width = 300
|
23 |
stock_overview = appComponents.BestAndWorstStocks(
|
24 |
+
analytic_df=analytic_p,
|
25 |
+
max_width=max_width,
|
26 |
+
min_width=min_width,)
|
27 |
composation_card = appComponents.PortfolioComposationCard(
|
28 |
+
analytic_p,
|
29 |
+
max_width=max_width,
|
30 |
+
min_width=min_width,
|
31 |
+
|
32 |
+
)
|
33 |
monthly_return_card = appComponents.HistReturnCard(
|
34 |
+
calculated_p_stock=analytic_p,
|
35 |
+
calculated_b_stock=analytic_b,
|
36 |
+
max_width=max_width,
|
37 |
+
min_width=min_width,
|
38 |
+
)
|
39 |
+
total_return_card = appComponents.TotalReturnCard(
|
40 |
+
name='Range',
|
41 |
+
b_stock_df=analytic_b,
|
42 |
+
p_stock_df=analytic_p,
|
43 |
+
max_width=max_width,
|
44 |
+
min_width=min_width,
|
45 |
+
value=(0, 20))
|
46 |
drawdown_card = appComponents.DrawDownCard(
|
47 |
+
calculated_p_stock=analytic_p,
|
48 |
+
max_width=max_width,
|
49 |
+
min_width=min_width,
|
50 |
+
)
|
51 |
|
52 |
top_header = appComponents.TopHeader(
|
53 |
eval_df=analytic_p,
|
54 |
+
|
55 |
+
)
|
56 |
+
|
57 |
+
# app = [pn.Row(top_header),
|
58 |
+
# pn.Row(
|
59 |
+
# pn.Column(monthly_return_card, stock_overview,
|
60 |
+
# width=500, margin=(10, 10, 10, 10)),
|
61 |
+
# pn.Column(total_return_card, drawdown_card, margin=(10, 10, 10, 10)),
|
62 |
+
# pn.Column(composation_card, margin=(10, 10, 10, 10)),
|
63 |
+
# )]
|
64 |
+
flex_box_style = {
|
65 |
+
'max-width': '100vw',
|
66 |
+
'height': '100vh',
|
67 |
+
'flex-flow': 'column wrap',
|
68 |
+
'justify-content': 'flex-start',
|
69 |
+
'align-items': 'flex-start',
|
70 |
+
|
71 |
+
}
|
72 |
+
flex_box = pn.FlexBox(
|
73 |
+
top_header,
|
74 |
+
total_return_card,
|
75 |
+
composation_card,
|
76 |
+
monthly_return_card,
|
77 |
+
stock_overview,
|
78 |
+
drawdown_card,
|
79 |
+
margin=(10, 10, 10, 10),
|
80 |
+
justify_content='start',
|
81 |
+
align_items='stretch',
|
82 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
template = pn.template.FastListTemplate(
|
85 |
title="Portfolio一览",
|
86 |
side_bar_width=200,
|
87 |
+
collapsed_sidebar=True,
|
88 |
# sidebar=[freq, phase],
|
89 |
)
|
90 |
template.sidebar.append(SideNavBar())
|
91 |
# template.main.extend([drawdown_card, stock_overview, composation_card, monthly_return_card, total_return_card])
|
92 |
+
template.main.append(flex_box)
|
93 |
template.servable()
|
styling.py
CHANGED
@@ -6,10 +6,13 @@ plot_layout = dict(
|
|
6 |
xaxis_title=None,
|
7 |
margin=dict(l=0, r=0, t=30, b=0),
|
8 |
uniformtext_mode='hide',
|
9 |
-
|
10 |
)
|
11 |
|
12 |
barplot_trace = dict(
|
13 |
marker_line_width=0,
|
14 |
selector=dict(type="bar"),
|
15 |
)
|
|
|
|
|
|
|
|
6 |
xaxis_title=None,
|
7 |
margin=dict(l=0, r=0, t=30, b=0),
|
8 |
uniformtext_mode='hide',
|
9 |
+
|
10 |
)
|
11 |
|
12 |
barplot_trace = dict(
|
13 |
marker_line_width=0,
|
14 |
selector=dict(type="bar"),
|
15 |
)
|
16 |
+
card_style = dict(
|
17 |
+
flex='1 1 calc(100% / 3)',
|
18 |
+
)
|