Beispiel #1
0
def cdf_charts(good_prob, bad_prob):
    """Plot CDF chart."""
    source1 = pd.DataFrame(
        {
            "Good loans": np.arange(len(good_prob)) / len(good_prob),
        },
        index=good_prob)
    c1 = altair.generate_chart("line", source1)

    source2 = pd.DataFrame(
        {
            "Bad loans": np.arange(len(bad_prob)) / len(bad_prob),
        },
        index=bad_prob)
    c2 = altair.generate_chart("line", source2)
    return c1 + c2
Beispiel #2
0
    def test_date_column_utc_scale(self):
        """Test that columns with date values have UTC time scale"""
        df = pd.DataFrame(
            {"index": [date(2019, 8, 9), date(2019, 8, 10)], "numbers": [1, 10]}
        ).set_index("index")

        chart = altair.generate_chart("line", df)
        st.altair_chart(chart)
        c = self.get_delta_from_queue().new_element.vega_lite_chart
        spec_dict = json.loads(c.spec)

        # The x axis should have scale="utc", because it uses date values.
        x_scale = _deep_get(spec_dict, "encoding", "x", "scale", "type")
        self.assertEqual(x_scale, "utc")

        # The y axis should _not_ have scale="utc", because it doesn't
        # use date values.
        y_scale = _deep_get(spec_dict, "encoding", "y", "scale", "type")
        self.assertNotEqual(y_scale, "utc")
Beispiel #3
0
def page_charts(today_date=date.today() - timedelta(days=1)):
    st.subheader("Shiller charts")
    df0 = load_ie_data()
    c1 = altair.generate_chart("line", df0[["Real_Price",
                                            "10xReal_Earnings"]]).properties(
                                                title="Index Plot",
                                                height=200,
                                                width=260,
                                            )
    c2 = altair.generate_chart("line", df0[["CAPE", "10xLong_IR"]]).properties(
        title="PE (CAPE) Plot",
        height=200,
        width=260,
    )
    st.altair_chart(alt.concat(c1, c2, columns=2), use_container_width=True)

    st.subheader("Stock charts")
    start_date = get_start_date(today_date, options=("3Y", "2Y", "1Y"))
    dates = pd.date_range(today_date - timedelta(days=365 * 2), today_date)

    # MSCI
    symbols = ["URTH", "EEM", "SPY", "ES3.SI"]
    colnames = ["MSCI World", "MSCI EM", "S&P500", "ES3"]
    df1 = load_data(dates, symbols, "SPY")
    df1.columns = colnames
    rebased_df1 = rebase(df1[df1.index >= start_date])
    chart1 = altair.generate_chart("line", rebased_df1).properties(
        title="MSCI",
        height=200,
        width=260,
    )

    # VIX
    symbols = ["^VIX"]
    colnames = ["VIX"]
    df2 = load_data(dates, symbols)[symbols]
    df2.columns = colnames
    chart2 = altair.generate_chart("line",
                                   df2[df2.index >= start_date]).properties(
                                       title="VIX",
                                       height=200,
                                       width=260,
                                   )

    st.altair_chart(alt.concat(chart1, chart2, columns=2),
                    use_container_width=True)

    # etfs
    symbols = ["IWDA", "EIMI"]
    colnames = ["World", "EM"]
    df3a = load_data(dates, symbols)
    df3a.columns = colnames
    rebased_df3a = rebase(df3a[df3a.index >= start_date])
    chart3a = altair.generate_chart("line", rebased_df3a).properties(
        title="ETF",
        height=200,
        width=260,
    )
    symbols = ["O87.SI", "ES3.SI", "CLR.SI"]
    colnames = ["GLD", "ES3", "Lion-Phillip"]
    df3b = load_data(dates, symbols)
    df3b.columns = colnames
    rebased_df3b = rebase(df3b[df3b.index >= start_date])
    chart3b = altair.generate_chart("line", rebased_df3b).properties(
        title="ETF SGX",
        height=200,
        width=260,
    )
    st.altair_chart(alt.concat(chart3a, chart3b, columns=2),
                    use_container_width=True)

    # industrial
    symbols = [
        "ES3.SI", "O5RU.SI", "A17U.SI", "J91U.SI", "BUOU.SI", "ME8U.SI",
        "M44U.SI"
    ]
    colnames = ["ES3", "AA", "Ascendas", "ESR", "FLCT", "MIT", "MLT"]
    df4 = load_data(dates, symbols)
    df4.columns = colnames
    rebased_df4 = rebase(df4[df4.index >= start_date])
    chart4a = altair.generate_chart(
        "line",
        rebased_df4[["ES3", "Ascendas", "FLCT", "MIT", "MLT"]],
    ).properties(
        title="Industrial 1",
        height=200,
        width=260,
    )
    chart4b = altair.generate_chart(
        "line",
        rebased_df4[["ES3", "AA", "ESR"]],
    ).properties(
        title="Industrial 2",
        height=200,
        width=260,
    )
    st.altair_chart(alt.concat(chart4a, chart4b, columns=2),
                    use_container_width=True)

    # retail
    symbols = ["ES3.SI", "C38U.SI", "J69U.SI", "N2IU.SI"]
    colnames = ["ES3", "CICT", "FCT", "MCT"]
    df5 = load_data(dates, symbols)
    df5.columns = colnames
    rebased_df5 = rebase(df5[df5.index >= start_date])
    chart5 = altair.generate_chart("line", rebased_df5).properties(
        title="Retail & Commercial",
        height=200,
        width=250,
    )

    # banks
    symbols = ["ES3.SI", "D05.SI", "O39.SI", "U11.SI"]
    colnames = ["ES3", "DBS", "OCBC", "UOB"]
    df6 = load_data(dates, symbols)
    df6.columns = colnames
    rebased_df6 = rebase(df6[df6.index >= start_date])
    chart6 = altair.generate_chart("line", rebased_df6).properties(
        title="Banks",
        height=200,
        width=250,
    )
    st.altair_chart(alt.concat(chart5, chart6, columns=2),
                    use_container_width=True)