예제 #1
0
    daily_vals = daily_vals / daily_vals.shift(1) - 1
    daily_vals.index = [str(x.year) + '/' + str(x.month) for x in daily_vals.index]
    daily_vals = daily_vals.drop(daily_vals.head(1).index)

    pf = PlotFactory()

    gp = GraphProperties()

    gp.source = 'Thalesians/BBG (created with PyThalesians Python library)'
    gp.html_file_output = "output_data/equities.htm"
    gp.title = 'Recent monthly changes in equity markets'
    gp.scale_factor = 2
    gp.display_legend = True
    gp.chart_type = ['bar', 'scatter', 'line']
    gp.x_title = 'Dates'
    gp.y_title = 'Pc'

    # plot using Bokeh then PyThalesians
    pf.plot_bar_graph(daily_vals * 100, adapter = 'bokeh', gp = gp)
    pf.plot_bar_graph(daily_vals * 100, adapter = 'pythalesians', gp = gp)

# plot daily changes in FX
if True:
    from datetime import timedelta
    ltsf = LightTimeSeriesFactory()

    end = datetime.datetime.utcnow()
    start = end - timedelta(days=5)

    tickers = ['EUR', 'GBP', 'AUD', 'NZD', 'CAD', 'CHF', 'NOK', 'SEK', 'JPY']
    vendor_tickers = [x + 'USD BGN Curncy' for x in tickers]
        df = ltsf.harvest_time_series(time_series_request)
        df.columns = [x.replace('.close', '') for x in df.columns.values]

        df = tsc.calculate_returns(df) * 100
        df = df.dropna()

        df_sorted = tsc.get_bottom_valued_sorted(df, "USDBRL", n = 20)
        # df = tsc.get_top_valued_sorted(df, "USDBRL", n = 20) # get biggest up moves

        # get values on day after
        df2 = df.shift(-1)
        df2 = df2.ix[df_sorted.index]
        df2.columns = ['T+1']

        df_sorted.columns = ['T']

        df_sorted = df_sorted.join(df2)
        df_sorted.index = [str(x.year) + '/' + str(x.month) + '/' + str(x.day) for x in df_sorted.index]

        gp = GraphProperties()
        gp.title = 'Largest daily falls in USDBRL'
        gp.scale_factor = 3
        gp.display_legend = True
        gp.chart_type = 'bar'
        gp.x_title = 'Dates'
        gp.y_title = 'Pc'
        gp.file_output = "usdbrl-biggest-downmoves.png"

        pf = PlotFactory()
        pf.plot_line_graph(df_sorted, adapter = 'pythalesians', gp=gp)
            data_source='bloomberg',  # use Bloomberg as data source
            tickers=tickers,  # ticker (Thalesians)
            fields=['close'],  # which fields to download
            vendor_tickers=vendor_tickers,  # ticker (Bloomberg)
            vendor_fields=['PX_LAST'],  # which Bloomberg fields to download
            cache_algo='internet_load_return')  # how to return data

        daily_vals = ltsf.harvest_time_series(time_series_request)

        # resample for year end
        daily_vals = daily_vals.resample('A')

        daily_vals = daily_vals / daily_vals.shift(1) - 1
        daily_vals.index = daily_vals.index.year
        daily_vals = daily_vals.drop(daily_vals.head(1).index)

        pf = PlotFactory()

        gp = GraphProperties()

        gp.source = 'Thalesians/BBG'
        gp.title = 'Yearly changes in spot'
        gp.scale_factor = 3
        gp.y_title = "Percent Change"

        daily_vals = daily_vals * 100

        # plot using PyThalesians (stacked & then bar graph)
        pf.plot_stacked_graph(daily_vals, adapter='pythalesians', gp=gp)
        pf.plot_bar_graph(daily_vals, adapter='pythalesians', gp=gp)