Skip to content

Commit

Permalink
Removed .ix
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedamen committed Aug 24, 2020
1 parent 543dfba commit d3c3084
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 31 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -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)
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions finmarketpy/backtest/backtestengine.py
Expand Up @@ -1857,15 +1857,15 @@ 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]

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)
Expand Down Expand Up @@ -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

Expand Down
18 changes: 10 additions & 8 deletions finmarketpy/economics/eventstudy.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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']

Expand Down
28 changes: 15 additions & 13 deletions 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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]

Expand Down
14 changes: 8 additions & 6 deletions finmarketpy_examples/quickchart_examples.py
Expand Up @@ -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')
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')
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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',
Expand Down

0 comments on commit d3c3084

Please sign in to comment.