def get_darwin_dataset(self, assets, cumulative=True, rebase=False): # Type checks for mandatorily used arguments if isinstance(assets, str): _symbols = [assets] elif isinstance(assets, list): _symbols = [a for a in assets] else: raise TypeError("Invalid DARWIN symbols array '{0}'. " "It should be a list of strings.".format(assets)) # Get Quotes _portfolio = self.info_api._Get_Historical_Quotes_(_symbols=_symbols) # Rebase to common dates if rebase: _portfolio.dropna(inplace=True) # Calculate cumulative portfolio returns _portfolio = calculate_portfolio_returns(_portfolio, cumulative=cumulative) # symbols now contains a dataframe of Quotes by asset, one column per. # symbols.columns will have a different source later on after calculating # the portfolio _portfolio.columns = ['Close'] return qm.Chart(_portfolio)
def update_graph_from_dropdown(dropdown_nsub, multi, arglist, dropdown): df = None if dropdown is None or len(dropdown) <= 0: return None if len(dropdown.split('.')) > 1: df = fetch_ib_history(dropdown) else: try: df = web.DataReader(dropdown, 'yahoo', dt.datetime(2016, 1, 1), dt.datetime.now()) except Exception as e: try: df = bca.fetch_history(dropdown, dt.datetime(2016, 1, 1), dt.datetime.now()) except Exception: pass if df is None or len(df) <= 0: print(f'update_graph_from_dropdown: no data for {dropdown}') return None print(df.tail()) print('Loading') ch = qm.Chart(df) # Get functions and arglist for technical indicators if arglist: arglist = arglist.replace('(', '').replace(')', '').split(';') arglist = [args.strip() for args in arglist] for function, args in zip(multi, arglist): if args: args = args.split(',') newargs = [] for arg in args: try: arg = int(arg) except: try: arg = float(arg) except: pass newargs.append(arg) print(newargs) # Dynamic calling getattr(qm, function)(ch, *newargs) else: getattr(qm, function)(ch) else: for function in multi: # Dynamic calling getattr(qm, function)(ch) # Return plot as figure fig = ch.to_figure(width=1100) return fig
def update_graph_from_dropdown(dropdown, multi, arglist): print('start') # Get Quantmod Chart df = web.DataReader(dropdown, 'yahoo', dt.datetime(2016, 1, 1), dt.datetime.now()) print('Loading') ch = qm.Chart(df) print(ch) # try: # df = web.DataReader(dropdown, 'yahoo', dt.datetime(2016, 1, 1), dt.datetime.now()) # print('Loading') # ch = qm.Chart(df) # print(ch) # except: # pass # Get functions and arglist for technical indicators if arglist: arglist = arglist.replace('(', '').replace(')', '').split(';') arglist = [args.strip() for args in arglist] for function, args in zip(multi, arglist): if args: args = args.split(',') newargs = [] for arg in args: try: arg = int(arg) except: try: arg = float(arg) except: pass newargs.append(arg) print(newargs) # Dynamic calling getattr(qm, function)(ch, *newargs) else: getattr(qm, function)(ch) else: for function in multi: # Dynamic calling getattr(qm, function)(ch) # Return plot as figure fig = ch.to_figure(width=1100) return fig
def update_graph_from_dropdown(dropdown, multi, arglist): # Get Quantmod Chart try: #df = web.DataReader(dropdown, 'stooq', dt.datetime(2016, 1, 1), dt.datetime.now()) df = web.DataReader(dropdown, 'moex', dt.datetime(2016, 1, 1), dt.datetime.now()). \ rename(dict(zip(['OPEN', 'LOW', 'HIGH', 'CLOSE', 'VALUE'], ['Open', 'High', 'Low', 'Close', 'Volume'])), axis=1) print('Loading') ch = qm.Chart(df) except: print('finito') raise # Get functions and arglist for technical indicators if arglist: arglist = arglist.replace('(', '').replace(')', '').split(';') arglist = [args.strip() for args in arglist] for function, args in zip(multi, arglist): if args: args = args.split(',') newargs = [] for arg in args: try: arg = int(arg) except: try: arg = float(arg) except: pass newargs.append(arg) print(newargs) # Dynamic calling getattr(qm, function)(ch, *newargs) else: getattr(qm, function)(ch) else: for function in multi: # Dynamic calling getattr(qm, function)(ch) # Return plot as figure fig = ch.to_figure(width=1100) return fig
def update_graph_from_dropdown(dropdown, multi, arglist): # Get Quantmod Chart print('Loading') strategy, config, res = setup_config(dropdown) candles, trade_scatter = setup_chart(res) ch = qm.Chart(candles, src=src) # Get functions and arglist for technical indicators if arglist: for function in multi: try: config = talib_dict(json.loads(arglist)) indicator = function.split("_")[1] newargs = config[indicator] # Dynamic calling fn = getattr(qm, function) fn(ch, **newargs) except Exception as e: print(e) getattr(qm, function)(ch) pass else: for function in multi: # Dynamic calling getattr(qm, function)(ch) fig = ch.to_figure(width=1100) # hack figure index = 0 for i in range(len(fig["layout"].keys())): axis = "yaxis" + str(i) if axis in fig["layout"]: index = i + 1 yrange = [candles["low"].min(), candles["high"].max()] fig["layout"]["yaxis"]["range"] = yrange fig["layout"]["yaxis" + str(index)] = fig["layout"]["yaxis2"] fig["layout"]["plot_bgcolor"] = 'rgba(0, 0, 0, 0.00)' trade_scatter["yaxis"] = "y1" fig["data"].append(trade_scatter) return fig
''' Created on Feb 4, 2019 @author: bperlman1 ''' import dash import quantmod as qm import datetime as dt import pandas_datareader.data as web import dash_core_components as dcc import dash_html_components as html app = dash.Dash(__name__) df = web.DataReader('SPY', 'yahoo', dt.datetime(2016, 1, 1), dt.datetime.now()) print('Loading') ch = qm.Chart(df) fig = ch.to_figure(width=1100) app.layout = html.Div([ dcc.Graph(id='my-graph', figure=fig), ], ) if __name__ == '__main__': app.server.run(port=8500)
# In[]: import numpy as np import quantmod as qm import pandas as pd import pandas_datareader as web # In[]: ticker = 'AAPL' df = web.DataReader(ticker, data_source='yahoo', start='2016/01/01') df = df.tail(365) ch = qm.Chart(df, start='2015/01/01', end='2017/03/02') ch.has_open ch.has_high ch.has_low ch.has_close ch.op ch.df ch.ind ch.pri ch.adjust(inplace=True) ch.adjust_volume(inplace=True) ch.has_OHLC print(ch.has_OHLCV) ch.add_MA()