Skip to main content

backtest utils

Project description

quantrading

  • 백테스팅 유틸 라이브러리입니다.

설치

pip install quantrading

사용 예시

example -> open_close_backtest_example.py 참고

import quantrading as qt
from datetime import datetime
import pandas as pd


class MyStrategy(qt.OpenCloseStrategy):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def on_data(self):
        data = self.get_available_data()
        today_date = self.get_date()

        allocation = {
            'MSCI_WORLD_ACWI': 0.8,
            'IEF_BOND_7_10_INDEX': 0.2
        }

        print(today_date, allocation)

        self.set_allocation(allocation)

    def on_end_of_algorithm(self):
        data = self.get_available_data(exclude_today_data=False)
        stock_price = data["market_close_df"]['MSCI_WORLD_ACWI']
        self.add_to_rebalancing_factor_history(stock_price)


if __name__ == "__main__":
    market_df = pd.read_csv("./stock_bond_data.csv", index_col=0, parse_dates=True)
    market_df = market_df.ffill()

    custom_mp_df = pd.DataFrame(data=[[0.5, 0.5]], index=[datetime(2020, 1, 6)], columns=[
        'MSCI_WORLD_ACWI',
        'IEF_BOND_7_10_INDEX',
    ])

    print(custom_mp_df)

    simulation_args = {
        "market_close_df": market_df,
        "market_open_price_df": market_df,
        "name": "OpenCloseStrategy 주식8 채권2 전략",
        "start_date": datetime(2005, 1, 1),
        "end_date": datetime(2020, 7, 31),
        "rebalancing_periodic": "quarterly",
        "rebalancing_moment": "first",
        "benchmark_ticker": "MSCI_WORLD_ACWI",
        "sell_delay": 1,
        "buy_delay": 2,

        "custom_mp_option": True,
        "custom_mp_start_date": datetime(2020, 1, 1),
        "custom_mp": custom_mp_df,
        "custom_mp_sell_delay": 0,
        "custom_mp_buy_delay": 1,

        "portfolio_transaction_fee": 0.02
    }

    strategy = MyStrategy(**simulation_args)
    strategy.run()
    strategy.print_result_log(display_image=True)
    strategy.result_to_excel(folder_path="simulation_result5")

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

quantrading-0.1.41-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file quantrading-0.1.41-py3-none-any.whl.

File metadata

  • Download URL: quantrading-0.1.41-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.4

File hashes

Hashes for quantrading-0.1.41-py3-none-any.whl
Algorithm Hash digest
SHA256 ab404253e71df2b2b8a85bd57fe517f7d8e2d91a54de5754610dc0560918b165
MD5 4318a7ee7f8843cbb9ae64e31b7160d3
BLAKE2b-256 97c431fedafd1459467d2865622e80cdd6c81ced8e55ee261213222220a078c2

See more details on using hashes here.

Supported by

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