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

MAINT: refactoring lazyval + silence a few warnings #90

Merged
merged 7 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
silence numpy divide errors
  • Loading branch information
MBounouar committed Mar 22, 2022
commit 01b731709a45e689762ea4fea5af68f055e60e9c
10 changes: 5 additions & 5 deletions src/zipline/pipeline/factors/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
sqrt,
sum as np_sum,
unique,
errstate as np_errstate,
)

from zipline.pipeline.data import EquityPricing
Expand Down Expand Up @@ -84,7 +85,8 @@ def _validate(self):
)

def compute(self, today, assets, out, values):
out[:] = (values[-1] - values[0]) / abs(values[0])
with np_errstate(divide="ignore", invalid="ignore"):
out[:] = (values[-1] - values[0]) / abs(values[0])


class DailyReturns(Returns):
Expand Down Expand Up @@ -433,9 +435,7 @@ def compute(self, today, assets, out, data, decay_rate):
variance = average((data - mean) ** 2, axis=0, weights=weights)

squared_weight_sum = np_sum(weights) ** 2
bias_correction = squared_weight_sum / (
squared_weight_sum - np_sum(weights ** 2)
)
bias_correction = squared_weight_sum / (squared_weight_sum - np_sum(weights**2))
out[:] = sqrt(variance * bias_correction)


Expand Down Expand Up @@ -489,7 +489,7 @@ class AnnualizedVolatility(CustomFactor):
window_length = 252

def compute(self, today, assets, out, returns, annualization_factor):
out[:] = nanstd(returns, axis=0) * (annualization_factor ** 0.5)
out[:] = nanstd(returns, axis=0) * (annualization_factor**0.5)


class PeerCount(SingleInputMixin, CustomFactor):
Expand Down
4 changes: 3 additions & 1 deletion src/zipline/pipeline/factors/factor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
factor.py
"""
import numpy as np
from operator import attrgetter
from numbers import Number
from math import ceil
Expand Down Expand Up @@ -1864,7 +1865,8 @@ def demean(row):


def zscore(row):
return (row - nanmean(row)) / nanstd(row)
with np.errstate(divide="ignore", invalid="ignore"):
return (row - nanmean(row)) / nanstd(row)


def winsorize(row, min_percentile, max_percentile):
Expand Down