kernc

Results 458 comments of kernc

Indeed, it's a way to carry over arbitrary info from orders to trades. Thanks for the reminder about tests. Testing at least that `tag=` indeed carries over to the trade...

@qacollective Care to add a simple unit test that confirms the working of the implementation? :smiley:

The PR is still missing: * [x] tag entry in the Trades dataframe https://github.com/kernc/backtesting.py/blob/94d20da85e278102a0cc71b27a3a35b815e11648/backtesting/_stats.py#L57-L69 * [x] unit tests. I guess I should get round to it. :sweat_smile:

If we look slightly higher up: https://github.com/kernc/backtesting.py/blob/77f4c46b82169c2689e1c4ad5994765556179eb2/backtesting/_stats.py#L72-L73 `returns` for expectancy are in percent whereas `pl` are in absolute currency units. I see [Van Tharp mentions expectancy and R-multiples (reward/risk)](https://web.archive.org/web/20180306153436/https://www.vantharp.com/tharp-concepts/sqn.asp), which...

Since the [CI tests fail](https://github.com/kernc/backtesting.py/pull/473/checks?check_run_id=3674938438#step:9:34) due to an upstream error in scikit-optimize (which I also help maintain, very uncommitedly), did you happen to run the tests locally and see if...

> Why is the framework closing the positions automatically at the end of the simulation? So the trades can produce some stats. See https://github.com/kernc/backtesting.py/issues/183, https://github.com/kernc/backtesting.py/commit/f77786e5216f536f4eb50475c750cdd7d438502f.

[`Strategy.data.index`](https://kernc.github.io/backtesting.py/doc/backtesting/backtesting.html#backtesting.backtesting.Strategy.data) is an instance of [`pd.DatetimeIndex`](https://pandas.pydata.org/docs/reference/api/pandas.DatetimeIndex.html) and its values are [`pd.Timestamp`](https://pandas.pydata.org/docs/reference/api/pandas.Timestamp.html). So something like this might work: ```py time = self.data.index[-1].time() if start

You can test the order via [`Order.is_long`](https://kernc.github.io/backtesting.py/doc/backtesting/backtesting.html#backtesting.backtesting.Order.is_long). The active [`Trade`](https://kernc.github.io/backtesting.py/doc/backtesting/backtesting.html#backtesting.backtesting.Trade.is_long) has a similar property. You can also just loop over `for order in self.orders`, because once the order fills and...

> Is there a way to disguinish between the stoploss which is attached to the current trade and the order for a limit short Orders have [`.is_contingent`](https://kernc.github.io/backtesting.py/doc/backtesting/backtesting.html#backtesting.backtesting.Order.is_contingent) property which is...

Do you see any warnings issued?