예제 #1
0
def test_field_bucketing():
    """Tests field bucketing by a label
    """

    results_summary = ResultsSummary()

    df = RandomiseTimeSeries().create_random_time_series(max_points=1000,
                                                         freq='minute',
                                                         start='01 Jan 2018',
                                                         end="01 Jun 2018")
    df['Col'] = 'something'

    df_fields = results_summary.field_bucketing(df,
                                                metric_name='price',
                                                aggregation_metric='sum',
                                                aggregate_by_field='Col')

    assert df_fields.values[0] - df_fields['Col'].sum() < eps

    # Overwrite first point
    df['Col'][0] = 'something-else'

    df_fields = results_summary.field_bucketing(df,
                                                metric_name='price',
                                                aggregation_metric='mean',
                                                aggregate_by_field='Col')

    # Check the averages match
    assert df_fields['Col']['something-else'] - df['price'][0] < eps
    assert df_fields['Col']['something'] - df['price'][1:].mean() < eps
예제 #2
0
def multiple_ticker_tca_aggregated_example():
    """Example of how to do TCa analysis on multiple tickers
    """

    tca_engine = TCAEngineImpl(version=tca_version)

    # Run a TCA computation for multiple tickers, calculating slippage
    tca_request = TCARequest(start_date=start_date, finish_date=finish_date, ticker=mult_ticker, tca_type='aggregated',
                             trade_data_store=trade_data_store, market_data_store=market_data_store,
                             metric_calcs=MetricSlippage(), reporting_currency='EUR')

    dict_of_df = tca_engine.calculate_tca(tca_request)

    trade_df = dict_of_df['trade_df']

    # Aggregate some of the results with the ResultsSummary class (we could have done this within the TCARequest)
    summary = ResultsSummary()

    # Bucket slippage by ticker and report the average
    summary_slippage_df = summary.field_bucketing(trade_df, aggregate_by_field='ticker')

    print(summary_slippage_df)

    # Bucket slippage by ticker & return the average as weighted by the executed notional in reporting currency
    # (in this case EUR)
    summary_slippage_df = summary.field_bucketing(trade_df, aggregate_by_field='venue',
                                                  weighting_field='executed_notional_in_reporting_currency')

    print(summary_slippage_df)

    # Bucket slippage by ticker and report the average
    summary_slippage_df = summary.field_bucketing(trade_df, aggregate_by_field='venue')

    print(summary_slippage_df)