Skip to content

Commit

Permalink
Fixed unit tests and some pep8 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
domokane committed Sep 30, 2024
1 parent c42ebbc commit 80032d7
Show file tree
Hide file tree
Showing 113 changed files with 5,537 additions and 3,795 deletions.
14 changes: 7 additions & 7 deletions book/ALL FINANCEPY/products/bonds/FINANNUITY_Valuation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,14 @@
"outputs": [],
"source": [
"depos = []\n",
"dcType = DayCountTypes.ACT_360\n",
"fixedFreq = FrequencyTypes.SEMI_ANNUAL\n",
"dc_type = DayCountTypes.ACT_360\n",
"fixed_freq = FrequencyTypes.SEMI_ANNUAL\n",
"swap_type = SwapTypes.PAY\n",
"swap1 = IborSwap(settle_dt,\"1Y\",swap_type,0.0500,fixedFreq,dcType)\n",
"swap2 = IborSwap(settle_dt,\"2Y\",swap_type,0.0500,fixedFreq,dcType)\n",
"swap3 = IborSwap(settle_dt,\"3Y\",swap_type,0.0500,fixedFreq,dcType)\n",
"swap4 = IborSwap(settle_dt,\"4Y\",swap_type,0.0500,fixedFreq,dcType)\n",
"swap5 = IborSwap(settle_dt,\"5Y\",swap_type,0.0500,fixedFreq,dcType)\n",
"swap1 = IborSwap(settle_dt,\"1Y\",swap_type,0.0500,fixed_freq,dc_type)\n",
"swap2 = IborSwap(settle_dt,\"2Y\",swap_type,0.0500,fixed_freq,dc_type)\n",
"swap3 = IborSwap(settle_dt,\"3Y\",swap_type,0.0500,fixed_freq,dc_type)\n",
"swap4 = IborSwap(settle_dt,\"4Y\",swap_type,0.0500,fixed_freq,dc_type)\n",
"swap5 = IborSwap(settle_dt,\"5Y\",swap_type,0.0500,fixed_freq,dc_type)\n",
"swaps = [swap1, swap2, swap3, swap4, swap5]\n",
"\n",
"libor_curve = IborSingleCurve(value_dt, depos, [], swaps)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@
},
"outputs": [],
"source": [
"dcType = DayCountTypes.ACT_360\n",
"fixedFreq = FrequencyTypes.SEMI_ANNUAL\n",
"dc_type = DayCountTypes.ACT_360\n",
"fixed_freq = FrequencyTypes.SEMI_ANNUAL\n",
"swap_type = SwapTypes.PAY\n",
"swap1 = IborSwap(settle_dt, Date(1,1,2008), swap_type, 0.05, fixedFreq, dcType)\n",
"swap2 = IborSwap(settle_dt, Date(1,1,2009), swap_type, 0.05, fixedFreq, dcType)\n",
"swap3 = IborSwap(settle_dt, Date(1,1,2010), swap_type, 0.05, fixedFreq, dcType)\n",
"swap1 = IborSwap(settle_dt, Date(1,1,2008), swap_type, 0.05, fixed_freq, dc_type)\n",
"swap2 = IborSwap(settle_dt, Date(1,1,2009), swap_type, 0.05, fixed_freq, dc_type)\n",
"swap3 = IborSwap(settle_dt, Date(1,1,2010), swap_type, 0.05, fixed_freq, dc_type)\n",
"swaps = [swap1, swap2, swap3]\n",
"discount_curve = IborSingleCurve(value_dt, [], [], swaps)"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@
"outputs": [],
"source": [
"rate = 0.10\n",
"dcType = DayCountTypes.THIRTY_360_BOND\n",
"fixedFreq = FrequencyTypes.SEMI_ANNUAL\n",
"discount_curve = DiscountCurveFlat(settle_dt, rate, fixedFreq, dcType)"
"dc_type = DayCountTypes.THIRTY_360_BOND\n",
"fixed_freq = FrequencyTypes.SEMI_ANNUAL\n",
"discount_curve = DiscountCurveFlat(settle_dt, rate, fixed_freq, dc_type)"
]
},
{
Expand Down Expand Up @@ -355,8 +355,8 @@
"outputs": [],
"source": [
"df = discount_curve.df(expiry_dt)\n",
"callIntrinsic = max(cp - strike_price, 0) * df\n",
"putIntrinsic = max(strike_price - cp, 0) * df"
"call_intrinsic = max(cp - strike_price, 0) * df\n",
"put_intrinsic = max(strike_price - cp, 0) * df"
]
},
{
Expand All @@ -383,7 +383,7 @@
}
],
"source": [
"callIntrinsic"
"call_intrinsic"
]
},
{
Expand All @@ -410,7 +410,7 @@
}
],
"source": [
"putIntrinsic"
"put_intrinsic"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@
},
"outputs": [],
"source": [
"dcType = DayCountTypes.THIRTY_360_BOND\n",
"fixedFreq = FrequencyTypes.SEMI_ANNUAL\n",
"dc_type = DayCountTypes.THIRTY_360_BOND\n",
"fixed_freq = FrequencyTypes.SEMI_ANNUAL\n",
"swap_type = SwapTypes.PAY\n",
"swap1 = IborSwap(settle_dt,\"1Y\",swap_type,0.0500,fixedFreq,dcType)\n",
"swap2 = IborSwap(settle_dt,\"3Y\",swap_type,0.0500,fixedFreq,dcType)\n",
"swap3 = IborSwap(settle_dt,\"5Y\",swap_type,0.0500,fixedFreq,dcType)\n",
"swap4 = IborSwap(settle_dt,\"7Y\",swap_type,0.0500,fixedFreq,dcType)\n",
"swap5 = IborSwap(settle_dt,\"10Y\",swap_type,0.0500,fixedFreq,dcType)\n",
"swap1 = IborSwap(settle_dt,\"1Y\",swap_type,0.0500,fixed_freq,dc_type)\n",
"swap2 = IborSwap(settle_dt,\"3Y\",swap_type,0.0500,fixed_freq,dc_type)\n",
"swap3 = IborSwap(settle_dt,\"5Y\",swap_type,0.0500,fixed_freq,dc_type)\n",
"swap4 = IborSwap(settle_dt,\"7Y\",swap_type,0.0500,fixed_freq,dc_type)\n",
"swap5 = IborSwap(settle_dt,\"10Y\",swap_type,0.0500,fixed_freq,dc_type)\n",
"swaps = [swap1, swap2, swap3, swap4, swap5]\n",
"\n",
"libor_curve = IborSingleCurve(value_dt, [], [], swaps)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@
"outputs": [],
"source": [
"rate = 0.05\n",
"dcType = DayCountTypes.THIRTY_360_BOND\n",
"fixedFreq = FrequencyTypes.SEMI_ANNUAL\n",
"discount_curve = DiscountCurveFlat(settle_dt, rate, fixedFreq, dcType)"
"dc_type = DayCountTypes.THIRTY_360_BOND\n",
"fixed_freq = FrequencyTypes.SEMI_ANNUAL\n",
"discount_curve = DiscountCurveFlat(settle_dt, rate, fixed_freq, dc_type)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@
"outputs": [],
"source": [
"rate = 0.05\n",
"dcType = DayCountTypes.THIRTY_360_BOND\n",
"fixedFreq = FrequencyTypes.SEMI_ANNUAL\n",
"discount_curve = DiscountCurveFlat(settle_dt, rate, fixedFreq, dcType)"
"dc_type = DayCountTypes.THIRTY_360_BOND\n",
"fixed_freq = FrequencyTypes.SEMI_ANNUAL\n",
"discount_curve = DiscountCurveFlat(settle_dt, rate, fixed_freq, dc_type)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@
"outputs": [],
"source": [
"rate = 0.05\n",
"fixedFreq = FrequencyTypes.ANNUAL\n",
"discount_curve = DiscountCurveFlat(settle_dt, rate, fixedFreq)"
"fixed_freq = FrequencyTypes.ANNUAL\n",
"discount_curve = DiscountCurveFlat(settle_dt, rate, fixed_freq)"
]
},
{
Expand Down Expand Up @@ -333,8 +333,8 @@
},
"outputs": [],
"source": [
"callIntrinsic = max(sp - K, 0)\n",
"putIntrinsic = max(K - sp, 0)"
"call_intrinsic = max(sp - K, 0)\n",
"put_intrinsic = max(K - sp, 0)"
]
},
{
Expand All @@ -359,8 +359,8 @@
}
],
"source": [
"print(\"Call Intrinsic Spot: %9.5f\" % callIntrinsic)\n",
"print(\"Put Intrinsic Spot: %9.5f\" % putIntrinsic)"
"print(\"Call Intrinsic Spot: %9.5f\" % call_intrinsic)\n",
"print(\"Put Intrinsic Spot: %9.5f\" % put_intrinsic)"
]
},
{
Expand All @@ -383,8 +383,8 @@
},
"outputs": [],
"source": [
"callIntrinsicPV = max(fp - K, 0) * df\n",
"putIntrinsicPV = max(K - fp, 0) * df"
"call_intrinsic_pv = max(fp - K, 0) * df\n",
"put_intrinsic_pv = max(K - fp, 0) * df"
]
},
{
Expand All @@ -409,8 +409,8 @@
}
],
"source": [
"print(\"Call Intrinsic Fwd: %9.5f\" % callIntrinsicPV)\n",
"print(\"Put Intrinsic Fwd: %9.5f\" % putIntrinsicPV)"
"print(\"Call Intrinsic Fwd: %9.5f\" % call_intrinsic_pv)\n",
"print(\"Put Intrinsic Fwd: %9.5f\" % put_intrinsic_pv)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@
"outputs": [],
"source": [
"rate = 0.05\n",
"fixedFreq = FrequencyTypes.ANNUAL\n",
"discount_curve = DiscountCurveFlat(settle_dt, rate, fixedFreq)"
"fixed_freq = FrequencyTypes.ANNUAL\n",
"discount_curve = DiscountCurveFlat(settle_dt, rate, fixed_freq)"
]
},
{
Expand Down Expand Up @@ -283,8 +283,8 @@
},
"outputs": [],
"source": [
"callIntrinsic = max(sp - K, 0)\n",
"putIntrinsic = max(K - sp, 0)"
"call_intrinsic = max(sp - K, 0)\n",
"put_intrinsic = max(K - sp, 0)"
]
},
{
Expand All @@ -309,8 +309,8 @@
}
],
"source": [
"print(\"Call Intrinsic Spot: %9.5f\" % callIntrinsic)\n",
"print(\"Put Intrinsic Spot: %9.5f\" % putIntrinsic)"
"print(\"Call Intrinsic Spot: %9.5f\" % call_intrinsic)\n",
"print(\"Put Intrinsic Spot: %9.5f\" % put_intrinsic)"
]
},
{
Expand All @@ -333,8 +333,8 @@
},
"outputs": [],
"source": [
"callIntrinsicPV = max(fp - K, 0) * df\n",
"putIntrinsicPV = max(K - fp, 0) * df"
"call_intrinsic_pv = max(fp - K, 0) * df\n",
"put_intrinsic_pv = max(K - fp, 0) * df"
]
},
{
Expand All @@ -359,8 +359,8 @@
}
],
"source": [
"print(\"Call Intrinsic Fwd: %9.5f\" % callIntrinsicPV)\n",
"print(\"Put Intrinsic Fwd: %9.5f\" % putIntrinsicPV)"
"print(\"Call Intrinsic Fwd: %9.5f\" % call_intrinsic_pv)\n",
"print(\"Put Intrinsic Fwd: %9.5f\" % put_intrinsic_pv)"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
},
"outputs": [],
"source": [
"bondDataFrame = pd.read_csv('./data/giltbondprices.txt', sep='\\t')"
"bond_dataframe = pd.read_csv('./data/giltbondprices.txt', sep='\\t')"
]
},
{
Expand All @@ -112,7 +112,7 @@
},
"outputs": [],
"source": [
"bondDataFrame['mid'] = 0.5*(bondDataFrame['bid'] + bondDataFrame['ask'])"
"bond_dataframe['mid'] = 0.5*(bond_dataframe['bid'] + bond_dataframe['ask'])"
]
},
{
Expand Down Expand Up @@ -194,7 +194,7 @@
},
"outputs": [],
"source": [
"for index, bond in bondDataFrame.iterrows():\n",
"for index, bond in bond_dataframe.iterrows():\n",
"\n",
" date_string = bond['maturity']\n",
" mat_date_time = dt.datetime.strptime(date_string, '%d-%b-%y')\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
},
"outputs": [],
"source": [
"bondDataFrame = pd.read_csv('./data/giltbondprices.txt', sep='\\t')"
"bond_dataframe = pd.read_csv('./data/giltbondprices.txt', sep='\\t')"
]
},
{
Expand All @@ -99,7 +99,7 @@
"outputs": [],
"source": [
"# CALCULATE MID MARKET PRICES\n",
"bondDataFrame['mid'] = 0.5*(bondDataFrame['bid'] + bondDataFrame['ask'])"
"bond_dataframe['mid'] = 0.5*(bond_dataframe['bid'] + bond_dataframe['ask'])"
]
},
{
Expand Down Expand Up @@ -139,7 +139,7 @@
"\n",
"# LOAD BONDS AND CREATE A VECTOR OF FINBOND AND THEIR CORRESPONDING YIELDS\n",
"\n",
"for index, bondData in bondDataFrame.iterrows():\n",
"for index, bondData in bond_dataframe.iterrows():\n",
"\n",
" date_string = bondData['maturity']\n",
" mat_dt_time = dt.datetime.strptime(date_string, '%d-%b-%y')\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
},
"outputs": [],
"source": [
"bondDataFrame = pd.read_csv('./data/giltbondprices.txt', sep='\\t')"
"bond_dataframe = pd.read_csv('./data/giltbondprices.txt', sep='\\t')"
]
},
{
Expand All @@ -112,7 +112,7 @@
},
"outputs": [],
"source": [
"bondDataFrame['mid'] = 0.5*(bondDataFrame['bid'] + bondDataFrame['ask'])"
"bond_dataframe['mid'] = 0.5*(bond_dataframe['bid'] + bond_dataframe['ask'])"
]
},
{
Expand Down Expand Up @@ -222,7 +222,7 @@
},
"outputs": [],
"source": [
"for index, bondRow in bondDataFrame.iterrows():\n",
"for index, bondRow in bond_dataframe.iterrows():\n",
"\n",
" date_string = bondRow['maturity']\n",
" mat_dt_time = dt.datetime.strptime(date_string, '%d-%b-%y')\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@
"metadata": {},
"outputs": [],
"source": [
"dcType = DayCountTypes.THIRTY_E_360_ISDA\n",
"fixedFreq = FrequencyTypes.SEMI_ANNUAL\n",
"dc_type = DayCountTypes.THIRTY_E_360_ISDA\n",
"fixed_freq = FrequencyTypes.SEMI_ANNUAL\n",
"swap_type = SwapTypes.PAY\n",
"depo = IborDeposit(settle_dt, \"1D\", 0.0502, dcType)\n",
"depo = IborDeposit(settle_dt, \"1D\", 0.0502, dc_type)\n",
"depos = [depo]\n",
"swap1 = IborSwap(settle_dt,\"1Y\",swap_type,0.0502,fixedFreq,dcType)\n",
"swap2 = IborSwap(settle_dt,\"2Y\",swap_type,0.0502,fixedFreq,dcType)\n",
"swap3 = IborSwap(settle_dt,\"3Y\",swap_type,0.0501,fixedFreq,dcType)\n",
"swap4 = IborSwap(settle_dt,\"4Y\",swap_type,0.0502,fixedFreq,dcType)\n",
"swap5 = IborSwap(settle_dt,\"5Y\",swap_type,0.0501,fixedFreq,dcType)\n",
"swap1 = IborSwap(settle_dt,\"1Y\",swap_type,0.0502,fixed_freq,dc_type)\n",
"swap2 = IborSwap(settle_dt,\"2Y\",swap_type,0.0502,fixed_freq,dc_type)\n",
"swap3 = IborSwap(settle_dt,\"3Y\",swap_type,0.0501,fixed_freq,dc_type)\n",
"swap4 = IborSwap(settle_dt,\"4Y\",swap_type,0.0502,fixed_freq,dc_type)\n",
"swap5 = IborSwap(settle_dt,\"5Y\",swap_type,0.0501,fixed_freq,dc_type)\n",
"swaps = [swap1,swap2,swap3,swap4,swap5]\n",
"\n",
"libor_curve = IborSingleCurve(value_dt, depos, [], swaps)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,27 @@
},
"outputs": [],
"source": [
"dcType = DayCountTypes.ACT_360\n",
"depo1 = IborDeposit(settle_dt, \"1M\", 0.022009, dcType)\n",
"depo2 = IborDeposit(settle_dt, \"2M\", 0.022138, dcType)\n",
"depo3 = IborDeposit(settle_dt, \"3M\", 0.021810, dcType)\n",
"depo4 = IborDeposit(settle_dt, \"6M\", 0.020503, dcType)\n",
"depo5 = IborDeposit(settle_dt, \"12M\", 0.019930, dcType)\n",
"dc_type = DayCountTypes.ACT_360\n",
"depo1 = IborDeposit(settle_dt, \"1M\", 0.022009, dc_type)\n",
"depo2 = IborDeposit(settle_dt, \"2M\", 0.022138, dc_type)\n",
"depo3 = IborDeposit(settle_dt, \"3M\", 0.021810, dc_type)\n",
"depo4 = IborDeposit(settle_dt, \"6M\", 0.020503, dc_type)\n",
"depo5 = IborDeposit(settle_dt, \"12M\", 0.019930, dc_type)\n",
"depos = [depo1,depo2,depo3,depo4,depo5]\n",
"\n",
"swap_type = SwapTypes.PAY\n",
"dcType = DayCountTypes.THIRTY_E_360_ISDA\n",
"fixedFreq = FrequencyTypes.SEMI_ANNUAL\n",
"swap1 = IborSwap(settle_dt,\"2Y\",swap_type,0.015910,fixedFreq,dcType)\n",
"swap2 = IborSwap(settle_dt,\"3Y\",swap_type,0.014990,fixedFreq,dcType)\n",
"swap3 = IborSwap(settle_dt,\"4Y\",swap_type,0.014725,fixedFreq,dcType)\n",
"swap4 = IborSwap(settle_dt,\"5Y\",swap_type,0.014640,fixedFreq,dcType)\n",
"swap5 = IborSwap(settle_dt,\"6Y\",swap_type,0.014800,fixedFreq,dcType)\n",
"swap6 = IborSwap(settle_dt,\"7Y\",swap_type,0.014995,fixedFreq,dcType)\n",
"swap7 = IborSwap(settle_dt,\"8Y\",swap_type,0.015180,fixedFreq,dcType)\n",
"swap8 = IborSwap(settle_dt,\"9Y\",swap_type,0.015610,fixedFreq,dcType)\n",
"swap9 = IborSwap(settle_dt,\"10Y\",swap_type,0.0159880,fixedFreq,dcType)\n",
"swap10 = IborSwap(settle_dt,\"12Y\",swap_type,0.016430,fixedFreq,dcType)\n",
"dc_type = DayCountTypes.THIRTY_E_360_ISDA\n",
"fixed_freq = FrequencyTypes.SEMI_ANNUAL\n",
"swap1 = IborSwap(settle_dt,\"2Y\",swap_type,0.015910,fixed_freq,dc_type)\n",
"swap2 = IborSwap(settle_dt,\"3Y\",swap_type,0.014990,fixed_freq,dc_type)\n",
"swap3 = IborSwap(settle_dt,\"4Y\",swap_type,0.014725,fixed_freq,dc_type)\n",
"swap4 = IborSwap(settle_dt,\"5Y\",swap_type,0.014640,fixed_freq,dc_type)\n",
"swap5 = IborSwap(settle_dt,\"6Y\",swap_type,0.014800,fixed_freq,dc_type)\n",
"swap6 = IborSwap(settle_dt,\"7Y\",swap_type,0.014995,fixed_freq,dc_type)\n",
"swap7 = IborSwap(settle_dt,\"8Y\",swap_type,0.015180,fixed_freq,dc_type)\n",
"swap8 = IborSwap(settle_dt,\"9Y\",swap_type,0.015610,fixed_freq,dc_type)\n",
"swap9 = IborSwap(settle_dt,\"10Y\",swap_type,0.0159880,fixed_freq,dc_type)\n",
"swap10 = IborSwap(settle_dt,\"12Y\",swap_type,0.016430,fixed_freq,dc_type)\n",
"swaps = [swap1,swap2,swap3,swap4,swap5,swap6,swap7,swap8,swap9,swap10]\n",
"\n",
"libor_curve = IborSingleCurve(value_dt, depos, [], swaps)"
Expand Down
Loading

0 comments on commit 80032d7

Please sign in to comment.