twopirllc / pandas-ta

Technical Analysis Indicators - Pandas TA is an easy to use Python 3 Pandas Extension with 150+ Indicators
https://twopirllc.github.io/pandas-ta/
MIT License
5.42k stars 1.06k forks source link

Migration from ta.lib to pandas.lib #485

Closed alexgreatparis closed 1 year ago

alexgreatparis commented 2 years ago

Recently Successfully installed pandas-ta-0.3.14b0

But still now.... with !pip install ta import ta

I am currently using the following code (to make in final a SVR(kernel="rbf", epsilon=0.005)) :

_df_indicators = ta.add_all_ta_features( df, open="open", high="high", low="low", close="close", volume="volume", fillna=True).shift(1)_

I would like to have the equivalent line code with pandas.ta to have in result the same df_indicators. Can you help me?

Thanks

twopirllc commented 2 years ago

Hello @alexgreatparis,

I won't be supporting v0.3.14b0 in the near future.

So, I recommend using the development version which will be hopefully released soon. It has numerous bug fixes, better documentation and typing and performance improvements.

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

Second, I recommend you read some of the README where already outlines what you are requesting. In particular, the section on Programming Conventions.

Here are the two Builtin Studies.

import pandas_ta as ta

df = # your ohlcv data

# The Default Study: ta.AllStudy
# The following are equivalent:
df.ta.study()
df.ta.study("All")
df.ta.study(ta.AllStudy)

# CommonStudy
# df.ta.study(ta.CommonStudy)

Let me know if this works.

Kind Regards, KJ

alexgreatparis commented 2 years ago

Hello @twopirllc Thanks for your help, I'll look into it and test it.

alexgreatparis commented 2 years ago

Hi, I run the install line you gave me and I have this error message

Collecting git+https://github.com/twopirllc/pandas-ta.git@development Cloning https://github.com/twopirllc/pandas-ta.git (to revision development) to c:\users\admin\appdata\local\temp\pip-req-build-s58imigv

Error [WinError 2] Le fichier spécifié est introuvable while executing command git clone -q https://github.com/twopirllc/pandas-ta.git C:\Users\admin\AppData\Local\Temp\pip-req-build-s58imigv Cannot find command 'git' - do you have 'git' installed and in your PATH?

Can you help me?

twopirllc commented 2 years ago

Hello @alexgreatparis,

You have two options.

  1. Install Git a. Install development branch
    $ pip install -U git+https://github.com/twopirllc/pandas-ta.git@development
  2. Download development branch source from here a. How to download files from Github b. Once source is saved in the directory of your app, you need to manually install it with pip.

I recommend installing Git, option 1. Hope this helps!

Kind Regards, KJ

alexgreatparis commented 2 years ago

I'm really sorry to bother you with my installation problems. I did what you told me to do but I still have problems. 1/ I installed Git. I installed development branch without any problem. image

But after adding you pip install ... instruction I add this error message image

So I tried the 2/ option a. I did the dowload and I have the zip in my download directory b. Once source is saved in the directory of your app -> I don't know where to save the zip content (ta was installed with anaconda so I have no idea of the installation process) I really feel like the dumbest man alive but if you could continue to help me that would be nice. Thanks in advance.

twopirllc commented 2 years ago

Hello @alexgreatparis,

I do not use Anaconda for package management... for various reasons. So I use the package virtualenv.

For this scenario, I would install virtualenv globally with Anaconda.

# change to the directory where you want to create your project
$ cd 
# Make project directory
$ mkdir test_pta
$ cd test_pta

# Make the python virtualenv named env
$ python -m virtualenv env

# Activate the virtualenv
$ source env/bin/activate

# Install Python packages for your project
(env)$ pip install pandas matplotlib

# Install PTA development version
(env)$ pip install -U git+https://github.com/twopirllc/pandas-ta.git@development
# Show installed project packages
(env)$ pip list

# To leave the virtualenv, deactivate it
(env)$ deactivate

Please show me a screenshot of the steps so I can see how you progress.

Thanks for your patience, KJ

alexgreatparis commented 2 years ago

First of all thank you for spending time to support me in this installation. It's really nice. I started doing what you asked me to do and here is the screenshot. What do you think of it? image

twopirllc commented 2 years ago

Hello @alexgreatparis,

No problem. We all start somewhere.

It is saying Anaconda could not find virtualenv. You need to install virtualenv with Anaconda first and then do the sequence of commands from my prior comment.

KJ

alexgreatparis commented 2 years ago

image virtualenv seems ok, but it is source that is an issue. What do you think?

twopirllc commented 2 years ago

@alexgreatparis,

Well, "/" are for unix like directories and "\" is for Windows directories. You seem to be using both and getting them mixed up.

Your last comment is using windows, so I believe it's:

PS .. > env\Scripts\activate

More info on virtualenv

Screen Shot 2022-02-21 at 9 38 56 AM
alexgreatparis commented 2 years ago

for each line, you find the solution but I find it incredible that it is so complicated. Your last solution was the right one. But the next line is problematic again. I let you look at it and come back to me. Thanks again

Windows 2021 2022-02-23 15-55-28

.

twopirllc commented 2 years ago

@alexgreatparis

for each line, you find the solution but I find it incredible that it is so complicated.

I hear you. Windows doesn't make it easy sometimes. 😒

However, there is nothing stopping you from using Google Search to find solutions and try them out... just like me and everyone else that run into uncommon problems. If there is an error, someone has already likely posted the same question and there is similarly some sort of solution to try. For instance, you pip error message you received I would have to look up also.

However, based on your initial post, you got Pandas and "ta" and "pandas_ta" installed before. So how did you do that? You should be able to replicate the process since you did it already, correct?

Anyhow, lets forget the git and updated version of pandas_ta in a test directory that we tried for now. I just want to get you running. I will have an updated version of the library as soon as I can.

So go back to the directory or wherever you installed Pandas, pandas_ta (v0.3.14b0) and ta, assuming it's still there and give this a try:

import pandas_ta as ta  # version v0.3.14b0

df = # your ohlcv data

# The Default Study: ta.AllStrategy
# The following are equivalent:
df.ta.strategy()
# df.ta.strategy("All")
# df.ta.strategy(ta.AllStrategy)

# CommonStudy
# df.ta.strategy(ta.CommonStrategy)

Let me know if you can run one of those.


Lastly, I want to be clear that the issues you are having have nothing to do with Pandas TA.

KJ

alexgreatparis commented 2 years ago

image As you can see I took an exemple on youtube and put after it your code

twopirllc commented 2 years ago

Hello @alexgreatparis

As you can see I took an exemple on youtube and put after it your code

No it is impossible for me to tell it is from YT. Which YT video are you referencing?

for df.ta.strategy() or df.ta.strategy("All") or df.ta.strategy(ta.AllStrategy) generate errors.

That is correct, they generate errors because these indicator groups/strategy/study include the vwap indicator which requires a DatetimeIndex as mentioned in the Quick Start section of the README (which includes how to create a DatetimeIndex). Whenever you need vwap, you need to create a DatetimeIndex.

for df.ta.strategy(ta.CommonStrategy), no error

This is correct, no error, since ta.CommonStrategy does not have the vwap indicator in it's group/strategy/study.


Since you chose ccxt for you example, then you need to do the following:

from datetime import datetime
import pandas as pd
import ccxt, yfinance

import pandas_ta as ta

def to_datetime(t):
    return datetime.utcfromtimestamp(float(t) / 1000.0)

# Fetch Data
exchange = ccxt.binance()
ohlcv = exchange.fetch_ohlcv("ETH/USDT", timeframe="5m", limit=500)

# Prep DataFrame
df = pd.DataFrame(ohlcv, columns=["time", "open", "high", "low", "close", "volume"])
df["time"] = pd.to_datetime(df["time"].apply(to_datetime))
df.set_index("time", inplace=True)
print(df)

# Run Strategy
# df.ta.cores = 0  # Might get a speed increase if setting cores = 0.
df.ta.strategy(verbose=True)
print(df)

# Continue your Data Mining ...


For other data providers, you will have to figure out how to set the DatetimeIndex.

Hope this helps! Good luck! 🍀

KJ

alexgreatparis commented 2 years ago

Hi, do you know someone who can help me to install the development version on my windows through a remote connection? I agree to pay for this.

twopirllc commented 2 years ago

Hey @alexgreatparis,

Unfortunately, I do not know of anyone. 🤷🏼‍♂️ Hopefully someone takes up your offer. If not, a new pip version will be coming out soon. 🤞🏼