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

Lacking Documentation

Open aress31 opened this issue 2 years ago • 6 comments

Could you please add somewhere in the doc a minimal working example on how to exactly use a strategy - ideally leveraging Python classes in order to be modular with the strategies?

My first assumption was that running a strategy on a given dataset would filter out the rows and keep only the complying ones but that does not appear to be the case.

Please confirm if a strategy simply adds the relevant technical indicators to a dataset.

This is an example of what I have tried, and nothing happened:

        df = fetch_bars(exchange, args.symbol, limit=1)

        NonMPStrategy = ta.Strategy(
            name="EMAs, BBs, and MACD",
            description="Non Multiprocessing Strategy by rename Columns",
            ta=[
                {"kind": "ema", "length": 8},
                {"kind": "ema", "length": 21},
                {"kind": "bbands", "length": 20, "col_names": ("BBL", "BBM", "BBU")},
                {"kind": "macd", "fast": 8, "slow": 21, "col_names": ("MACD", "MACD_H", "MACD_S")}
            ]
        )

        df.ta.strategy(ta.CommonStrategy, verbose=True)

        print(df)

Also, what about the signals, are they Booleans to indicate buy/sell signals?

I am a bit lost with this lib... more documentation and examples would be great!

aress31 avatar Sep 06 '22 17:09 aress31

Hello @aress31,

Documentation and Contributing

I am a bit lost with this lib... more documentation and examples would be great!

I am sorry to hear that you find the documentation difficult or confusing. 😐

Contributions are always welcome to improve documentation, examples, bugs, features, testing, tools, et al. We would greatly appreciate your contribution to help everyone! 😎

Update

Additionally, I recommend updating to the development version as "strategy" has been renamed to "study" as well as many other improvements. Here is the link to the development README.

$ pip install -U git+https://github.com/twopirllc/pandas-ta.git@development

Under Kind of Studies on the development README, you will notice that there are quite a few minimal examples illustrating use cases of a Study. Furthermore, there are example notebooks to further illustrate the use of the library.

... ideally leveraging Python classes in order to be modular with the strategies?

Please provide a more explicit example of what you are attempting to achieve.

My first assumption was that running a strategy on a given dataset would filter out the rows and keep only the complying ones but that does not appear to be the case.

The assumption is that a DataFrame df contains at least one of open, high, low, close, volumes columns with the minimum number of rows required per indicator. If the df does not have enough rows/ohlcv bars for the indicator, the indicator will be skipped in the Study.

This is an example of what I have tried, and nothing happened:

You provided no screenshots nor intermediary snapshots through the posted code... 🤷🏼‍♂️

        df = fetch_bars(exchange, args.symbol, limit=1)

        NonMPStrategy = ta.Strategy(
            name="EMAs, BBs, and MACD",
            description="Non Multiprocessing Strategy by rename Columns",
            ta=[
                {"kind": "ema", "length": 8},
                {"kind": "ema", "length": 21},
                {"kind": "bbands", "length": 20, "col_names": ("BBL", "BBM", "BBU")},
                {"kind": "macd", "fast": 8, "slow": 21, "col_names": ("MACD", "MACD_H", "MACD_S")}
            ]
        )

        df.ta.strategy(ta.CommonStrategy, verbose=True)

        print(df)

Please confirm if a strategy simply adds the relevant technical indicators to a dataset.

I can not confirm your code since I do not know what: df = fetch_bars(exchange, args.symbol, limit=1) does or returns. It is currently not reproducible for me in it's present state. Does df = fetch_bars(exchange, args.symbol, limit=1) contain data? If so, what happens when you do:

df = fetch_bars(exchange, args.symbol, limit=1)
print(df.shape)
print(df.columns)
print(df)

Signals

Also, what about the signals, are they Booleans to indicate buy/sell signals?

Please see Issue https://github.com/twopirllc/pandas-ta/issues/406 for an example using crossing signals (ta.xsignals()). For an example of trend signals (ta.tsignals()), see notebook.

Moving forward, it would be great to make separate Issues instead of rolling them into one large Issue with many topics. 👍🏼

Kind Regards, KJ

twopirllc avatar Sep 08 '22 15:09 twopirllc

@aress31,

Here is a simplified example using the Common Study:

Screen Shot 2022-09-08 at 12 07 47 PM

Of course, you will need to replace ta.CommonStudy with your custom Study NonMPStrategy like so:

df.ta.study(NonMPStrategy, verbose=True)

Hope this helps!

KJ

twopirllc avatar Sep 08 '22 19:09 twopirllc

Amazing, thanks for the though answer and pointing me to the right direction.

Side-note: A potential improvement could be to automatically get buy and sell signal (booleans) based on the Study parameters and a given datagrams. That would help remove a lot of boilerplate code when automating trading.

aress31 avatar Sep 08 '22 20:09 aress31

@aress31,

Amazing, thanks for the though answer and pointing me to the right direction.

No worries. Thanks for your patience.

Side-note

Sure. But it's much more nuanced than that. Buy/Sell signals can not be easily reduced given a set of ohlcv and potentially 1 or more indicators added to the data frame.

For instance, suppose one has the following indicators: RSI14, MACD_12_26_9, SUPERTREND, EMA_5, EMA_10, SMA_100, SMA_200, VOL_SMA_5, VOL_SMA_50, and STDEV_30. What is the automatic buy/sell logic for this? What about the data miners that process all the indicators? How is the buy/sell logic determined in this case automatically? There are too many permutations for trading logic that can be derived from it, no? Moreover, whom should decide this? Perhaps I am overthinking this. Do you have a simpler perspective/solution to determine this?

KJ

twopirllc avatar Sep 09 '22 15:09 twopirllc

See https://github.com/twopirllc/pandas-ta/issues/586. Basically, the way I see this, is that Study which is an awesome concept could be extended to add upper/lower value before sending a signal type, i.e., buy or sell.

The Boolean logic of how the different indicators work together should be somehow handled by the Study component, but basically that would give the Study the power to generate complex buy/sell signal based on its instantiation. Effectively porting the coding logic from the devs to the Study component.

A buy/sell signal as you pointed is a simple permutation of indicators that the Study component already process.

Your thoughts?

aress31 avatar Sep 09 '22 15:09 aress31

@aress31,

Basically, the way I see this, is that Study which is an awesome concept could be extended to add upper/lower value before sending a signal type, i.e., buy or sell.

There is certainly room to add that functionality. Fresh eyes and logic on tackling that feature would help expedite the process. 😎

The Boolean logic of how the different indicators work together should be somehow handled by the Study component, ...

Naturally. That is one avenue to approach it from. I would love to see some code demonstrating this while I focus on outstanding indicator accuracy/precision issues, indicator speed improvements and finishing the Remaining TA-Lib indicators.

KJ

twopirllc avatar Sep 09 '22 23:09 twopirllc

Hello @aress31,

I assume by no response that the solution provided was sufficient. Thus I will be closing this issue in a few days.

Kind Regards, KJ

twopirllc avatar Oct 12 '22 22:10 twopirllc