Skip to main content

Simple trading backtester

Project description

This project aims to provide easy and straitforward backtesting oportunities.

Installation

Install via setup.py:

git clone git@github.com:bluella/stbt.git
cd stbt
python setup.py install

Usage

import datetime as dt
import pandas as pd
import matplotlib.pyplot as plt
from Simple_trading_backtest.simulator import Strategy
import Simple_trading_backtest.helpers as hlp

# creating fake trading data

# prepare datetime index
some_date = dt.datetime(2017, 1, 1)
days = pd.date_range(some_date, some_date + dt.timedelta(30), freq='D')

# initialize close prices
data_values = list(range(1, 32))
closes_df = pd.DataFrame({'Date': days, 'inst1': data_values})
closes_df.set_index('Date', inplace=True)

# initialize weights
weights_values = [1 for i in range(31)]
weights_df = pd.DataFrame({'Date': days, 'inst1': weights_values})
weights_df.set_index('Date', inplace=True)

# create strategy
s = Strategy(closes_df, weights_df, cash=100)

# run backtest, robust tests, calculate stats
s.run_all(delay=2, verify_data_integrity=True, instruments_drop=None,
        commissions_const=0, capitalization=False)

# check strategy stats
print(s.stats_dict)

# save strategy to futher comparison
s.add_to_pnls_pool()

# plot pool correlation heatmap
heatmap_fig, corr_matrix = s.get_pool_heatmap()

plt.show()

Features

License

This project is licensed under the MIT License - see the LICENSE.txt file for details

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

stbt-0.0.2.tar.gz (23.0 kB view hashes)

Uploaded Source

Built Distribution

stbt-0.0.2-py2.py3-none-any.whl (23.1 kB view hashes)

Uploaded Python 2 Python 3

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