Skip to main content

This backtesting is used to backtest algorithmic/quant trading strategies.

Project description

Setup

Install the project via the shell: pip install quantbacktest.

Update to a newer version via the shell (do this twice!): pip install quantbacktest --upgrade.

Exemplary usage

from quantbacktest import backtest_visualizer

# For managing dates
from datetime import datetime

# For allowing for flexible time differences (frequencies)
from pandas.tseries.offsets import Timedelta


strategy_hyperparameters = {
    'maximum_deviation_in_days': 300,
    'prices_table_id_column_name': 'token_itin',
    'excel_worksheet_name': excel_worksheet_name,  # Set this to None if CSV is used!
    'buy_parameter_space': [9.8],  # [11, 20] # Times 10! Will be divided by 10.
    'sell_parameter_space': [9.7],  # [5, 9] # Times 10! Will be divided by 10.
    'maximum_relative_exposure_per_buy': 0.34,
    'frequency': Timedelta(days=1),
    'moving_average_window_in_days': 14,
    'id': 'TP3B-248N-Q',
    'boolean_allow_partially_filled_orders': True,
}

comments = {
    'display_options': repr(display_options),
    'strategy_hyperparameters': repr(strategy_hyperparameters)
}

constraints = {
    'maximum_individual_asset_exposure_all': 1.0,  # Not yet implemented
    'maximum_individual_asset_exposure_individual': {},  # Not yet implemented
    'maximum_gross_exposure': 1.0,  # Already implemented
    'boolean_allow_shortselling': False,  # Shortselling not yet implemented
    'minimum_cash': 100,
}

dict_crypto_options={
    'general': {
        'percentage_buying_fees_and_spread': 0.005,  # 0.26% is the taker fee for low-volume clients at kraken.com https://www.kraken.com/features/fee-schedule
        'percentage_selling_fees_and_spread': 0.005,  # 0.26% is the taker fee for low-volume clients at kraken.com https://www.kraken.com/features/fee-schedule
        # Additional fees may apply for depositing money.
        'absolute_fee_buy_order': 0.0,
        'absolute_fee_sell_order': 0.0,
    }
}

display_options = {
    'boolean_plot_heatmap': False,
    'boolean_test': False,  # If multi-asset strategy is used, this will cause sampling of the signals to speed up the run for testing during development.
    'warning_no_price_for_last_day': False,
    'warning_no_price_during_execution': False,
    'warning_no_price_for_intermediate_valuation': True,
    'warning_alternative_date': False,
    'warning_calculate_daily_returns_alternative_date': False,
    'warning_no_price_for_calculate_daily_returns': False,
    'warning_buy_order_could_not_be_filled': True,
    'warning_sell_order_could_not_be_filled': True,
    'errors_on_benchmark_gap': True,
    'boolean_plot_equity_curve': False,
    'boolean_save_equity_curve_to_disk': True
}

general_settings = {
    'rounding_decimal_places': 4,
    'rounding_decimal_places_for_security_quantities': 0,
}

benchmark_data_specifications={
    'name_of_column_with_benchmark_primary_key': 'id',  # Will be id after processing. Columns will be renamed.
    'benchmark_key': 'TP3B-248N-Q',  # Ether: T22F-QJGB-N, Bitcoin: TP3B-248N-Q
    'file_path_with_benchmark_data': 'raw_itsa_data/20190717_itsa_tokenbase_top600_wtd302_token_daily.csv',
    'risk_free_rate': 0.02
}

backtest_visualizer(
    file_path_with_price_data='/home/janspoerer/code/janspoerer/quantbacktest/quantbacktest/assets/raw_itsa_data/20190717_itsa_tokenbase_top600_wtd302_token_daily.csv',
    # ONLY LEAVE THIS LINE UNCOMMENTED IF YOU WANT TO USE ETH-ADDRESSES AS ASSET IDENTIFIERS!
    # file_path_with_token_data='raw_itsa_data/20190717_itsa_tokenbase_top600_wtd301_token.csv',  # Only for multi-asset strategies.
    name_of_foreign_key_in_price_data_table='token_itin',
    name_of_foreign_key_in_token_metadata_table='token_itin',
    # 1: execute_strategy_white_noise()
    # 2: Not used anymore, can be reassigned
    # 3: execute_strategy_multi_asset() -> Uses strategy table
    # 4: execute_strategy_ma_crossover()
    int_chosen_strategy=4,
    dict_crypto_options={
        'general': {
            'percentage_buying_fees_and_spread': 0.005,  # 0.26% is the taker fee for low-volume clients at kraken.com https://www.kraken.com/features/fee-schedule
            'percentage_selling_fees_and_spread': 0.005,  # 0.26% is the taker fee for low-volume clients at kraken.com https://www.kraken.com/features/fee-schedule
            # Additional fees may apply for depositing money.
            'absolute_fee_buy_order': 0.0,
            'absolute_fee_sell_order': 0.0,
        }
    },
    float_budget_in_usd=1000000.00,
    file_path_with_signal_data=file_path_with_signal_data,
    strategy_hyperparameters=strategy_hyperparameters,
    margin_loan_rate=0.05,
    list_times_of_split_for_robustness_test=[
        [datetime(2014, 1, 1), datetime(2019, 5, 30)]
    ],
    benchmark_data_specifications={
        'name_of_column_with_benchmark_primary_key': 'id',  # Will be id after processing. Columns will be renamed.
        'benchmark_key': 'TP3B-248N-Q',  # Ether: T22F-QJGB-N, Bitcoin: TP3B-248N-Q
        'file_path_with_benchmark_data': '/home/janspoerer/code/janspoerer/quantbacktest/quantbacktest/assets/raw_itsa_data/20190717_itsa_tokenbase_top600_wtd302_token_daily.csv',
        'risk_free_rate': 0.02
    },
    display_options=display_options,
    constraints=constraints,
    general_settings=general_settings,
    comments=comments,
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quantbacktest-0.0.14.tar.gz (18.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quantbacktest-0.0.14-py3-none-any.whl (19.0 MB view details)

Uploaded Python 3

File details

Details for the file quantbacktest-0.0.14.tar.gz.

File metadata

  • Download URL: quantbacktest-0.0.14.tar.gz
  • Upload date:
  • Size: 18.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.5

File hashes

Hashes for quantbacktest-0.0.14.tar.gz
Algorithm Hash digest
SHA256 6d9ba2c6dce06f094d2cbb77c8d231e7a960dfe65a76d7fe2db392448001d4d8
MD5 026cc9a3b383a645bac73b30f6448931
BLAKE2b-256 c6ccf21cedaa72cd862beee293ce29fdbd61e60e9ddfa79591e16a5e44b3a54e

See more details on using hashes here.

File details

Details for the file quantbacktest-0.0.14-py3-none-any.whl.

File metadata

  • Download URL: quantbacktest-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 19.0 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.5

File hashes

Hashes for quantbacktest-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 2d9408e842e20b6b7ddb9a4e7be15681ddb088d86f304a7263c861c1dd00ae95
MD5 16d160da8ebd1aa19e9d62ed3c0d672e
BLAKE2b-256 9402c8ac3bbe8c30bb503c6e9e7b94ec0195cde52ea67c83970cb3c5b1ead75d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page