Пример #1
0
def calculate_sim_traces(
    account_names: Tuple[str],
    sim_symbol: str,
    start_time=None,
    stop_time=None,
    date_range=None,
) -> pd.DataFrame:
    """As `calculate_traces`, but return a table of traces for a portfolio
    which has all of the same purchases and withdrawals as the input accounts,
    but in which all transactions are for the `sim_symbol` security.
    """
    if not account_names or not sim_symbol:
        raise NoUpdate()
    if "All Accounts" in account_names:
        account_names = db.get_account_names(simulated=False)

    # First get the real account, and cut it to the desired time window.
    account_names = tuple(sorted(account_names))
    _, max_range, latest_time = _calculate_traces(account_names)
    acct = db.sum_accounts(account_names)

    start_time = pd.to_datetime(start_time)
    start_time = start_time or get_start_time(date_range, max_range)
    stop_time = pd.to_datetime(stop_time)
    stop_time = stop_time or get_stop_time(date_range, latest_time)
    acct = acct[start_time:stop_time]

    # Now convert the read portfolio to a simulated portfolio
    sim_acct = create_simulated_portfolio(acct, sim_symbol=sim_symbol)
    all_traces, _, _ = _portfolio_to_traces(sim_acct)

    return all_traces.loc[start_time:stop_time]
Пример #2
0
def calculate_traces(account_names, start_time=None, stop_time=None, date_range=None):
    if not account_names:
        raise NoUpdate()
    if "All Accounts" in account_names:
        account_names = db.get_account_names(simulated=False)
    account_names = tuple(sorted(account_names))
    all_traces, max_range, latest_time = _calculate_traces(account_names)

    start_time = pd.to_datetime(start_time)
    start_time = start_time or get_start_time(date_range, max_range)
    stop_time = pd.to_datetime(stop_time)
    stop_time = stop_time or get_stop_time(date_range, latest_time)
    return all_traces.loc[start_time:stop_time]
Пример #3
0
from dash import html
import pandas as pd

from config import conf
from portdash import database as db

layout = html.Div(
    children=[
        html.Div(
            [
                html.H4(
                    "Account(s) to display", style={"margin-bottom": 0, "margin-top": 0}
                ),
                dcc.Dropdown(
                    id="portfolio-selector",
                    options=[{"label": n, "value": n} for n in db.get_account_names()]
                    + [{"label": "All Accounts", "value": "All Accounts"}],
                    multi=True,
                    placeholder="Select an account",
                    value=["All Accounts"],
                ),
            ],
            style={"text-align": "left"},
        ),
        html.Div(
            [
                html.H4("Value to chart", style={"margin-bottom": 0, "margin-top": 0}),
                dcc.Dropdown(
                    id="line-selector",
                    options=[
                        {"label": v, "value": k} for k, v in conf("lines").items()
Пример #4
0
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd

from config import conf
from portdash import database as db

layout = html.Div(children=[
    html.Div([
        html.H4('Account(s) to display',
                style={'margin-bottom': 0, 'margin-top': 0}),
        dcc.Dropdown(id='portfolio-selector',
                     options=[{'label': n, 'value': n}
                              for n in db.get_account_names()] +
                             [{'label': 'All Accounts',
                               'value': 'All Accounts'}],
                     multi=True,
                     placeholder='Select an account',
                     value=['All Accounts']),
        ], style={'text-align': 'left'}),
    html.Div([
        html.H4('Value to chart',
                style={'margin-bottom': 0, 'margin-top': 0}),
        dcc.Dropdown(id='line-selector',
                     options=[{'label': v, 'value': k}
                              for k, v in conf('lines').items()],
                     multi=True,
                     value=['_total:1']),
        ], style={'text-align': 'left'}),
    html.Div([
        dcc.RadioItems(