diff --git a/README.md b/README.md index bb9c97c..59c0cff 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ In finmarketpy/examples you will find several examples, including some simple tr # Release Notes +* 0.11.5 - finmarketpy (24 Aug 2020) * 0.11.4 - finmarketpy (06 May 2020) * 0.11.3 - finmarketpy (04 Dec 2019) * 0.11.1 - finmarketpy (23 Oct 2019) @@ -114,6 +115,8 @@ In finmarketpy/examples you will find several examples, including some simple tr # finmarketpy log +* 24 Aug 2020 + * Replaced .ix to work with later versions of pandas * 07 May 2020 * Improved QuickChart, adding additional labels, fixing example * 06 May 2020 diff --git a/finmarketpy/backtest/backtestengine.py b/finmarketpy/backtest/backtestengine.py index 6921b13..2519864 100644 --- a/finmarketpy/backtest/backtestengine.py +++ b/finmarketpy/backtest/backtestengine.py @@ -1857,7 +1857,7 @@ def plot_strategy_net_exposures_notional(self, strip=None, silent_plot=False, re #### grab signals for specific days def _grab_signals(self, strategy_signal, date=None, strip=None): if date is None: - last_day = strategy_signal.ix[-1].transpose().to_frame() + last_day = strategy_signal.loc[-1].transpose().to_frame() else: if not (isinstance(date, list)): date = [date] @@ -1865,7 +1865,7 @@ def _grab_signals(self, strategy_signal, date=None, strip=None): last_day = [] for d in date: - last_day.append(strategy_signal.ix[d].transpose().to_frame()) + last_day.append(strategy_signal[d].transpose().to_frame()) last_day = pandas.concat(last_day, axis=1) last_day = last_day.sort_index(axis=1) @@ -2053,7 +2053,7 @@ def calculate_leverage_factor(self, returns_df, vol_target, vol_max_leverage, vo # # now realign back to days when we trade # returns_df, lev_df = returns_df.align(lev_df, join='left', axis=0) - lev_df.ix[0:vol_periods] = numpy.nan # ignore the first elements before the vol window kicks in + lev_df[0:vol_periods] = numpy.nan # ignore the first elements before the vol window kicks in return lev_df diff --git a/finmarketpy/economics/eventstudy.py b/finmarketpy/economics/eventstudy.py index 899dbba..b4b5b70 100644 --- a/finmarketpy/economics/eventstudy.py +++ b/finmarketpy/economics/eventstudy.py @@ -59,7 +59,7 @@ def get_economic_event_ret_over_custom_event_day(self, data_frame_in, event_date data_frame.index = data_frame.index + bday # set as New York time and select only those ON vols at the 10am NY cut just before the event - data_frame_events = data_frame.ix[event_dates.index] + data_frame_events = data_frame[event_dates.index] data_frame_events.columns = data_frame.columns.values + '-' + name + ' ' + event return data_frame_events @@ -104,13 +104,15 @@ def get_intraday_moves_over_custom_event(self, data_frame_rets, ef_time_frame, v # TODO vectorise this! for i in range(0, len(ef_time_frame.index)): try: - data_frame_rets.ix[start_index[i]:finish_index[i], 'Ind'] = ords + data_frame_rets['Ind'][start_index[i]:finish_index[i]] = ords except: - data_frame_rets.ix[start_index[i]:finish_index[i], 'Ind'] = ords[0:(finish_index[i] - start_index[i])] + data_frame_rets['Ind'][start_index[i]:finish_index[i]] = ords[0:(finish_index[i] - start_index[i])] - # set the release dates - data_frame_rets.ix[start_index, 'Rel'] = ef_time # set entry points - data_frame_rets.ix[finish_index + 1, 'Rel'] = numpy.zeros(len(start_index)) # set exit points + data_frame_rets['Rel'] = numpy.nan + + # Set the release dates + data_frame_rets['Rel'][start_index] = ef_time # set entry points + data_frame_rets['Rel'][finish_index + 1] = numpy.zeros(len(start_index)) # set exit points data_frame_rets['Rel'] = data_frame_rets['Rel'].fillna(method='pad') # fill down signals data_frame_rets = data_frame_rets[pandas.notnull(data_frame_rets['Ind'])] # get rid of other @@ -122,7 +124,7 @@ def get_intraday_moves_over_custom_event(self, data_frame_rets, ef_time_frame, v if create_index: calculations = Calculations() - data_frame.ix[-minute_start + min_offset, :] = numpy.nan + data_frame.iloc[-minute_start + min_offset] = numpy.nan data_frame = calculations.create_mult_index(data_frame) else: if vol is True: @@ -548,7 +550,7 @@ def get_economic_data_history(self, start_date, finish_date, country_group, data return self.market_data_generator.fetch_market_data(md_request) def grasp_coded_entry(self, df, index): - df = df.ix[index:].stack() + df = df[index:].stack() df = df.reset_index() df.columns = ['Date', 'Name', 'Val'] diff --git a/finmarketpy/economics/quickchart.py b/finmarketpy/economics/quickchart.py index a5ff65d..76f4537 100644 --- a/finmarketpy/economics/quickchart.py +++ b/finmarketpy/economics/quickchart.py @@ -1,7 +1,7 @@ __author__ = 'saeedamen' # Saeed Amen / saeed@thalesians.com # -# Copyright 2016 Cuemacro +# Copyright 2020 Cuemacro # # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the # License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 @@ -40,7 +40,7 @@ def plot_chart(self, tickers=None, tickers_rhs=None, start_date=None, finish_dat reindex=False, yoy=False, plotly_plot_mode='offline_png', quandl_api_key=dataconstants.quandl_api_key, fred_api_key=dataconstants.fred_api_key, - alpha_vantage_api_key=dataconstants.alpha_vantage_api_key): + alpha_vantage_api_key=dataconstants.alpha_vantage_api_key, df=None): if start_date is None: start_date = datetime.datetime.utcnow().date() - timedelta(days=60) @@ -72,17 +72,19 @@ def plot_chart(self, tickers=None, tickers_rhs=None, start_date=None, finish_dat else: tickers_rhs = {} - md_request = MarketDataRequest(start_date=start_date, finish_date=finish_date, - freq=freq, - data_source=self._data_source, - tickers=list(tickers.keys()), vendor_tickers=list(tickers.values()), - fields=list(fields.keys()), - vendor_fields=list(fields.values()), - quandl_api_key=quandl_api_key, - fred_api_key=fred_api_key, - alpha_vantage_api_key=alpha_vantage_api_key) - - df = self._market.fetch_market(md_request=md_request) + if df is None: + md_request = MarketDataRequest(start_date=start_date, finish_date=finish_date, + freq=freq, + data_source=self._data_source, + tickers=list(tickers.keys()), vendor_tickers=list(tickers.values()), + fields=list(fields.keys()), + vendor_fields=list(fields.values()), + quandl_api_key=quandl_api_key, + fred_api_key=fred_api_key, + alpha_vantage_api_key=alpha_vantage_api_key) + + df = self._market.fetch_market(md_request=md_request) + df = df.fillna(method='ffill') df.columns = [x.split('.')[0] for x in df.columns] diff --git a/finmarketpy_examples/quickchart_examples.py b/finmarketpy_examples/quickchart_examples.py index 43c9796..1be325a 100644 --- a/finmarketpy_examples/quickchart_examples.py +++ b/finmarketpy_examples/quickchart_examples.py @@ -42,11 +42,13 @@ from finmarketpy.economics import QuickChart # Plot with matplotlib - Major USD crosses reindexed from 100 in 2020 - QuickChart(engine='matplotlib', data_source='bloomberg').plot_chart(tickers=['EURUSD Curncy', 'GBPUSD Curncy', 'AUDUSD Curncy'], - title='USD crosses in 2020', - start_date='01 Jan 2020', reindex=True, source='Bloomberg') + QuickChart(engine='matplotlib', data_source='bloomberg').plot_chart( + tickers=['EURUSD Curncy', 'GBPUSD Curncy', 'AUDUSD Curncy'], + title='USD crosses in 2020', + start_date='01 Jan 2020', reindex=True, source='Bloomberg') # Plot with Plotly - Major USD crosses reindexed from 100 in 2020 - QuickChart(engine='plotly', data_source='bloomberg').plot_chart(tickers=['EURUSD Curncy', 'GBPUSD Curncy', 'AUDUSD Curncy'], - title='USD crosses in 2020 (Plotly)', - start_date='01 Jan 2020', reindex=True, source='Bloomberg') \ No newline at end of file + QuickChart(engine='plotly', data_source='bloomberg').plot_chart( + tickers=['EURUSD Curncy', 'GBPUSD Curncy', 'AUDUSD Curncy'], + title='USD crosses in 2020 (Plotly)', + start_date='01 Jan 2020', reindex=True, source='Bloomberg') \ No newline at end of file diff --git a/setup.py b/setup.py index 8f37192..0cd9b36 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ trading strategies using a simple to use API, which has prebuilt templates for you to define backtest.""" setup(name='finmarketpy', - version='0.11.4', + version='0.11.5', description='finmarketpy is a Python based library for backtesting trading strategies', author='Saeed Amen', author_email='saeed@cuemacro.com',