pandas-ta icon indicating copy to clipboard operation
pandas-ta copied to clipboard

Looking for documention about the best way to work with shorting

Open eervin123 opened this issue 3 years ago • 1 comments

Hey there, great project. I don't see the discussion forum open so I'm leaving this here as a feature request, but really it is more of a question.

I've gone through the examples and looked over the library a fair amount. I can't seem to find much documentation on how to work with shorting. For example, in your AIExample.ipynb you show how to find the inverse of an indicator eg. image however that doesn't seem to work later on using tsignals

trendy = asset.ta.tsignals(long, asbool=False, append=True)
trendy.tail()

I did see mention of a "long or short" in xsignals however, my signal is not always based on a cross above or below.

Please forgive me if I'm missing something obvious. In the meantime, I'm just multiplying the asset.PCTRET_1 * -1 I'm assuming this is not the best approach.

asset["ACTRET_1"] = trendy.TS_Trends.shift(1) * (asset.PCTRET_1 * -1)
asset[["PCTRET_1", "ACTRET_1"]].plot(figsize=(16, 3), color=colors("GyOr"), alpha=1, grid=True).axhline(0, color="black")

It seems like tsignals should receive an argument like long_only as true or false, and if false then it would return 1 for long, 0 for no-trend and -1 for short

eervin123 avatar Jan 22 '22 18:01 eervin123

Apologies @eervin123,

I haven't forgotten the request nor the question on shorting. I have been swamped while finishing this development sprint.

To address this, I recently started a new Jupyter Notebook, similar to VectorBT Backtest with Pandas TA, to help analyze and resolve bugs in ta.tsignals() and ta.xsignals() and eventually add it to the examples/.

In the mean time, in VectorBT Backtest with Pandas TA you can control the VBT's Portfolio Settings Signal Direction based on the Entries and Exits of your Strategy. So irregardless of your given Entries and Exits, it will calculate Long, Short, or Both positions for you. VBT Portfolio from_signals() method

Just include this in the second cell with the other VBT settings.

# Modfify the index number to adjust the signal_direction
vbt.settings["portfolio"]["signal_direction"] = ["longonly", "shortonly", "both"][1]

This is the approach I would take as it is a full suite Backtesting Software. It has a lot more options to control trading mechanics of the portfolio.


Please forgive me if I'm missing something obvious. In the meantime, I'm just multiplying the asset.PCTRET_1 * -1 I'm assuming this is not the best approach.

I am not certain on the best approach or convention, that is why I am making the new Notebook to investigate or at least develop one.

It seems like tsignals should receive an argument like long_only as true or false, and if false then it would return 1 for long, 0 for no-trend and -1 for short

That sounds like a reasonable argument to include in both tsignals and xsignals. Perhaps one of your devs or interns can make a PR with the inclusion. 😎

Will keep you posted on the Notebook progress.

Kind Regards, KJ

twopirllc avatar Feb 04 '22 18:02 twopirllc