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:///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()