portfolio_management / index_page.py
huggingface112's picture
enhanced historyReturnCard
a77544c
raw
history blame
2.64 kB
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
import api
# from backgroundTask import stocks_stream
from functools import partial
import plotly.graph_objects as go
from panel.viewable import Viewer
import processing
import appComponents
import param
import db_operation as db
# 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)
analytic_p = db.get_portfolio_analytic_df()
analytic_b = db.get_benchmark_analytic_df()
# load benchmark stock
# with engine.connect() as connection:
# analytics_df = pd.read
# 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(
analytic_df=analytic_p)
composation_card = appComponents.PortfolioComposationCard(
analytic_p)
monthly_return_card = appComponents.HistReturnCard(
calculated_p_stock=analytic_p, calculated_b_stock=analytic_b)
# 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([stock_overview, composation_card, monthly_return_card])
# 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()