margot.backtest

Module contents

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

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

Longer class information…. Longer class information….

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.

Returns

[description]

Return type

[type]

run()

Run the backtest.

Returns

[description]

Return type

[type]