Last active
June 6, 2024 17:09
-
-
Save scubamut/a9ceaff5899be8cbee4940cd87f16cec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import talib | |
# routine to get args required for talib function | |
def find_talib_args(func): | |
s = eval('talib.' + func + '.__doc__') | |
try: | |
s = s.splitlines()[0].split('(')[1].split(')')[0].replace('[','').replace(']','').replace('?','') | |
return s.split(',') | |
except: | |
return None | |
func='WILLR' | |
print(eval('talib.' + func + '.__doc__')) | |
print(find_talib_args(func)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from datetime import datetime, timezone | |
import pytz | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
%matplotlib inline | |
from pandas_highcharts.core import serialize | |
from pandas_highcharts.display import display_charts | |
from fintools import * | |
tickers = ['^GSPC','^DJI','^NDX','^OEX','SPY','XLF'] | |
symbols = ['GSPC','DJI','NDX','OEX','SPY','XLF'] | |
start = datetime(2018, 1, 1, 0, 0, 0, 0, pytz.utc) | |
end = datetime(2018, 1, 5, 0, 0, 0, 0, pytz.utc) | |
data_path = '/home/scubamut/MEGAsync/10_DATA/' | |
da = get_DataArray(tickers, start, end) | |
dp = da.to_pandas().transpose(2,1,0) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timezone, timedelta | |
import pandas as pd | |
import pytz | |
import xarray as xr | |
from fintools import get_DataArray, endpoints | |
import talib | |
start = datetime(2016, 1, 5, 0, 0, 0, 0, pytz.utc) | |
end = datetime(2017, 1, 1, 0, 0, 0, 0, pytz.utc) | |
tickers = ['XLP','XLY'] | |
da = get_DataArray(tickers, start, end) | |
prices = da.loc['close'].transpose().to_pandas() | |
# Apply function to column of DAILY ADJ_CLOSE prices, COLUMN_BY_COLUMN | |
df = prices.copy() | |
function = talib.MA | |
lookback = 21 | |
# make sure that TALIB fuction only requires one price! | |
try: | |
transformed = pd.DataFrame({etf:function(df[etf], lookback) for etf in df.columns}).dropna() | |
except: | |
print('ValueError: Shape of passed values is incorrect!') | |
# print(transformed) | |
MA_daily = transformed | |
print(MA_daily[:5]) | |
end_points = endpoints(period='M', trading_days=df.index) | |
df = prices.loc[end_points] | |
function = talib.MA | |
lookback = 3 | |
# make sure that TALIB fuction only requires one price! | |
try: | |
transformed = pd.DataFrame({etf:function(df[etf], lookback) for etf in df.columns}).dropna() | |
except: | |
print('ValueError: Shape of passed values is incorrect!') | |
MA_monthly = transformed | |
MA_monthly[:5] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timezone, timedelta | |
import pytz | |
import xarray as xr | |
from fintools import get_DataArray | |
import talib | |
start = datetime(2016, 1, 5, 0, 0, 0, 0, pytz.utc) | |
end = datetime(2016, 3, 1, 0, 0, 0, 0, pytz.utc) | |
tickers = ['XLP','XLY'] | |
da = get_DataArray(tickers, start, end) | |
xlp = da.loc['close','XLP'].to_pandas() | |
print(talib.STDDEV(xlp.values,10)) | |
print_stats(xlp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import talib | |
import pandas as pd | |
%matplotlib inline | |
SPY = pd.read_csv('/home/scubamut/MEGAsync/10_DATA/daily/etfs/SPY.csv') | |
def ADXR(data, args_ls): | |
try: | |
return talib.ADXR(data.high.values, data.low.values, data.close.values, args_ls[0]) | |
except : | |
print ('ADXR: USING DEFAULT PARAMETERS') | |
return talib.ADXR(data.high.values, data.low.values, data.close.values) | |
print(ADXR (SPY, [252])) | |
data = SPY | |
func = "ADXR" | |
args = "data.high.values, data.low.values, data.close.values, 252" | |
mycode = "data[func] = talib." + func + "(" + args + ")" | |
exec (mycode) | |
data[func].plot(grid=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment