Skip to content

Commit 47290d0

Browse files
committed
Pep8 changes
1 parent 80032d7 commit 47290d0

30 files changed

+1792
-1330
lines changed

book/ALL FINANCEPY/products/credit/FINCDSOPTION_ValuingCDSOption.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,12 @@
348348
},
349349
"outputs": [],
350350
"source": [
351-
"fwdValues = []\n",
351+
"fwd_values = []\n",
352352
"\n",
353353
"for strike in strikes:\n",
354354
" fwdCDSContract = CDS(expiry_dt, maturity_dt, strike, notional, True)\n",
355355
" v = fwdCDSContract.value(value_dt, issuer_curve, recovery_rate)\n",
356-
" fwdValues.append(v['dirty_pv'])"
356+
" fwd_values.append(v['dirty_pv'])"
357357
]
358358
},
359359
{
@@ -396,7 +396,7 @@
396396
}
397397
],
398398
"source": [
399-
"plt.plot(strikes*10000, fwdValues, label=\"Forward Values\")\n",
399+
"plt.plot(strikes*10000, fwd_values, label=\"Forward Values\")\n",
400400
"plt.plot(strikes*10000, callMinusPut, label=\"Long minus short\")\n",
401401
"plt.xlabel(\"Strike (bp)\")\n",
402402
"plt.ylabel(\"Value (USD)\")\n",

book/ALL FINANCEPY/products/equity/EQUITY_VARIANCESWAP_Basic_Example.ipynb

+6-6
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
},
140140
"outputs": [],
141141
"source": [
142-
"volSwap = EquityVarianceSwap(start_dt, tenor, strike)"
142+
"vol_swap = EquityVarianceSwap(start_dt, tenor, strike)"
143143
]
144144
},
145145
{
@@ -243,7 +243,7 @@
243243
"skew = 0\n",
244244
"strikes = np.linspace(50.0, 135.0, 18)\n",
245245
"vols = volSkew(strikes, atm_vol, atmK, skew)\n",
246-
"volCurve = EquityVolCurve(value_dt, maturity_dt, strikes, vols)"
246+
"vol_curve = EquityVolCurve(value_dt, maturity_dt, strikes, vols)"
247247
]
248248
},
249249
{
@@ -340,8 +340,8 @@
340340
}
341341
],
342342
"source": [
343-
"k1 = volSwap.fair_strike(value_dt, stock_price, dividend_curve,\n",
344-
" volCurve, num_call_options, num_put_options,\n",
343+
"k1 = vol_swap.fair_strike(value_dt, stock_price, dividend_curve,\n",
344+
" vol_curve, num_call_options, num_put_options,\n",
345345
" strike_spacing, discount_curve, False)\n",
346346
"print(\"Fair strike:\", k1)"
347347
]
@@ -367,7 +367,7 @@
367367
}
368368
],
369369
"source": [
370-
"k2 = volSwap.fair_strike_approx(value_dt, stock_price, strikes, vols)\n",
370+
"k2 = vol_swap.fair_strike_approx(value_dt, stock_price, strikes, vols)\n",
371371
"print(\"DERMAN SKEW APPROX for K:\", k2)"
372372
]
373373
},
@@ -412,7 +412,7 @@
412412
}
413413
],
414414
"source": [
415-
"volSwap.print_weights()"
415+
"vol_swap.print_weights()"
416416
]
417417
},
418418
{

financepy/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cr = "\n"
22

33
s = "####################################################################" + cr
4-
s += "# FINANCEPY BETA Version " + str('0.360') + " - This build: 30 Sep 2024 at 21:35 #" + cr
4+
s += "# FINANCEPY BETA Version " + str('0.360') + " - This build: 01 Oct 2024 at 10:42 #" + cr
55
s += "# This software is distributed FREE AND WITHOUT ANY WARRANTY #" + cr
66
s += "# Report bugs as issues at https://github.com/domokane/FinancePy #" + cr
77
s += "####################################################################"

financepy/products/equity/equity_fixed_lookback_option.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class EquityFixedLookbackOption(EquityOption):
3535
the value of the stock price used to determine the payoff is the maximum
3636
in the case of a call option, and a minimum in the case of a put option."""
3737

38-
def __init__(self, expiry_dt: Date, option_type: OptionTypes, strike_price: float):
38+
def __init__(
39+
self, expiry_dt: Date, option_type: OptionTypes, strike_price: float
40+
):
3941
"""Create the FixedLookbackOption by specifying the expiry date, the
4042
option type and the option strike."""
4143

@@ -140,7 +142,9 @@ def value(
140142

141143
else:
142144

143-
e1 = (np.log(s0 / s_max) + (r - q + v * v / 2) * t) / v / sqrt_t
145+
e1 = (
146+
(np.log(s0 / s_max) + (r - q + v * v / 2) * t) / v / sqrt_t
147+
)
144148
e2 = e1 - v * sqrt_t
145149

146150
if s0 == s_max:
@@ -199,7 +203,9 @@ def value(
199203
v = k * df * N(-d2) - s0 * dq * N(-d1) + s0 * df * u * term
200204

201205
else:
202-
raise FinError("Unknown lookback option type:" + str(self.option_type))
206+
raise FinError(
207+
"Unknown lookback option type:" + str(self.option_type)
208+
)
203209

204210
return v
205211

@@ -238,11 +244,15 @@ def value_mc(
238244
if self.option_type == OptionTypes.EUROPEAN_CALL:
239245
s_max = stock_min_max
240246
if s_max < stock_price:
241-
raise FinError("Smax must be greater than or equal to the stock price.")
247+
raise FinError(
248+
"Smax must be greater than or equal to the stock price."
249+
)
242250
elif self.option_type == OptionTypes.EUROPEAN_PUT:
243251
s_min = stock_min_max
244252
if s_min > stock_price:
245-
raise FinError("Smin must be less than or equal to the stock price.")
253+
raise FinError(
254+
"Smin must be less than or equal to the stock price."
255+
)
246256

247257
t_all, s_all = get_paths_times(
248258
num_paths, num_time_steps, t, mu, stock_price, volatility, seed

golden_tests/TestFinEquityForward.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
###############################################################################
44

55
import sys
6+
67
sys.path.append("..")
78

89
from financepy.products.equity.equity_forward import EquityForward
@@ -34,25 +35,23 @@ def test_EquityForward():
3435
discount_curve = DiscountCurveFlat(value_dt, discount_rate)
3536
dividend_curve = DiscountCurveFlat(value_dt, dividend_rate)
3637

37-
equityForward = EquityForward(expiry_dt,
38-
forward_price,
39-
notional,
40-
FinLongShort.LONG)
38+
equityForward = EquityForward(
39+
expiry_dt, forward_price, notional, FinLongShort.LONG
40+
)
4141

4242
test_cases.header("SPOT FX", "FX FWD", "VALUE_BS")
4343

44-
fwdPrice = equityForward.forward(value_dt,
45-
stock_price,
46-
discount_curve,
47-
dividend_curve)
44+
fwd_price = equityForward.forward(
45+
value_dt, stock_price, discount_curve, dividend_curve
46+
)
47+
48+
fwd_value = equityForward.value(
49+
value_dt, stock_price, discount_curve, dividend_curve
50+
)
4851

49-
fwdValue = equityForward.value(value_dt,
50-
stock_price,
51-
discount_curve,
52-
dividend_curve)
52+
# print(stock_price, fwd_price, fwd_value)
53+
test_cases.print(stock_price, fwd_price, fwd_value)
5354

54-
# print(stock_price, fwdPrice, fwdValue)
55-
test_cases.print(stock_price, fwdPrice, fwdValue)
5655

5756
###############################################################################
5857

0 commit comments

Comments
 (0)