Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated get_range_selector() #278

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
b049673
Update tools.py
Saran33 Aug 16, 2021
e9a026d
Update quant_figure.py
Saran33 Aug 16, 2021
b34816f
Merge pull request #2 from Saran33/Saran33-3
Saran33 Aug 16, 2021
cf7d4bd
Update ta.py
Saran33 Aug 16, 2021
5bea26c
Merge pull request #3 from Saran33/Saran33-patch-2
Saran33 Aug 16, 2021
09a81f9
Update plotlytools.py
Saran33 Aug 16, 2021
7f43198
Merge pull request #4 from Saran33/Saran33-patch-2
Saran33 Aug 16, 2021
0b233ac
Update tools.py
Saran33 Aug 16, 2021
289cd79
Merge pull request #5 from Saran33/Saran33-patch-3
Saran33 Aug 16, 2021
96edf0d
Update tools.py
Saran33 Aug 16, 2021
dd831bf
Merge pull request #6 from Saran33/Saran33-patch-4
Saran33 Aug 16, 2021
c3e0373
Update plotlytools.py
Saran33 Aug 16, 2021
a966c39
Merge pull request #7 from Saran33/Saran33-patch-5
Saran33 Aug 16, 2021
b6d0539
Update tools.py
Saran33 Aug 16, 2021
fc13518
Merge pull request #8 from Saran33/Saran33-patch-6
Saran33 Aug 16, 2021
b39e3c5
Update tools.py
Saran33 Aug 16, 2021
70e8c34
Update tools.py
Saran33 Aug 16, 2021
c7eb455
Merge pull request #9 from Saran33/Saran33-patch-6
Saran33 Aug 16, 2021
8186e11
Update py tools
Saran33 Aug 16, 2021
470c671
Merge pull request #10 from Saran33/Saran33-patch-7
Saran33 Aug 16, 2021
3df709f
Update ta.py
Saran33 Aug 16, 2021
2ddb63f
Merge pull request #11 from Saran33/Saran33-patch-8-1
Saran33 Aug 16, 2021
9f38828
Update qf
Saran33 Aug 16, 2021
66286b9
Merge pull request #12 from Saran33/Saran33-patch-2
Saran33 Aug 16, 2021
cc30ab4
Update ta.py
Saran33 Aug 16, 2021
a5b8d5a
Merge pull request #13 from Saran33/Saran33-patch-3
Saran33 Aug 16, 2021
ae5c9f2
Update tools.py
Saran33 Aug 16, 2021
c6a9e33
Merge pull request #14 from Saran33/Saran33-patch-4
Saran33 Aug 16, 2021
ec88d1d
Update plotlytools
Saran33 Aug 16, 2021
ee65945
Merge pull request #15 from Saran33/Saran33-patch-5
Saran33 Aug 16, 2021
47b800a
Update ta.py
Saran33 Aug 16, 2021
395446c
Merge pull request #17 from Saran33/Saran33-patch-22
Saran33 Aug 16, 2021
314ebad
Add files via upload
Saran33 Aug 20, 2021
e07bb67
Update tools.py
Saran33 Aug 24, 2021
3a84fd8
Added control for annotations
Saran33 Sep 10, 2021
1fecf29
Annotations control
Saran33 Sep 10, 2021
0e4c7d7
Update quant_figure.py
Saran33 Nov 17, 2021
22652d5
Update quant_figure.py
Saran33 Nov 17, 2021
5932648
lru_cache
Saran33 Nov 22, 2021
0fe1b34
lru_cache
Saran33 Nov 22, 2021
610d28f
Merge branch 'master' into Saran33
Saran33 Nov 22, 2021
5b52242
Merge pull request #18 from Saran33/Saran33
Saran33 Nov 22, 2021
7c76e86
Heatmap colorscale
Saran33 Nov 22, 2021
3a89d37
Merge pull request #19 from Saran33/Saran33
Saran33 Nov 22, 2021
cdf0433
Added Kalman Filter
Saran33 Nov 24, 2021
1eed751
Kalman
Saran33 Nov 24, 2021
2a0e5e2
Kalman
Saran33 Nov 24, 2021
091b439
Merge pull request #20 from Saran33/Saran33
Saran33 Nov 24, 2021
c5cba80
Update ta.py
Saran33 Nov 24, 2021
69d8183
Update ta.py
Saran33 Nov 25, 2021
fe36605
Merge pull request #21 from Saran33/Saran33
Saran33 Nov 25, 2021
a30e365
Update Kalman Filter
Saran33 Jan 27, 2022
405d608
Update get_range_selector
Saran33 Feb 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cufflinks/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import json
import warnings
from .offline import go_offline
from functools import lru_cache

package='cufflinks'

Expand Down Expand Up @@ -176,7 +177,7 @@ def set_config_file(sharing=None,theme=None,colorscale=None,offline=None,offline
save_json_dict(CONFIG_FILE, config)
ensure_local_files()


@lru_cache(maxsize=32)
def get_config_file(*args):
"""
Return specified args from `~/.config`. as dict.
Expand Down Expand Up @@ -260,4 +261,4 @@ def save_json_dict(filename, json_dict):
with open(filename, "w") as f:
f.write(json.dumps(json_dict, indent=4))
else:
raise TypeError("json_dict was not a dictionary. couldn't save.")
raise TypeError("json_dict was not a dictionary. couldn't save.")
24 changes: 15 additions & 9 deletions cufflinks/plotlytools.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def dict_to_iplot(d):

def _to_iplot(self,colors=None,colorscale=None,kind='scatter',mode='lines',interpolation='linear',symbol='dot',size='12',fill=False,
width=3,dash='solid',sortbars=False,keys=False,bestfit=False,bestfit_colors=None,opacity=0.6,
mean=False,mean_colors=None,asDates=False,asTimestamp=False,text=None,**kwargs):
mean=False,mean_colors=None,asDates=False,asTimestamp=False,text=None,hovertext=None,textangle=None,**kwargs):
"""
Generates a plotly Data object

Expand Down Expand Up @@ -206,7 +206,7 @@ def _iplot(self,kind='scatter',data=None,layout=None,filename='',sharing=None,ti
bestfit_colors=None,mean=False,mean_colors=None,categories='',x='',y='',z='',text='',gridcolor=None,
zerolinecolor=None,margin=None,labels=None,values=None,secondary_y='',secondary_y_title='',subplots=False,shape=None,error_x=None,
error_y=None,error_type='data',locations=None,lon=None,lat=None,asFrame=False,asDates=False,asFigure=False,
asImage=False,dimensions=None,asPlot=False,asUrl=False,online=None,**kwargs):
asImage=False,dimensions=None,asPlot=False,asUrl=False,online=None,hovertemplate=None,hovertext=None,textangle=None,arrowlen=-50,**kwargs):
"""
Returns a plotly chart either as inline chart, image of Figure object

Expand Down Expand Up @@ -666,9 +666,9 @@ def _iplot(self,kind='scatter',data=None,layout=None,filename='',sharing=None,ti
"""

# Valid Kwargs
valid_kwargs = ['color','opacity','column','columns','labels','text','world_readable','colorbar']
valid_kwargs = ['color','opacity','column','columns','labels','text','world_readable','colorbar','hoverinfo','hovertext']
BUBBLE_KWARGS = ['abs_size']
TRACE_KWARGS = ['hoverinfo','connectgaps']
TRACE_KWARGS = ['hoverinfo','connectgaps','hovertext']
HEATMAP_SURFACE_KWARGS = ['center_scale','zmin','zmax']
PIE_KWARGS=['sort','pull','hole','textposition','textinfo','linecolor','linewidth','textcolor']
OHLC_KWARGS=['up_color','down_color','open','high','low','close','volume','name','decreasing','increasing']
Expand Down Expand Up @@ -770,7 +770,7 @@ def get_marker(marker={}):
df=self.copy()
df=df.set_index(categories)
fig=df.figure(kind=kind,colors=colors,colorscale=colorscale,fill=fill,width=width,sortbars=sortbars,opacity=opacity,
asDates=asDates,mode=mode,symbol=symbol,size=size,text=text,barmode=barmode,orientation=orientation)
asDates=asDates,mode=mode,symbol=symbol,size=size,text=text,barmode=barmode,orientation=orientation,textangle=textangle,hovertext=hovertext)
data=fig['data']
else:
_keys=pd.unique(self[categories])
Expand Down Expand Up @@ -871,6 +871,8 @@ def get_marker(marker={}):
orientation = 'h' if kind=='barh' else orientation
for trace in data:
trace.update(orientation=orientation)
trace.update(textangle=textangle)
trace.update(hovertext=hovertext)
if orientation=='h':
trace['x'],trace['y']=trace['y'],trace['x']

Expand Down Expand Up @@ -956,9 +958,11 @@ def get_marker(marker={}):
x=self.index.values.tolist()
y=self[y].values.tolist() if y else self.columns.values.tolist()
z=self[z].values.tolist() if z else self.values.transpose()
scale=get_scales('rdbu') if not colorscale else get_scales(colorscale)
scale=[normalize(_) for _ in scale]
colorscale=[[float(_)/(len(scale)-1),scale[_]] for _ in range(len(scale))]
# scale=get_scales('rdbu') if not colorscale else get_scales(colorscale)
scale=get_scales('rdbu') if not colorscale else colorscale
# scale=[normalize(_) for _ in scale]
# colorscale=[[float(_)/(len(scale)-1),scale[_]] for _ in range(len(scale))]

center_scale = kwargs.get('center_scale',None)

if is_list(z):
Expand Down Expand Up @@ -1625,11 +1629,13 @@ def get_study(df,func,iplot_kwargs,iplot_study_kwargs,str=None,include=False,col
study_kwargs=check_kwargs(iplot_kwargs,__TA_KWARGS,{},clean_origin=True)
iplot_study_kwargs=kwargs_from_keyword(iplot_kwargs,{},'study')

# if not study == 'kalman': # Saran
# study_kwargs.update({'periods':periods})
study_kwargs.update({'periods':periods})

ta_func = eval('ta.{0}'.format(study))

inset=study in ('sma','boll','ema','atr','ptps')
inset=study in ('sma','boll','ema','atr','ptps','ama', 'kalman')
figure=get_study(self,ta_func,iplot_kwargs,iplot_study_kwargs,include=include,
column=column,str=str,inset=inset)

Expand Down
126 changes: 120 additions & 6 deletions cufflinks/quant_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ def figure(self,**kwargs):

"""
kwargs['asFigure']=True
kwargs['auto_open']=auto_open #Saran
return self.iplot(**kwargs)

def _panel_domains(self,n=2,min_panel_size=.15,spacing=0.08,top_margin=1,bottom_margin=0):
Expand Down Expand Up @@ -713,8 +714,120 @@ def add_sma(self,periods=20,column=None,name='',
'display':utils.merge_dict({'legendgroup':False},kwargs)}
self._add_study(study)

def add_line(self,column=None,name='',
str=None,**kwargs):
"""
#Saran: Add another security (line, not OHLC) to QuantFigure.studies

Parameters:
periods : int or list(int)
Number of periods
column :string
Defines the data column name that contains the
data over which the study will be applied.
Default: 'close'
name : string
Name given to the study
str : string
Label factory for studies
The following wildcards can be used:
{name} : Name of the column
{study} : Name of the study
{period} : Period used
Examples:
'study: {study} - period: {period}'
kwargs:
legendgroup : bool
If true, all legend items are grouped into a
single one
All formatting values available on iplot()
"""
if not column:
column=self._d['close']
study={'kind':'line',
'name':name,
'params':{'column':column,
'str':str},
'display':utils.merge_dict({'legendgroup':False},kwargs)}
self._add_study(study)

def add_ama(self,periods=9,column=None,name='',
str=None,**kwargs):
"""
Saran: Add Adaptive Moving Average (AMA) study to QuantFigure.studies

Parameters:
periods : int
Number of periods
fast_period : int
number of periods for the fastest EMA constant.
slow_period : int
number of periods for the slowest EMA constant.
column :string
Defines the data column name that contains the
data over which the study will be applied.
Default: 'close'
name : string
Name given to the study
str : string
Label factory for studies
The following wildcards can be used:
{name} : Name of the column
{study} : Name of the study
{period} : Period used
Examples:
'study: {study} - period: {period}'
kwargs:
legendgroup : bool
If true, all legend items are grouped into a
single one
All formatting values available on iplot()
"""
if not column:
column=self._d['close']
study={'kind':'ama',
'name':name,
'params':{'periods':periods,'column':column,
'str':str},
'display':utils.merge_dict({'legendgroup':False},kwargs)}
self._add_study(study)

def add_kalman(self,periods=1,column=None,name='',
str=None,**kwargs):
"""
Saran: Add a Kalman Filter study to QuantFigure.studies

Parameters:
column :string
Defines the data column name that contains the
data over which the study will be applied.
Default: 'close'
name : string
Name given to the study
str : string
Label factory for studies
The following wildcards can be used:
{name} : Name of the column
{study} : Name of the study
Examples:
'study: {study}'
kwargs:
legendgroup : bool
If true, all legend items are grouped into a
single one
All formatting values available on iplot()
"""
if not column:
column=self._d['close']
study={'kind':'kalman',
'name':name,
'params':{'periods':periods,'column':column,
'str':str},
'display':utils.merge_dict({'legendgroup':False},kwargs)}
self._add_study(study)

def add_rsi(self,periods=20,rsi_upper=70,rsi_lower=30,showbands=True,column=None,
name='',str=None,**kwargs):
name='',str='{name}({period})',**kwargs):
"""
Add Relative Strength Indicator (RSI) study to QuantFigure.studies

Expand Down Expand Up @@ -763,7 +876,7 @@ def add_rsi(self,periods=20,rsi_upper=70,rsi_lower=30,showbands=True,column=None
self._add_study(study)

def add_bollinger_bands(self,periods=20,boll_std=2,fill=True,column=None,name='',
str='{name}({column},{period})',**kwargs):
str='{name}({period})',**kwargs):
"""
Add Bollinger Bands (BOLL) study to QuantFigure.studies

Expand Down Expand Up @@ -1068,7 +1181,7 @@ def get_params(locals_list,params,display,append_study=True):
fig['data'][0].update(marker=dict(color=bar_colors,line=dict(color=bar_colors)),
opacity=0.8)

if kind in ('sma','ema','atr','adx','dmi','ptps'):
if kind in ('sma','ema','atr','adx','dmi','ptps','ama','kalman', f'{df}'): #Saran
local_kwargs,params=get_params([],params,display)
fig=df.ta_figure(study=kind,**params)

Expand Down Expand Up @@ -1144,7 +1257,7 @@ def get_params(locals_list,params,display,append_study=True):

def iplot(self,**kwargs):
__QUANT_FIGURE_EXPORT = ['asFigure','asUrl','asImage','asPlot','display_image','validate',
'sharing','online','filename','dimensions']
'sharing','online','filename','dimensions','auto_open'] # Saran added auto_open

layout=copy.deepcopy(self.layout)
data=copy.deepcopy(self.data)
Expand All @@ -1154,6 +1267,7 @@ def iplot(self,**kwargs):
data['resample']=kwargs.pop('resample',data.pop('resample',None))

asFigure=kwargs.pop('asFigure',False)
auto_open=kwargs.pop('auto_open',False) # Saran
showstudies=kwargs.pop('showstudies',True)
study_kwargs=utils.kwargs_from_keyword(kwargs,{},'study',True)
datalegend=kwargs.pop('datalegend',data.pop('datalegend',data.pop('showlegend',True)))
Expand Down Expand Up @@ -1237,7 +1351,7 @@ def iplot(self,**kwargs):
if 'yaxis' in study_fig['layout']:
study_fig['layout']['yaxis1']=study_fig['layout']['yaxis'].copy()
del study_fig['layout']['yaxis']
if v['kind'] in ('boll','sma','ema','ptps'):
if v['kind'] in ('boll','sma','ema','ptps','ama','kalman',f'{df}'): #Saran
tools._move_axis(study_fig, yaxis='y2') # FIXME TKP
pass
if v['kind'] in ('rsi','volume','macd','atr','adx','cci','dmi'):
Expand Down Expand Up @@ -1265,7 +1379,7 @@ def iplot(self,**kwargs):
except:
pass
if asFigure:
return go.Figure(fig)
return go.Figure(fig) # , write_html={'auto_open': auto_open}
else:
return pt_iplot(fig, **export_kwargs)

Expand Down
Loading