|
14 | 14 | from __future__ import annotations
|
15 | 15 |
|
16 | 16 | import multiprocessing as mp
|
| 17 | +import warnings |
17 | 18 | from collections import OrderedDict
|
18 | 19 | from inspect import currentframe
|
19 | 20 | from itertools import chain, compress, count
|
@@ -511,22 +512,31 @@ class FractionalBacktest(Backtest):
|
511 | 512 | A `backtesting.backtesting.Backtest` that supports fractional share trading
|
512 | 513 | by simple composition. It applies roughly the transformation:
|
513 | 514 |
|
514 |
| - data = (data / satoshi).assign(Volume=data.Volume * satoshi) |
| 515 | + data = (data * fractional_unit).assign(Volume=data.Volume / fractional_unit) |
515 | 516 |
|
516 | 517 | as left unchallenged in [this FAQ entry on GitHub](https://github.com/kernc/backtesting.py/issues/134),
|
517 | 518 | then passes `data`, `args*`, and `**kwargs` to its super.
|
518 | 519 |
|
519 |
| - Parameter `satoshi` tells the amount of scaling to do. E.g. for |
520 |
| - μBTC trading, pass `satoshi=1e6`. |
| 520 | + Parameter `fractional_unit` represents the smallest fraction of currency that can be traded |
| 521 | + and defaults to one [satoshi]. For μBTC trading, pass `fractional_unit=1/1e6`. |
| 522 | + Thus-transformed backtest does a whole-sized trading of `fractional_unit` units. |
| 523 | +
|
| 524 | + [satoshi]: https://en.wikipedia.org/wiki/Bitcoin#Units_and_divisibility |
521 | 525 | """
|
522 | 526 | def __init__(self,
|
523 | 527 | data,
|
524 | 528 | *args,
|
525 |
| - satoshi=int(100e6), |
| 529 | + fractional_unit=1 / 100e6, |
526 | 530 | **kwargs):
|
| 531 | + if 'satoshi' in kwargs: |
| 532 | + warnings.warn( |
| 533 | + 'Parameter `FractionalBacktest(..., satoshi=)` is deprecated. ' |
| 534 | + 'Use `FractionalBacktest(..., fractional_unit=)`.', |
| 535 | + category=DeprecationWarning, stacklevel=2) |
| 536 | + fractional_unit = 1 / kwargs.pop('satoshi') |
527 | 537 | data = data.copy()
|
528 |
| - data[['Open', 'High', 'Low', 'Close']] /= satoshi |
529 |
| - data['Volume'] *= satoshi |
| 538 | + data[['Open', 'High', 'Low', 'Close']] *= fractional_unit |
| 539 | + data['Volume'] /= fractional_unit |
530 | 540 | super().__init__(data, *args, **kwargs)
|
531 | 541 |
|
532 | 542 |
|
|
0 commit comments