Spaces:
Runtime error
Runtime error
File size: 2,553 Bytes
976166f 588011f 976166f |
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 |
import panel as pn
import pandas as pd
from datetime import datetime, timedelta
import plotly.express as px
import holoviews as hv
import numpy as np
import random
import scipy.stats as stats
import hvplot.pandas # noqa
from sqlalchemy import create_engine
from . import api
# from backgroundTask import stocks_stream
from functools import partial
import plotly.graph_objects as go
from panel.viewable import Viewer
from script import processing
import appComponents
import param
# import warnings
pn.extension('mathjax')
# warnings.filterwarnings("ignore", category=pd.core.common.SettingWithCopyWarning)
pn.extension('plotly')
pn.extension('tabulator')
db_url = 'sqlite:///instance/local.db'
engine = create_engine(db_url)
p_eval_df = None
calculated_b_stock = None
calculated_p_stock = None
# load benchmark stock
with engine.connect() as connection:
calculated_b_stock = pd.read_sql('calculated_b_stock', con=connection)
calculated_p_stock = pd.read_sql('calculated_p_stock', con=connection)
p_eval_df = pd.read_sql('p_eval_result', con=connection)
stock_overview = appComponents.BestAndWorstStocks(
p_stock_df=calculated_p_stock, b_stock_df=calculated_b_stock)
composation_card = appComponents.PortfolioComposationCard(
p_stock_df=calculated_p_stock)
monthly_return_card = appComponents.HistReturnCard(
eval_df=p_eval_df, calculated_p_stock=calculated_p_stock, calculated_b_stock=calculated_b_stock)
total_return_card = appComponents.TotalReturnCard(name='Range', eval_df=p_eval_df,
b_stock_df=calculated_b_stock,
p_stock_df=calculated_p_stock,
value=(0, 20))
drawdown_card = appComponents.DrawDownCard(
eval_df=p_eval_df, calculated_p_stock=calculated_p_stock, calculated_b_stock=calculated_b_stock)
top_header = appComponents.TopHeader(
eval_df=p_eval_df
)
template = pn.template.FastListTemplate(
title="Portfolio一览",
# sidebar=[freq, phase],
)
template.main.extend(
[pn.Row(top_header),
pn.Row(
pn.Column(monthly_return_card, stock_overview,
width=500, margin=(10, 10, 10, 10)),
pn.Column(total_return_card, drawdown_card, margin=(10, 10, 10, 10)),
pn.Column(composation_card, margin=(10, 10, 10, 10)),
)]
)
template.servable()
# pn.Row(
# pn.Column(monthly_return_card, stock_overview, width=500),
# pn.Column(total_return_card),
# pn.Column(composation_card)
# ).servable()
|