Beispiel #1
0
    def table_of_correlations(self) -> table:
        corr_data = get_correlation_matrix_all_instruments(self.data)
        corr_data = cluster_correlation_matrix(corr_data)
        corr_data = corr_data.as_pd().round(2)
        table_corr = table("Correlations", corr_data)

        return table_corr
Beispiel #2
0
    def table_of_last_price_updates(self):
        price = get_last_price_updates_as_df(self.data)
        price = annonate_df_index_with_positions_held(self.data, price)
        price_table = table("Status of adjusted price / FX price collection",
                            price)

        return price_table
Beispiel #3
0
def table_of_duplicate_markets_for_dict_entry(mkt_data, dict_entry: dict,
                                              filters: tuple):
    included = dict_entry["included"]
    excluded = dict_entry["excluded"]

    all_markets = list(set(list(included + excluded)))
    mkt_data_for_duplicates = get_df_of_data_for_duplicate(
        mkt_data, all_markets)
    best_market = get_best_market(mkt_data_for_duplicates, filters)
    current_list ="Current list of included markets %s, excluded markets %s"\
        % (included, excluded)

    suggested_list =\
        "Best market %s, current included market(s) %s" % (best_market, str(included))

    if best_market is no_good_markets:
        change_str = "No change - no good markets"

    elif len(included) > 1:
        change_str = "%s Replace %s with %s" % (CHANGE_FLAG, str(included),
                                                best_market)

    elif best_market != included[0]:
        change_str = "%s Replace %s with %s" % (CHANGE_FLAG, included[0],
                                                best_market)
    else:
        change_str = "No change required"

    all_string = change_str + " " + current_list + " " + suggested_list

    return table(Heading=all_string, Body=mkt_data_for_duplicates)
Beispiel #4
0
    def table_strategy_pandl_and_residual(self):

        strategies_pandl_df = self.pandl_calculator.get_strategy_pandl_and_residual(
        )
        strategies_pandl_df = strategies_pandl_df.round(2)

        return table("P&L by strategy", strategies_pandl_df)
Beispiel #5
0
    def table_of_sr_costs(self):
        SR_costs = self.SR_costs()
        SR_costs = SR_costs.round(5)
        SR_costs = annonate_df_index_with_positions_held(data=self.data,
                                                         pd_df=SR_costs)
        formatted_table = table("SR costs (using stored slippage)", SR_costs)

        return formatted_table
Beispiel #6
0
    def table_of_strategy_risk(self):
        strategy_risk = get_portfolio_risk_across_strategies(self.data)
        strategy_risk = strategy_risk * 100.0
        strategy_risk = strategy_risk.round(1)
        table_strategy_risk = table("Risk per strategy, annualised percentage",
                                    strategy_risk)

        return table_strategy_risk
Beispiel #7
0
    def table_of_cash_slippage(self):
        cash_slippage = self.cash_slippage
        if len(cash_slippage) == 0:
            return body_text("No trades")

        table_slippage = table("Slippage (In base currency)", cash_slippage)

        return table_slippage
Beispiel #8
0
    def table_of_raw_slippage(self):
        raw_slippage = self.raw_slippage
        if len(raw_slippage) == 0:
            return body_text("No trades")

        table_of_raw_slippage = table("Slippage (ticks per lot)", raw_slippage)

        return table_of_raw_slippage
Beispiel #9
0
    def table_of_liquidity_contract_sort(self) -> table:
        all_liquidity_df = self.liquidity_data()
        all_liquidity_df = all_liquidity_df.sort_values("contracts")
        table_liquidity = table(
            " Sorted by contracts: Less than 100 contracts a day is a problem",
            all_liquidity_df,
        )

        return table_liquidity
Beispiel #10
0
    def table_of_liquidity_contract_sort(self) -> table:
        all_liquidity_df = self.liquidity_data()
        all_liquidity_df = all_liquidity_df.sort_values("contracts")
        table_liquidity = table(
            " Sorted by contracts",
            all_liquidity_df,
        )

        return table_liquidity
Beispiel #11
0
    def table_of_minimum_capital(self) -> table:
        min_capital = minimum_capital_table(self.data)
        min_capital = min_capital.sort_values('minimum_capital')

        min_capital = nice_format_min_capital_table(min_capital)
        min_capital_table = table("Minimum capital in base currency",
                                  min_capital)

        return min_capital_table
Beispiel #12
0
    def table_of_liquidity_risk_sort(self) -> table:
        all_liquidity_df = self.liquidity_data()
        all_liquidity_df = all_liquidity_df.sort_values("risk")
        table_liquidity = table(
            "$m of annualised risk per day, sorted by risk",
            all_liquidity_df,
        )

        return table_liquidity
Beispiel #13
0
    def table_of_liquidity_risk_sort(self) -> table:
        all_liquidity_df = self.liquidity_data()
        all_liquidity_df = all_liquidity_df.sort_values("risk")
        table_liquidity = table(
            "Sorted by risk: Less than $1.5 million of risk per day is a problem",
            all_liquidity_df,
        )

        return table_liquidity
Beispiel #14
0
    def table_of_slippage_comparison(self):
        combined_df_costs = self.combined_df_costs()
        combined_df_costs = combined_df_costs.round(6)
        combined_df_costs = annonate_df_index_with_positions_held(
            self.data, pd_df=combined_df_costs)

        combined_df_costs_as_formatted_table = table("Check of slippage",
                                                     combined_df_costs)

        return combined_df_costs_as_formatted_table
Beispiel #15
0
    def table_of_order_delays(self):
        broker_orders = self.broker_orders
        if len(broker_orders) == 0:
            return body_text("No trades")

        delays = create_delay_df(broker_orders)

        table_of_delays = table("Delays", delays)

        return table_of_delays
Beispiel #16
0
    def table_of_vol_slippage(self):
        raw_slippage = self.raw_slippage
        if len(raw_slippage) == 0:
            return body_text("No trades")

        vol_slippage = create_vol_norm_slippage_df(raw_slippage, self.data)
        table_of_vol_slippage = table(
            "Slippage (normalised by annual vol, BP of annual SR)",
            vol_slippage)

        return table_of_vol_slippage
Beispiel #17
0
    def table_pandl_for_instruments_across_strategies(self):

        pandl_for_instruments_across_strategies_df = (
            self.pandl_for_instruments_across_strategies())
        pandl_for_instruments_across_strategies_df = (
            pandl_for_instruments_across_strategies_df.round(1))

        return table(
            "P&L by instrument for all strategies",
            pandl_for_instruments_across_strategies_df,
        )
Beispiel #18
0
def get_table_of_SR_costs_as_formatted_table(data):
    table_of_SR_costs = get_table_of_SR_costs(data)
    table_of_SR_costs = table_of_SR_costs.round(5)
    table_of_SR_costs = annonate_df_index_with_positions_held(
        data=data, pd_df=table_of_SR_costs)
    formatted_table = table(
        "SR costs (using stored slippage): more than 0.01 means panic",
        table_of_SR_costs,
    )

    return formatted_table
Beispiel #19
0
def filter_data_for_delays_and_return_table(data_with_datetime,
                                            datetime_colum='last_start',
                                            table_header="Only delayed data",
                                            max_delay_in_days=3):

    filtered_data = filter_data_for_delays(data_with_datetime,
                                           datetime_colum=datetime_colum,
                                           max_delay_in_days=max_delay_in_days)
    if len(filtered_data) == 0:
        return body_text("%s: No delays" % table_header)
    else:
        return table(table_header, filtered_data)
Beispiel #20
0
def filter_data_for_max_value_and_return_table(data_with_field,
                                               field_column='field',
                                               max_value=0,
                                               table_header=""):

    filtered_data = filter_data_for_max_value(data_with_field,
                                              field_column=field_column,
                                              max_value=max_value)
    if len(filtered_data) == 0:
        return body_text("%s: No constraints" % table_header)
    else:
        return table(table_header, filtered_data)
Beispiel #21
0
    def table_of_market_moves_using_dates(self,
                                          sortby: str,
                                          truncate: bool = True) -> table:

        # sort by one of ['name', 'change', 'vol_adjusted']
        raw_df = self.market_moves_for_dates()
        sorted_df = raw_df.sort_values(sortby)
        rounded_df = sorted_df.round(2)

        if truncate:
            rounded_df = top_and_tail(rounded_df, rows=6)

        return table(
            "Market moves between %s and %s, sort by %s" %
            (str(self.start_date), str(self.end_date), sortby), rounded_df)
Beispiel #22
0
def get_combined_df_of_costs_as_table(data: dataBlob,
                                      start_date: datetime.datetime,
                                      end_date: datetime.datetime):

    combined_df_costs = get_combined_df_of_costs(data,
                                                 start_date=start_date,
                                                 end_date=end_date)
    combined_df_costs = combined_df_costs.round(6)
    combined_df_costs = annonate_df_index_with_positions_held(
        data=data, pd_df=combined_df_costs)

    combined_df_costs_as_formatted_table = table("Check of slippage",
                                                 combined_df_costs)

    return combined_df_costs_as_formatted_table
Beispiel #23
0
    def table_of_market_moves_given_period(self,
                                           period: str,
                                           sortby: str,
                                           truncate: bool = True) -> table:

        # sort by one of ['name', 'change', 'vol_adjusted']
        # period eg ['1B', '7D', '1M', '3M', '6M', 'YTD', '12M']
        raw_df = self.market_moves_for_period(period)
        sorted_df = raw_df.sort_values(sortby)
        rounded_df = sorted_df.round(2)

        if truncate:
            rounded_df = top_and_tail(rounded_df, rows=6)

        return table(
            "Market moves for period %s, sort by %s (%s/%s)" %
            (period, sortby, period, sortby), rounded_df)
Beispiel #24
0
    def table_of_orders_overview(self):
        broker_orders = self.broker_orders
        if len(broker_orders) == 0:
            return body_text("No trades")

        overview = broker_orders[[
            "instrument_code",
            "strategy_name",
            "contract_date",
            "fill_datetime",
            "fill",
            "filled_price",
        ]]
        overview = overview.sort_values("instrument_code")
        overview_table = table("Broker orders", overview)

        return overview_table
Beispiel #25
0
    def table_of_risk_all_instruments(
            self,
            table_header="Risk of all instruments with data - sorted by annualised % standard deviation",
            sort_by='annual_perc_stdev'):
        instrument_risk_all = self.instrument_risk_data_all_instruments()
        instrument_risk_sorted = instrument_risk_all.sort_values(sort_by)
        instrument_risk_sorted = instrument_risk_sorted[[
            'daily_price_stdev', 'annual_price_stdev', 'price',
            'daily_perc_stdev', 'annual_perc_stdev', 'point_size_base',
            'contract_exposure', 'annual_risk_per_contract'
        ]]
        instrument_risk_sorted = \
            instrument_risk_sorted.round({'daily_price_stdev': 4,
                                            'annual_price_stdev': 3,
                                          'price': 4,
                                          'daily_perc_stdev': 3,
                                          'annual_perc_stdev': 1,
                                          'point_size_base': 3,
                                          'contract_exposure': 0,
                                          'annual_risk_per_contract': 0})
        instrument_risk_sorted_table = table(table_header,
                                             instrument_risk_sorted)

        return instrument_risk_sorted_table
Beispiel #26
0
 def table_of_optimal_positions(self):
     positions_optimal = get_optimal_positions(self.data)
     table_positions_optimal = table("Optimal versus actual positions",
                                     positions_optimal)
     return table_positions_optimal
Beispiel #27
0
    def table_of_my_positions(self):
        positions_mine = get_my_positions(self.data)
        table_positions_mine = table("Positions in DB", positions_mine)

        return table_positions_mine
Beispiel #28
0
    def table_of_ib_positions(self):
        positions_ib = get_broker_positions(self.data)
        table_positions_ib = table("Positions broker", positions_ib)

        return table_positions_ib
Beispiel #29
0
    def table_of_my_recent_trades_from_db(self):
        trades_mine = get_recent_trades_from_db_as_terse_df(self.data)
        table_trades_mine = table("Trades in DB", trades_mine)

        return table_trades_mine
Beispiel #30
0
    def table_of_recent_ib_trades(self):
        trades_ib = get_broker_trades_as_terse_df(self.data)
        table_trades_ib = table("Trades from broker", trades_ib)

        return table_trades_ib