margot.backtest

Module contents

class margot.backtest.BackTest(algo_class, start_balance=100000)

Backtest an trading algo that’s a descendent of BaseAlgo.

Warning

BackTest is still a work in progress - it probably doesn’t even work yet!

algo

A boolean indicating if we like SPAM or not.

starting_balance

An integer count of the eggs we have laid.

calc_daily_returns(day)

Calculate the returns based on yesterdays positions, MoC to MoC.

Parameters

day (date) – the date for which we calculate returns.

Daily returns are the difference between yesterdays adjusted_close and todays adjusted_close.

walk_forward(start: datetime.date, end: datetime.date)

Backtest the algo, walk forward for every trading day in the date range.

Calculates the returns from taking the previous days positions.

Parameters
  • start (date) – The first day of the backtest.

  • end (date) – The last day of the backtest.

Returns

a DataFrame of daily simple returns, and log returns.

Note: A walk forward backtest is much slower than backtesting a dataframe with shift(), but we can use it on the same algo that is deployed live. It’s also a good way to standardise backtesting so that we can keep margot simple, and reuse performance calcs etc.

create_position_timeseries()

Create Position time-series from signals.

Runs through all of the backtest data by default.

Returns

time-series of Positions

Return type

pd.DataFrame

run()

Run the backtest.

Returns

[description]

Return type

[type]