Beispiel #1
0
def fig_total_ex_fwd(df_ex, dfc, dfv, df):
    fig = go.Figure()

    dif = dif_forward_nacional(dfc, dfv, df)

    fig.add_trace(go.Scatter(x=dif['Fecha'], y=dif['TOTAL'],
                             name='Pos Neta Fwd (Vendida)', hovertemplate='%{x}, %{y:.1f}'))
    fig.add_trace(go.Scatter(
        x=df_ex['Fecha'], y=df_ex['MMUSD_TOTAL'], name='Total', hovertemplate='%{x}, %{y:.1f}'))

    fig.update_layout(yaxis={'title': 'MMUSD'},
                      title='INVERSIÓN EXTRANJERA TOTAL MMUSD')
    fig.add_trace(go.Scatter(
        x=[0], y=[0], visible=False, showlegend=False, yaxis="y2"))

    fig.update_layout(
        xaxis=dict(domain=[0, 0.985]),
        yaxis=dict(
            range=[0, max(df_ex['MMUSD_TOTAL'])*1.1],
        ),
        yaxis2=dict(
            range=[0, max(df_ex['MMUSD_TOTAL'])*1.1],
            position=0.985,
            anchor="x",
            overlaying="y",
            side="right",
        )
    )
    return fig
Beispiel #2
0
def fig_hedge_total(df_inter, dfc, dfv, df_fn, usdclp, resumen=False):
    df_fn = dif_forward_nacional(dfc, dfv, df_fn).reset_index()
    fig = go.Figure()

    df_inter = df_inter[df_inter['Nombre'] ==
                        'INVERSIÓN EXTRANJERA'].reset_index()

    y_p = df_fn['TOTAL']/df_inter['MMUSD_TOTAL']*100
    fig.add_trace(go.Scatter(
        x=df_inter['Fecha'], y=y_p, yaxis="y", name='Total', hovertemplate='%{x}, %{y:.1f}'))

    if not resumen:
        fig.add_trace(go.Scatter(x=usdclp['Fecha'], y=usdclp['Precio'], yaxis="y2",
                                 name='USD/CLP', marker_color='orange', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))
        # Create axis objects
        fig.update_layout(
            xaxis=dict(
                domain=[0.1, 1]
            ),
            yaxis=dict(
                title="%Fondo",
                titlefont=dict(
                    color="RoyalBlue"
                ),
                tickfont=dict(
                    color="RoyalBlue"
                ),
                position=0
            ),
            yaxis2=dict(
                title="CLP",
                titlefont=dict(
                    color="orange"
                ),
                tickfont=dict(
                    color="orange"
                ),
                anchor="x",
                overlaying="y",
                position=0.1
            ),
        )
    else:
        fig.add_trace(go.Scatter(
            x=[0], y=[0], visible=False, showlegend=False, yaxis="y2"))
        fig.update_layout(
            xaxis=dict(domain=[0, 0.985]),
            yaxis=dict(
                range=[max(0, min(y_p)-2), min(100, max(y_p)+2)],
            ),
            yaxis2=dict(
                range=[max(0, min(y_p)-2), min(100, max(y_p)+2)],
                position=0.985,
                anchor="x",
                overlaying="y",
                side="right",
            )
        )

    fig.update_layout(yaxis={'title': '%Fondo'},
                      title='Porcentaje Inversión Extranjera Hedge TOTAL')

    return fig
Beispiel #3
0
def fig_forwards_nacional_afp(dfc, dfv, df, usdclp, df_vf, df_q):

    dif = dif_forward_nacional(dfc, dfv, df)

    color = np.array(['rgb(255,255,255)']*dif['Dif'].shape[0])
    color[dif['Dif'] < 0] = 'red'
    color[dif['Dif'] >= 0] = 'green'

    hover = list()
    for i in dif['Dif']:
        if i >= 0:
            hover.append('▲ UP: ' + str(round(i, 2)))
        else:
            hover.append('▼ DOWN: ' + str(round(i, 2)))

    fig = go.Figure()
    # forwards
    fig.add_trace(go.Scatter(x=dif['Fecha'], y=dif['TOTAL'], yaxis="y",
                             name='Pos Neta Fwd (Vendida)', marker_color='RoyalBlue', hovertemplate='%{x}, %{y:.1f}'))

    fig.add_trace(go.Bar(
        name='Cambio en Pos Neta Fwd',
        x=dif['Fecha'],
        y=dif['Dif'].abs(),
        marker=dict(color=color.tolist()),
        hovertext=hover
    ))

    fig.add_trace(go.Scatter(x=dfc['Fecha'], y=dfc['TOTAL'].abs(
    ), yaxis="y", name='Pos Comprada Fwd', marker_color='red', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))
    fig.add_trace(go.Scatter(x=dfv['Fecha'], y=dfv['TOTAL'], yaxis="y",
                             name='Pos Vendida Fwd', marker_color='green', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))
    fig.add_trace(go.Scatter(x=usdclp['Fecha'], y=usdclp['Precio'], yaxis="y4",
                             name='USD/CLP', marker_color='orange', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))

    # fondos
    df_vf_usd = df_vf.drop(columns='AFP', inplace=False).groupby(
        ['Fecha']).sum().reset_index()
    df_vf_usd = clp_to_usd(df_vf_usd, usdclp)

    fig.add_trace(go.Scatter(x=df_vf_usd['Fecha'], y=df_vf_usd['VF_A'],
                             yaxis="y2", name='Patrimonio Fondo A', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))
    fig.add_trace(go.Scatter(x=df_vf_usd['Fecha'], y=df_vf_usd['VF_B'],
                             yaxis="y2", name='Patrimonio Fondo B', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))
    fig.add_trace(go.Scatter(x=df_vf_usd['Fecha'], y=df_vf_usd['VF_C'],
                             yaxis="y2", name='Patrimonio Fondo C', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))
    fig.add_trace(go.Scatter(x=df_vf_usd['Fecha'], y=df_vf_usd['VF_D'],
                             yaxis="y2", name='Patrimonio Fondo D', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))
    fig.add_trace(go.Scatter(x=df_vf_usd['Fecha'], y=df_vf_usd['VF_E'],
                             yaxis="y2", name='Patrimonio Fondo E', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))

    AFPs = df_q['AFP'].unique()
    Qs = list()
    for afp in AFPs:
        Q_afp = df_q[df_q['AFP'] == afp].reset_index()
        VF_afp = df_vf[df_vf['AFP'] == afp].reset_index()

        last_date = max(Q_afp['Fecha'])
        # / df_vf[df_vf['Fecha'] == last_date]['VF_A'].squeeze()
        Q_afp['Q_A'] = VF_afp['VF_A'] / Q_afp['Q_A'] * \
            Q_afp[Q_afp['Fecha'] == last_date]['Q_A'].squeeze()
        # / df_vf[df_vf['Fecha'] == last_date]['VF_B'].squeeze()
        Q_afp['Q_B'] = VF_afp['VF_B'] / Q_afp['Q_B'] * \
            Q_afp[Q_afp['Fecha'] == last_date]['Q_B'].squeeze()
        # / df_vf[df_vf['Fecha'] == last_date]['VF_C'].squeeze()
        Q_afp['Q_C'] = VF_afp['VF_C'] / Q_afp['Q_C'] * \
            Q_afp[Q_afp['Fecha'] == last_date]['Q_C'].squeeze()
        # / df_vf[df_vf['Fecha'] == last_date]['VF_D'].squeeze()
        Q_afp['Q_D'] = VF_afp['VF_D'] / Q_afp['Q_D'] * \
            Q_afp[Q_afp['Fecha'] == last_date]['Q_D'].squeeze()
        # / df_vf[df_vf['Fecha'] == last_date]['VF_E'].squeeze()
        Q_afp['Q_E'] = VF_afp['VF_E'] / Q_afp['Q_E'] * \
            Q_afp[Q_afp['Fecha'] == last_date]['Q_E'].squeeze()
        Qs.append(Q_afp)

    df_q = pd.concat(Qs)
    df_q = df_q.drop(columns=['AFP']).groupby(['Fecha']).sum().reset_index()

    last_fx = max(usdclp['Fecha'])
    df_q['Q_A'] = df_q['Q_A'] / \
        usdclp[usdclp['Fecha'] == last_fx]['Precio'].squeeze()
    df_q['Q_B'] = df_q['Q_B'] / \
        usdclp[usdclp['Fecha'] == last_fx]['Precio'].squeeze()
    df_q['Q_C'] = df_q['Q_C'] / \
        usdclp[usdclp['Fecha'] == last_fx]['Precio'].squeeze()
    df_q['Q_D'] = df_q['Q_D'] / \
        usdclp[usdclp['Fecha'] == last_fx]['Precio'].squeeze()
    df_q['Q_E'] = df_q['Q_E'] / \
        usdclp[usdclp['Fecha'] == last_fx]['Precio'].squeeze()

    fig.add_trace(go.Scatter(x=df_q['Fecha'], y=df_q['Q_A'],
                             yaxis="y3", name='Cambios de Fondo A', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))
    fig.add_trace(go.Scatter(x=df_q['Fecha'], y=df_q['Q_B'],
                             yaxis="y3", name='Cambios de Fondo B', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))
    fig.add_trace(go.Scatter(x=df_q['Fecha'], y=df_q['Q_C'],
                             yaxis="y3", name='Cambios de Fondo C', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))
    fig.add_trace(go.Scatter(x=df_q['Fecha'], y=df_q['Q_D'],
                             yaxis="y3", name='Cambios de Fondo D', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))
    fig.add_trace(go.Scatter(x=df_q['Fecha'], y=df_q['Q_E'],
                             yaxis="y3", name='Cambios de Fondo E', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))

    # Create axis objects
    fig.update_layout(
        xaxis=dict(
            domain=[0.1, 0.8]
        ),
        yaxis=dict(
            title="Forwards MMUSD",
            titlefont=dict(
                color="RoyalBlue"
            ),
            tickfont=dict(
                color="RoyalBlue"
            ),
            position=0,
            dtick=5000
        ),
        yaxis2=dict(
            title="AFP Fondos USD",
            titlefont=dict(
                color="#101414"
            ),
            tickfont=dict(
                color="#101414"
            ),
            anchor="x",
            overlaying="y",
            side="right",
            position=0.8
        ),
        yaxis3=dict(
            title="AFP Index de Cambio",
            titlefont=dict(
                color="#323838"
            ),
            tickfont=dict(
                color="#323838"
            ),
            anchor="free",
            overlaying="y",
            side="right",
            position=0.9
        ),
        yaxis4=dict(
            title="USDCLP",
            titlefont=dict(
                color="orange"
            ),
            tickfont=dict(
                color="orange"
            ),
            anchor="free",
            overlaying="y",
            side="left",
            position=0.1
        )
    )

    fig.update_layout(title='Venta neta FWD USDCLP AFP')

    return fig
Beispiel #4
0
def fig_forwards_nacional(dfc, dfv, df, usdclp, resumen=False):
    dif = dif_forward_nacional(dfc, dfv, df)

    color = np.array(['rgb(255,255,255)']*dif['Dif'].shape[0])
    color[dif['Dif'] < 0] = 'red'
    color[dif['Dif'] >= 0] = 'green'

    hover = list()
    for i in dif['Dif']:
        if i >= 0:
            hover.append('▲ UP: ' + str(round(i, 2)))
        else:
            hover.append('▼ DOWN: ' + str(round(i, 2)))

    fig = go.Figure()
    # forwards
    fig.add_trace(go.Scatter(x=dif['Fecha'], y=dif['TOTAL'], yaxis="y",
                             name='Pos Neta Fwd (Vendida)', marker_color='RoyalBlue', hovertemplate='%{x}, %{y:.1f}'))
    # hovertemplate='$%{y:,.0f}' + '<br>%{x}</br>'))

    if resumen:
        fig.add_trace(go.Scatter(x=dfc['Fecha'], y=dfc['TOTAL'].abs(
        ), yaxis="y", name='Pos Comprada Fwd', marker_color='red', hovertemplate='%{x}, %{y:.1f}'))
        fig.add_trace(go.Scatter(x=dfv['Fecha'], y=dfv['TOTAL'], yaxis="y",
                                 name='Pos Vendida Fwd', marker_color='green', hovertemplate='%{x}, %{y:.1f}'))
    else:
        fig.add_trace(go.Scatter(x=dfv['Fecha'], y=dfv['TOTAL'], yaxis="y",
                                 name='Pos Vendida Fwd', marker_color='green', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))
        fig.add_trace(go.Scatter(x=usdclp['Fecha'], y=usdclp['Precio'], yaxis="y2",
                                 name='USD/CLP', marker_color='orange', visible="legendonly", hovertemplate='%{x}, %{y:.1f}'))

    fig.add_trace(go.Bar(
        name='Cambio en Pos Neta Fwd',
        x=dif['Fecha'],
        y=dif['Dif'].abs(),
        marker=dict(color=color.tolist()),
        hovertext=hover
    ))

    # Create axis objects
    if not resumen:
        fig.update_layout(
            xaxis=dict(
                domain=[0.1, 1]
            ),
            yaxis=dict(
                title="Forwards MMUSD",
                titlefont=dict(
                    color="RoyalBlue"
                ),
                tickfont=dict(
                    color="RoyalBlue"
                ),
                position=0,
                dtick=5000
            ),
            yaxis2=dict(
                title="CLP",
                titlefont=dict(
                    color="orange"
                ),
                tickfont=dict(
                    color="orange"
                ),
                anchor="x",
                overlaying="y",
                position=0.1
            ),
        )
    else:
        fig.update_layout(
            yaxis=dict(
                title="MMUSD",
                dtick=5000
            ),
        )
        fig.add_trace(go.Scatter(
            x=[0], y=[0], visible=False, showlegend=False, yaxis="y2"))
        fig.update_layout(
            xaxis=dict(domain=[0, 0.985]),
            yaxis=dict(
                range=[0, max(dfv['TOTAL'])*1.1],
            ),
            yaxis2=dict(
                dtick=5000,
                range=[0, max(dfv['TOTAL'])*1.1],
                position=0.985,
                anchor="x",
                overlaying="y",
                side="right",
            )
        )

    fig.update_layout(title='Venta neta FWD USDCLP')
    fig.update_layout(legend={'itemsizing': 'constant'})
    return fig