margot.backtest¶
Module contents¶
-
class
margot.backtest.
BackTest
(algo, 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.
-
calculate_returns
()¶ Calculate returns.
Assumes the trade is made the next period after a signal is generated.
You should construct your MargotDataFrame to be indexed by the trading periods (e.g. days).
-
create_trade_signals_timeseries
()¶ Create time-series of when position changes occur.
- Return the subset of the positions time-series to indicate positions
when signals indicate trade should be placed.
- Returns
- A dataframe of signals when changes to positions are
suggested.
- Return type
pd.DataFrame
-
create_position_timeseries
(periods)¶ Create Position time-series from signals.
Runs through all of the backtest data, generating position indicating signals.
- Parameters
periods (int) – the number of periods to backtest over, counted back from the end of the dataset. If no value is supplied then the whole dataset is used.
- Returns
time-series of Positions
- Return type
pd.DataFrame
-
run
(periods=None)¶ Run the backtest.
- Returns
[description]
- Return type
[type]
-