示例#1
0
def view_strategy_config(data):
    diag_config = diagProcessConfig(data)
    strategy_name = get_valid_strategy_name_from_user()
    result_dict = diag_config.get_strategy_dict_for_strategy(strategy_name)
    for key, value in result_dict.items():
        print("%s: %s" % (str(key), str(value)))
    print("\nAbove should be modified in private_config.yaml files")
示例#2
0
def update_strategy_override(data):
    update_overrides = updateOverrides(data)
    strategy_name = get_valid_strategy_name_from_user(data=data)
    new_override = get_overide_object_from_user()
    ans = input("Are you sure? (y/other)")
    if ans =="y":
        update_overrides.update_override_for_strategy(strategy_name, new_override)
def create_balance_trade(data):
    data_broker = dataBroker(data)
    default_account = data_broker.get_broker_account()

    print(
        "Most likely use case here is that IB has closed one of your positions as close to the expiry"
    )
    print(
        "Or an edge case in which an order was submitted and then filled whilst you were not monitoring fills"
    )
    print("Or perhaps you are trading manually")
    print("Trades have to be attributed to a strategy (even roll trades)")
    strategy_name = get_valid_strategy_name_from_user(data=data, source="positions")
    instrument_code, contract_date = get_valid_instrument_code_and_contractid_from_user(
        data)
    fill_qty = get_and_convert(
        "Quantity ",
        type_expected=int,
        allow_default=False)
    filled_price = get_and_convert(
        "Filled price", type_expected=float, allow_default=False
    )
    fill_datetime = get_datetime_input("Fill datetime", allow_default=True)
    commission = get_and_convert(
        "Commission",
        type_expected=float,
        allow_default=True,
        default_value=0.0)
    broker_account = get_and_convert(
        "Account ID",
        type_expected=str,
        allow_default=True,
        default_value=default_account,
    )

    broker_order = brokerOrder(
        strategy_name,
        instrument_code,
        contract_date,
        fill_qty,
        fill=fill_qty,
        algo_used="balance_trade",
        order_type=broker_balance_order_type,
        filled_price=filled_price,
        fill_datetime=fill_datetime,
        broker_account=broker_account,
        commission=commission,
        manual_fill=True,
        active=False,
    )

    print(broker_order)
    ans = input("Are you sure? (Y/other)")
    if ans != "Y":
        return None

    stack_handler = stackHandlerCreateBalanceTrades(data)

    stack_handler.create_balance_trade(broker_order)
示例#4
0
def reset_limit_for_instrument_strategy(data):
    trade_limits = dataTradeLimits(data)
    instrument_code = get_valid_instrument_code_from_user(data)
    period_days = get_and_convert("Period of days?", type_expected=int, allow_default=True, default_value = 1)
    strategy_name = get_valid_strategy_name_from_user(data=data)

    ans = input("Reset means trade 'clock' will restart. Are you sure? (y/other)")
    if ans =="y":
        trade_limits.reset_instrument_strategy_limit(strategy_name, instrument_code, period_days)
示例#5
0
def change_limit_for_instrument_strategy(data):
    trade_limits = dataTradeLimits(data)
    instrument_code = get_valid_instrument_code_from_user(data)
    period_days = get_and_convert("Period of days?", type_expected=int, allow_default=True, default_value = 1)
    strategy_name = get_valid_strategy_name_from_user(data=data)
    new_limit = get_and_convert("Limit (in contracts?)", type_expected=int, allow_default=False)

    ans = input("Update will change number of trades allowed in periods, but won't reset 'clock'. Are you sure? (y/other)")
    if ans =="y":
        trade_limits.update_instrument_strategy_limit_with_new_limit(strategy_name, instrument_code, period_days, new_limit)
def update_strategy_instrument_override(data):
    view_overrides(data)
    update_overrides = updateOverrides(data)
    instrument_code = get_valid_instrument_code_from_user(data)
    strategy_name = get_valid_strategy_name_from_user(data=data,
                                                      source="positions")
    new_override = get_overide_object_from_user()
    ans = input("Are you sure? (y/other)")
    if ans == "y":
        update_overrides.update_override_for_strategy_instrument(
            strategy_name, instrument_code, new_override)
示例#7
0
def optimal_positions(data):
    strategy_name = get_valid_strategy_name_from_user(data=data)
    optimal_data = dataOptimalPositions(data)

    instrument_code_list = optimal_data.get_list_of_instruments_for_strategy_with_optimal_position(strategy_name)
    instrument_code = get_valid_code_from_list(instrument_code_list)
    if instrument_code is user_exit:
        return None

    data_series = optimal_data.get_optimal_position_as_df_for_strategy_and_instrument(strategy_name, instrument_code)
    print(data_series)
    return None
示例#8
0
def strategy_report(data):

    strategy_name = get_valid_strategy_name_from_user(data=data, allow_all=True, all_code="ALL")
    if strategy_name!="ALL":
        data_backtests = dataBacktest(data)
        timestamp = data_backtests.interactively_choose_timestamp(strategy_name)
    else:
        timestamp = arg_not_supplied

    report_config = email_or_print(strategy_report_config)
    report_config.modify_kwargs(strategy_name = strategy_name,
                                timestamp = timestamp)
    run_report(report_config, data = data)
def strategy_report(data):

    strategy_name = get_valid_strategy_name_from_user(
        data=data, allow_all=True, all_code=ALL_STRATEGIES
    )
    if strategy_name != ALL_STRATEGIES:
        timestamp = interactively_choose_timestamp(
            strategy_name=strategy_name, data=data
        )
    else:
        timestamp = arg_not_supplied

    report_config = email_or_print_or_file(strategy_report_config)
    report_config.modify_kwargs(strategy_name=strategy_name, timestamp=timestamp)
    run_report(report_config, data=data)
def optimal_positions(data):
    strategy_name = get_valid_strategy_name_from_user(
        data=data, source="optimal_positions")
    optimal_data = dataOptimalPositions(data)

    instrument_code_list = (
        optimal_data.
        get_list_of_instruments_for_strategy_with_optimal_position(
            strategy_name))
    instrument_code = get_valid_code_from_list(instrument_code_list)
    if instrument_code is user_exit:
        return None
    instrument_strategy = instrumentStrategy(instrument_code=instrument_code,
                                             strategy_name=strategy_name)
    data_series = optimal_data.get_optimal_position_as_df_for_instrument_strategy(
        instrument_strategy)
    print(data_series)

    return None