Exemplo n.º 1
0
def view_instrument_config(data):
    instrument_code = get_valid_instrument_code_from_user(data)
    diag_instruments = diagInstruments(data)
    meta_data = diag_instruments.get_meta_data(instrument_code)
    print(meta_data)

    return None
Exemplo n.º 2
0
def last_currency_fx(data: dataBlob, instrument_code: str) -> float:
    data_currency = dataCurrency(data)
    diag_instruments = diagInstruments(data)
    currency = diag_instruments.get_currency(instrument_code)
    fx_rate = data_currency.get_last_fx_rate_to_base(currency)

    return fx_rate
Exemplo n.º 3
0
def get_perc_pandl_series_for_strategy_instrument_vs_total_capital(
        data, instrument_strategy: instrumentStrategy):
    print("Data for %s" % (instrument_strategy))
    instrument_code = instrument_strategy.instrument_code
    strategy_name = instrument_strategy.strategy_name

    capital = get_total_capital_series(data)
    fx = get_fx_series_for_instrument(data, instrument_code)

    diag_instruments = diagInstruments(data)
    value_per_point = diag_instruments.get_point_size(instrument_code)

    positions = get_position_series_for_instrument_strategy(
        data, instrument_code=instrument_code, strategy_name=strategy_name)
    prices = get_current_contract_price_series_for_instrument(
        data, instrument_code=instrument_code)
    fills = get_fills_for_instrument(data,
                                     instrument_code=instrument_code,
                                     strategy_name=strategy_name)

    calculator = pandlCalculationWithFills.using_positions_and_prices_merged_from_fills(
        prices,
        positions=positions,
        fills=fills,
        fx=fx,
        capital=capital,
        value_per_point=value_per_point,
    )

    perc_pandl = calculator.percentage_pandl()

    return perc_pandl
Exemplo n.º 4
0
def get_fx_series_for_instrument(data, instrument_code):
    diag_instruments = diagInstruments(data)
    currency = diag_instruments.get_currency(instrument_code)
    currency_data = currencyData(data)
    fx_series = currency_data.get_fx_prices_to_base(currency)

    return fx_series
Exemplo n.º 5
0
def get_pandl_series_in_local_ccy_for_contract(data, instrument_code, contract_id):
    diag_instruments = diagInstruments(data)

    pandl_in_points = get_pandl_series_in_points_for_contract(data, instrument_code, contract_id)
    point_size = diag_instruments.get_point_size(instrument_code)
    pandl_in_local = point_size * pandl_in_points

    return pandl_in_local
def view_instrument_config(data):
    instrument_code = get_valid_instrument_code_from_user(data)
    diag_instruments = diagInstruments(data)
    meta_data = diag_instruments.get_meta_data(instrument_code)
    print(meta_data)
    data_broker = dataBroker(data)
    instrument_broker_data = data_broker.get_brokers_instrument_with_metadata(instrument_code)
    print(instrument_broker_data)
Exemplo n.º 7
0
def get_pandl_series_in_local_ccy_for_strategy_instrument(
        data, strategy_name, instrument_code):
    diag_instruments = diagInstruments(data)

    pandl_in_points = get_pandl_series_in_points_for_instrument_strategy(
        data, instrument_code, strategy_name)
    point_size = diag_instruments.get_point_size(instrument_code)
    pandl_in_local = point_size * pandl_in_points

    return pandl_in_local
Exemplo n.º 8
0
    def get_period_perc_pandl_for_sector_in_date_range(self, asset_class: str):
        diag_instruments = diagInstruments(self.data)
        list_of_instruments = diag_instruments.get_all_instruments_in_asset_class(
            asset_class)
        instrument_pandl = [
            self.
            get_period_perc_pandl_for_instrument_all_strategies_in_date_range(
                instrument_code) for instrument_code in list_of_instruments
        ]
        asset_class_pandl = sum(instrument_pandl)

        return asset_class_pandl
Exemplo n.º 9
0
    def get_period_perc_pandl_for_all_sectors_in_date_range(self):
        diag_instruments = diagInstruments(self.data)
        asset_classes = diag_instruments.get_all_asset_classes()
        list_pandl = [
            PandL(
                asset_class,
                self.get_period_perc_pandl_for_sector_in_date_range(
                    asset_class),
            ) for asset_class in asset_classes
        ]

        return list_pandl
Exemplo n.º 10
0
def get_percentage_cost_for_instrument(data: dataBlob, instrument_code: str):
    diag_instruments = diagInstruments(data)
    costs_object = diag_instruments.get_cost_object(instrument_code)
    blocks_traded = 1
    block_price_multiplier = get_block_size(data, instrument_code)
    price = recent_average_price(data, instrument_code)
    percentage_cost = \
        costs_object.calculate_cost_percentage_terms(blocks_traded=blocks_traded,
                                                     block_price_multiplier=block_price_multiplier,
                                                     price=price)

    return percentage_cost
Exemplo n.º 11
0
def get_current_configured_spread_cost(data):
    diag_instruments = diagInstruments(data)
    list_of_instruments = diag_instruments.get_list_of_instruments()

    spreads_as_list = [
        get_configured_spread_cost_for_instrument(data, instrument_code)
        for instrument_code in list_of_instruments
    ]

    spreads_as_df = pd.Series(spreads_as_list, index=list_of_instruments)

    return spreads_as_df
Exemplo n.º 12
0
def get_period_perc_pandl_for_all_sectors_in_date_range(
        data, start_date, end_date):
    diag_instruments = diagInstruments(data)
    asset_classes = diag_instruments.get_all_asset_classes()
    list_pandl = [
        PandL(
            asset_class,
            get_period_perc_pandl_for_sector_in_date_range(
                asset_class, data, start_date, end_date),
        ) for asset_class in asset_classes
    ]

    return list_pandl
Exemplo n.º 13
0
def get_period_perc_pandl_for_sector_in_date_range(asset_class, data,
                                                   start_date, end_date):
    print("Getting data for %s" % asset_class)
    diag_instruments = diagInstruments(data)
    list_of_instruments = diag_instruments.get_all_instruments_in_asset_class(
        asset_class)
    instrument_pandl = [
        get_period_perc_pandl_for_instrument_all_strategies_in_date_range(
            data, instrument_code, start_date, end_date)
        for instrument_code in list_of_instruments
    ]
    asset_class_pandl = sum(instrument_pandl)

    return asset_class_pandl * 100
Exemplo n.º 14
0
def cash_calculations_for_slippage_row(slippage_row, data):
    ## What's a tick worth in base currency?
    diag_instruments = diagInstruments(data)
    value_of_price_point = diag_instruments.get_point_size_base_currency(
        slippage_row.instrument_code)
    input_items = [
        'delay', 'bid_ask', 'execution', 'versus_limit', 'versus_parent_limit',
        'total_trading'
    ]
    output = [
        value_of_price_point * slippage_row[input_name]
        for input_name in input_items
    ]

    return tuple(output + [value_of_price_point])
Exemplo n.º 15
0
def get_cash_cost_in_base_for_instrument(data: dataBlob, instrument_code: str):
    diag_instruments = diagInstruments(data)
    costs_object = diag_instruments.get_cost_object(instrument_code)
    blocks_traded = 1
    block_price_multiplier = get_block_size(data, instrument_code)
    price = recent_average_price(data, instrument_code)
    cost_instrument_ccy = costs_object.calculate_cost_instrument_currency(
        blocks_traded=blocks_traded,
        block_price_multiplier=block_price_multiplier,
        price=price,
    )
    fx = last_currency_fx(data, instrument_code)
    cost_base_ccy = cost_instrument_ccy * fx

    return cost_base_ccy
Exemplo n.º 16
0
def get_perc_pandl_series_for_contract(data, instrument_code, contract_id):

    capital = get_total_capital_series(data)
    fx = get_fx_series_for_instrument(data, instrument_code)
    diag_instruments = diagInstruments(data)
    value_per_point = diag_instruments.get_point_size(instrument_code)

    positions = get_position_series_for_contract(
        data, instrument_code, contract_id)
    prices = get_price_series_for_contract(
        data, instrument_code, contract_id)
    fills = get_fills_for_contract(data, instrument_code, contract_id)

    calculator = pandlCalculationWithFills.using_positions_and_prices_merged_from_fills(prices,
                    positions=positions,
                    fills=fills,
                     fx=fx,
                     capital = capital,
                     value_per_point=value_per_point)

    perc_pandl = calculator.percentage_pandl()

    return perc_pandl
Exemplo n.º 17
0
def get_base_currency_point_size_per_contract(data, instrument_code):
    diag_instruments = diagInstruments(data)
    point_size_base_currency = diag_instruments.get_point_size_base_currency(
        instrument_code)

    return point_size_base_currency
Exemplo n.º 18
0
def get_block_size(data, instrument_code):
    diag_instruments = diagInstruments(data)
    return diag_instruments.get_point_size(instrument_code)
Exemplo n.º 19
0
def get_configured_spread_cost_for_instrument(data, instrument_code):
    diag_instruments = diagInstruments(data)
    meta_data = diag_instruments.get_meta_data(instrument_code)

    return meta_data.Slippage