Skip to content
Open
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
2 changes: 1 addition & 1 deletion tf_quant_finance/math/optimizer/conjugate_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@


@attr.s
class ConjugateGradientParams(object):
class ConjugateGradientParams:
"""Adjustable parameters of conjugate gradient algorithm."""
# Real number. Sufficient decrease parameter for Wolfe conditions.
# Corresponds to `delta` in [HZ2006].
Expand Down
2 changes: 1 addition & 1 deletion tf_quant_finance/math/pde/fd_solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ def _is_callable(var_or_fn):
"""Returns whether an object is callable or not."""
# Python 2.7 as well as Python 3.x with x > 2 support 'callable'.
# In between, callable was removed hence we need to do a more expansive check
if hasattr(var_or_fn, '__call__'):
if callable(var_or_fn):
Comment on lines 692 to +694
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a legacy part to deal with Python 2.7. Since we now require Python >= 3.7, we can replace '_is_callable' with the in-built method 'callable'. Please do so or leave it as it is now

return True
try:
return callable(var_or_fn)
Expand Down
2 changes: 1 addition & 1 deletion tf_quant_finance/math/piecewise.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import tensorflow.compat.v2 as tf


class PiecewiseConstantFunc(object):
class PiecewiseConstantFunc:
"""Creates a piecewise constant function."""

def __init__(self, jump_locations, values, dtype=None, name=None):
Expand Down
11 changes: 5 additions & 6 deletions tf_quant_finance/models/hjm/gaussian_hjm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ def _true_std_time_dep(t, intervals, vol, k):
var = 0.0
for j in range(len(intervals) - 1):
if tt >= intervals[j] and tt < intervals[j + 1]:
var = var + vol[j]**2 / 2 / k * (
np.exp(2 * k * tt) - np.exp(2 * k * intervals[j]))
break
else:
var = var + vol[j]**2 / 2 / k * (
np.exp(2 * k * intervals[j + 1]) - np.exp(2 * k * intervals[j]))
var = var + vol[j]**2 / 2 / k * (
np.exp(2 * k * tt) - np.exp(2 * k * intervals[j]))
break
var = var + vol[j]**2 / 2 / k * (
np.exp(2 * k * intervals[j + 1]) - np.exp(2 * k * intervals[j]))
else:
var = var + vol[-1]**2/2/k *(np.exp(2*k*tt)-np.exp(2*k*intervals[-1]))
res[i] = np.exp(-k*tt) * np.sqrt(var)
Expand Down
11 changes: 5 additions & 6 deletions tf_quant_finance/models/hjm/quasi_gaussian_hjm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ def _true_std_time_dep(t, intervals, vol, k):
var = 0.0
for j in range(len(intervals) - 1):
if tt >= intervals[j] and tt < intervals[j + 1]:
var = var + vol[j]**2 / 2 / k * (
np.exp(2 * k * tt) - np.exp(2 * k * intervals[j]))
break
else:
var = var + vol[j]**2 / 2 / k * (
np.exp(2 * k * intervals[j + 1]) - np.exp(2 * k * intervals[j]))
var = var + vol[j]**2 / 2 / k * (
np.exp(2 * k * tt) - np.exp(2 * k * intervals[j]))
break
var = var + vol[j]**2 / 2 / k * (
np.exp(2 * k * intervals[j + 1]) - np.exp(2 * k * intervals[j]))
else:
var = var + vol[-1]**2/2/k *(np.exp(2*k*tt)-np.exp(2*k*intervals[-1]))
res[i] = np.exp(-k*tt) * np.sqrt(var)
Expand Down
11 changes: 5 additions & 6 deletions tf_quant_finance/models/hull_white/hull_white_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ def _true_std_time_dep(t, intervals, vol, k):
var = 0.0
for j in range(len(intervals) - 1):
if tt >= intervals[j] and tt < intervals[j + 1]:
var = var + vol[j]**2 / 2 / k * (
np.exp(2 * k * tt) - np.exp(2 * k * intervals[j]))
break
else:
var = var + vol[j]**2 / 2 / k * (
np.exp(2 * k * intervals[j + 1]) - np.exp(2 * k * intervals[j]))
var = var + vol[j]**2 / 2 / k * (
np.exp(2 * k * tt) - np.exp(2 * k * intervals[j]))
break
var = var + vol[j]**2 / 2 / k * (
np.exp(2 * k * intervals[j + 1]) - np.exp(2 * k * intervals[j]))
else:
var = var + vol[-1]**2/2/k *(np.exp(2*k*tt)-np.exp(2*k*intervals[-1]))
res[i] = np.exp(-k*tt) * np.sqrt(var)
Expand Down
4 changes: 2 additions & 2 deletions tf_quant_finance/models/hull_white/swaption.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def _map_payoff_to_sim_times(indices, payoff, num_samples):
"""
indices = tf.expand_dims(indices, axis=0)
indices = tf.repeat(indices, num_samples, axis=0)
index_list = list()
index_list = []
tensor_shape = np.array(indices.shape.as_list())
output_shape = indices.shape.as_list()[:-1] + [
tf.math.reduce_max(indices) + 1
Expand Down Expand Up @@ -272,7 +272,7 @@ def _analytic_valuation(expiries, floating_leg_start_times,
name=name + '_jamshidian_decomposition')

bond_strike_rank = breakeven_bond_option_strikes.shape.rank
perm = [bond_strike_rank-1] + [x for x in range(0, bond_strike_rank - 1)]
perm = [bond_strike_rank-1] + list(range(0, bond_strike_rank - 1))
breakeven_bond_option_strikes = tf.transpose(
breakeven_bond_option_strikes, perm=perm)
bond_option_prices = zcb.bond_option_price(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def _analytic_valuation(discount_rate_fn, model, strikes, expiries, maturities,
# Make `dim` as the last dimension and return.
return tf.transpose(
option_value,
perm=[i for i in range(1, len(option_value.shape.as_list()))] + [0])
perm=list(range(1, len(option_value.shape.as_list()))) + [0])


# TODO(b/158501671): Clean-up this implementation.
Expand Down
2 changes: 1 addition & 1 deletion tf_quant_finance/models/ito_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


@six.add_metaclass(abc.ABCMeta)
class ItoProcess(object):
class ItoProcess:
"""Interface for specifying Ito processes.

Interface for defining stochastic process defined by the Ito SDE:
Expand Down
2 changes: 1 addition & 1 deletion tf_quant_finance/models/legacy/brownian_motion_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def is_callable(var_or_fn):
"""Returns whether an object is callable or not."""
# Python 2.7 as well as Python 3.x with x > 2 support 'callable'.
# In between, callable was removed hence we need to do a more expansive check
if hasattr(var_or_fn, '__call__'):
if callable(var_or_fn):
return True
try:
return callable(var_or_fn)
Expand Down
2 changes: 1 addition & 1 deletion tf_quant_finance/models/legacy/ito_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@


@six.add_metaclass(abc.ABCMeta)
class ItoProcess(object):
class ItoProcess:
"""Base class for Ito processes.

Represents a general Ito process:
Expand Down
2 changes: 1 addition & 1 deletion tf_quant_finance/models/sabr/sabr_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def _is_callable(var_or_fn):
"""Returns whether an object is callable or not."""
# Python 2.7 as well as Python 3.x with x > 2 support 'callable'.
# In between, callable was removed hence we need to do a more expansive check
if hasattr(var_or_fn, '__call__'):
if callable(var_or_fn):
return True
try:
return callable(var_or_fn)
Expand Down