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

Fix pandas deprecation warnings #202

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
__pycache__/
*.py[cod]

# IDE-specific settings
.idea/

# C extensions & files
*.so
*.c
Expand Down
22 changes: 11 additions & 11 deletions ffn/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def _calculate(self, obj):
self.best_day = r.max()
self.worst_day = r.min()

self.total_return = obj[-1] / obj[0] - 1
self.total_return = obj.iloc[-1] / obj.iloc[0] - 1

self.cagr = calc_cagr(dp)
self.incep = self.cagr
Expand Down Expand Up @@ -305,7 +305,7 @@ def _calculate(self, obj):
# add first month
fidx = mr.index[0]
try:
self.return_table[fidx.year][fidx.month] = float(mp[0]) / dp[0] - 1
self.return_table[fidx.year][fidx.month] = float(mp.iloc[0]) / dp.iloc[0] - 1
except ZeroDivisionError:
self.return_table[fidx.year][fidx.month] = 0
# calculate the YTD values
Expand All @@ -319,7 +319,7 @@ def _calculate(self, obj):

denom = dp[: dp.index[-1] - pd.DateOffset(months=3)]
if len(denom) > 0:
self.three_month = dp[-1] / denom[-1] - 1
self.three_month = dp.iloc[-1] / denom.iloc[-1] - 1

if r.index.to_series().diff().min() < pd.Timedelta("32 days"):
if len(mr) < 4:
Expand All @@ -338,7 +338,7 @@ def _calculate(self, obj):
denom = dp[: dp.index[-1] - pd.DateOffset(months=6)]

if len(denom) > 0:
self.six_month = dp[-1] / denom[-1] - 1
self.six_month = dp.iloc[-1] / denom.iloc[-1] - 1

# Will calculate yearly figures only if the input data has at least yearly frequency or higher (e.g monthly)
# Rather < 367 days than <= 366 days in case of data taken at different hours of the days
Expand All @@ -352,7 +352,7 @@ def _calculate(self, obj):
denom = dp[: dp.index[-1] - pd.DateOffset(years=1)]

if len(denom) > 0:
self.one_year = dp[-1] / denom[-1] - 1
self.one_year = dp.iloc[-1] / denom.iloc[-1] - 1

self.yearly_mean = yr.mean()
self.yearly_vol = np.std(yr, ddof=1)
Expand Down Expand Up @@ -381,7 +381,7 @@ def _calculate(self, obj):
win = 0
for i in range(11, len(mr)):
tot += 1
if mp[i] / mp[i - 11] > 1:
if mp.iloc[i] / mp.iloc[i - 11] > 1:
win += 1
self.twelve_month_win_perc = float(win) / tot

Expand Down Expand Up @@ -1229,7 +1229,7 @@ def to_drawdown_series(prices):
drawdown = prices.copy()

# Fill NaN's with previous values
drawdown = drawdown.fillna(method="ffill")
drawdown = drawdown.ffill()

# Ignore problems with NaN's in the beginning
drawdown[np.isnan(drawdown)] = -np.Inf
Expand All @@ -1253,9 +1253,9 @@ def calc_mtd(daily_prices, monthly_prices):
else use monthly_prices
"""
if len(monthly_prices) == 1:
return daily_prices[-1] / daily_prices[0] - 1
return daily_prices.iloc[-1] / daily_prices.iloc[0] - 1
else:
return daily_prices[-1] / monthly_prices[-2] - 1
return daily_prices.iloc[-1] / monthly_prices.iloc[-2] - 1


def calc_ytd(daily_prices, yearly_prices):
Expand All @@ -1265,9 +1265,9 @@ def calc_ytd(daily_prices, yearly_prices):
else use yearly_prices
"""
if len(yearly_prices) == 1:
return daily_prices[-1] / daily_prices[0] - 1
return daily_prices.iloc[-1] / daily_prices.iloc[0] - 1
else:
return daily_prices[-1] / yearly_prices[-2] - 1
return daily_prices.iloc[-1] / yearly_prices.iloc[-2] - 1


def calc_max_drawdown(prices):
Expand Down