financial_formulas¶
shortfx.fxExcel.financial_formulas
¶
Excel Financial Functions Module.
This module provides Excel-compatible financial functions for shortfx. Functions include: - Depreciation: SLN, DDB - Bond/Coupon calculations: COUPDAYS, COUPDAYBS, COUPDAYSNC, COUPPCD, COUPNCD, COUPNUM - Duration: DURATION, MDURATION - Accrued interest: ACCRINT, ACCRINTM - Pricing: PRICE, PRICEDISC, PRICEMAT - Yield: YIELD, YIELDDISC, YIELDMAT - Cash flows: XIRR, XNPV - Loan payments: CUMPRINC, PPMT
All functions follow Excel naming conventions and behavior.
Functions¶
ACCRINT(issue: datetime, first_interest: datetime, settlement: datetime, rate: float, par: Union[int, float], frequency: int, basis: int = 0) -> float
¶
Return the accrued interest for a security that pays periodic interest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
issue
|
datetime
|
Issue date. |
required |
first_interest
|
datetime
|
First interest date. |
required |
settlement
|
datetime
|
Settlement date. |
required |
rate
|
float
|
Annual coupon rate. |
required |
par
|
Union[int, float]
|
Par value of the security. |
required |
frequency
|
int
|
Number of coupon payments per year (1, 2, or 4). |
required |
basis
|
int
|
Day count basis (0=30/360, 1=actual/actual). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Accrued interest. |
Example
from datetime import datetime ACCRINT(datetime(2025, 1, 1), datetime(2025, 7, 1), datetime(2025, 4, 1), 0.08, 1000, 2) 20.0
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
ACCRINTM(issue: datetime, settlement: datetime, rate: float, par: Union[int, float], basis: int = 0) -> float
¶
Return the accrued interest for a security that pays interest at maturity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
issue
|
datetime
|
Issue date. |
required |
settlement
|
datetime
|
Maturity date. |
required |
rate
|
float
|
Annual coupon rate. |
required |
par
|
Union[int, float]
|
Par value of the security. |
required |
basis
|
int
|
Day count basis (0=30/360, 1=actual/actual). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Accrued interest. |
Example
from datetime import datetime ACCRINTM(datetime(2025, 1, 1), datetime(2025, 12, 31), 0.08, 1000) 80.0
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
AMORDEGRC(cost, date_purchased, first_period, salvage, period, rate, basis=0)
¶
Calculate depreciation for each accounting period using a depreciation coefficient.
Description: Returns the depreciation for each accounting period. This function is provided for the French accounting system. A depreciation coefficient is applied depending on the asset life.
Args: cost (float): The cost of the asset. date_purchased (datetime.date): The date of the purchase of the asset. first_period (datetime.date): The date of the end of the first period. salvage (float): The salvage value at the end of the life of the asset. period (int): The period for which to calculate depreciation. rate (float): The rate of depreciation. basis (int, optional): The type of day count basis to use (0-4). Default is 0.
Returns: float: The depreciation for the specified period.
Raises: ValueError: If parameters are invalid.
Usage Example: >>> from datetime import date >>> AMORDEGRC(2400, date(2008, 8, 19), date(2008, 12, 31), 300, 1, 0.15) 776.0
Cost: O(n) where n is the period number
Source code in shortfx/fxExcel/financial_formulas.py
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 | |
AMORLINC(cost, date_purchased, first_period, salvage, period, rate, basis=0)
¶
Calculate depreciation for each accounting period using a depreciation coefficient.
Description: Returns the depreciation for each accounting period. This function is provided for the French accounting system. If an asset is purchased in the middle of the accounting period, the prorated depreciation is taken into account.
Args: cost (float): The cost of the asset. date_purchased (datetime.date): The date of the purchase of the asset. first_period (datetime.date): The date of the end of the first period. salvage (float): The salvage value at the end of the life of the asset. period (int): The period for which to calculate depreciation. rate (float): The rate of depreciation. basis (int, optional): The type of day count basis to use (0-4). Default is 0.
Returns: float: The depreciation for the specified period.
Raises: ValueError: If parameters are invalid.
Usage Example: >>> from datetime import date >>> AMORLINC(2400, date(2008, 8, 19), date(2008, 12, 31), 300, 1, 0.15) 360.0
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
COUPDAYBS(settlement: datetime, maturity: datetime, frequency: int) -> int
¶
Return the number of days from the beginning of the coupon period to the settlement date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settlement
|
datetime
|
Settlement date. |
required |
maturity
|
datetime
|
Maturity date. |
required |
frequency
|
int
|
Number of coupon payments per year (1, 2, or 4). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of days from period start to settlement. |
Example
from datetime import datetime COUPDAYBS(datetime(2025, 1, 25), datetime(2026, 11, 15), 2) 71
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
COUPDAYS(settlement: datetime, maturity: datetime, frequency: int) -> int
¶
Return the number of days in the coupon period containing the settlement date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settlement
|
datetime
|
Settlement date. |
required |
maturity
|
datetime
|
Maturity date. |
required |
frequency
|
int
|
Number of coupon payments per year (1, 2, or 4). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of days in the coupon period. |
Example
from datetime import datetime COUPDAYS(datetime(2025, 1, 25), datetime(2026, 11, 15), 2) 181
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
COUPDAYSNC(settlement: datetime, maturity: datetime, frequency: int) -> int
¶
Return the number of days from the settlement date to the next coupon date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settlement
|
datetime
|
Settlement date. |
required |
maturity
|
datetime
|
Maturity date. |
required |
frequency
|
int
|
Number of coupon payments per year (1, 2, or 4). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of days from settlement to next coupon. |
Example
from datetime import datetime COUPDAYSNC(datetime(2025, 1, 25), datetime(2026, 11, 15), 2) 110
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
COUPNCD(settlement: datetime, maturity: datetime, frequency: int) -> datetime
¶
Return the next coupon date after the settlement date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settlement
|
datetime
|
Settlement date. |
required |
maturity
|
datetime
|
Maturity date. |
required |
frequency
|
int
|
Number of coupon payments per year (1, 2, or 4). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
datetime |
datetime
|
Next coupon date. |
Example
from datetime import datetime COUPNCD(datetime(2025, 1, 25), datetime(2026, 11, 15), 2) datetime(2025, 5, 15, 0, 0)
Cost: O(k) where k is the number of coupons from maturity to settlement.
Source code in shortfx/fxExcel/financial_formulas.py
COUPNUM(settlement: datetime, maturity: datetime, frequency: int) -> int
¶
Return the number of coupons payable between settlement and maturity dates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settlement
|
datetime
|
Settlement date. |
required |
maturity
|
datetime
|
Maturity date. |
required |
frequency
|
int
|
Number of coupon payments per year (1, 2, or 4). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of coupons remaining. |
Example
from datetime import datetime COUPNUM(datetime(2025, 1, 25), datetime(2026, 11, 15), 2) 4
Cost: O(n) where n is the number of remaining coupons.
Source code in shortfx/fxExcel/financial_formulas.py
COUPPCD(settlement: datetime, maturity: datetime, frequency: int) -> datetime
¶
Return the previous coupon date before the settlement date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settlement
|
datetime
|
Settlement date. |
required |
maturity
|
datetime
|
Maturity date. |
required |
frequency
|
int
|
Number of coupon payments per year (1, 2, or 4). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
datetime |
datetime
|
Previous coupon date. |
Example
from datetime import datetime COUPPCD(datetime(2025, 1, 25), datetime(2026, 11, 15), 2) datetime(2024, 11, 15, 0, 0)
Cost: O(k) where k is the number of coupons from maturity to settlement.
Source code in shortfx/fxExcel/financial_formulas.py
CUMIPMT(rate: float, nper: int, pv: Union[int, float], start_period: int, end_period: int, type: int) -> float
¶
Calculate cumulative interest paid between two periods.
Description
Returns the cumulative interest paid on a loan between start_period and end_period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
Interest rate. |
required |
nper
|
int
|
Total number of payment periods. |
required |
pv
|
Union[int, float]
|
Present value. |
required |
start_period
|
int
|
First period in the calculation (1-based). |
required |
end_period
|
int
|
Last period in the calculation. |
required |
type
|
int
|
When payments are due (0 = end of period, 1 = beginning of period). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Cumulative interest paid. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If start_period < 1, end_period < start_period, or end_period > nper. |
Usage Example
CUMIPMT(0.09/12, 30*12, 125000, 1, 12, 0) -11135.232905681283
Cost: O(n) where n is (end_period - start_period + 1).
Source code in shortfx/fxExcel/financial_formulas.py
CUMPRINC(rate: float, nper: int, pv: Union[int, float], start_period: int, end_period: int, type: int = 0) -> float
¶
Return the cumulative principal paid on a loan between two periods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
Interest rate per period. |
required |
nper
|
int
|
Total number of payment periods. |
required |
pv
|
Union[int, float]
|
Present value (loan amount). |
required |
start_period
|
int
|
First period in the calculation (1-based). |
required |
end_period
|
int
|
Last period in the calculation. |
required |
type
|
int
|
Payment timing (0=end of period, 1=beginning of period). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Cumulative principal paid. |
Example
CUMPRINC(0.09/12, 30*12, 125000, 1, 12, 0) -934.11
Cost: O(n) where n is the number of periods.
Source code in shortfx/fxExcel/financial_formulas.py
DB(cost: Union[int, float], salvage: Union[int, float], life: int, period: int, month: int = 12) -> float
¶
Calculate depreciation using the fixed-declining balance method.
Description
Returns the depreciation of an asset for a specified period using the fixed-declining balance method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cost
|
Union[int, float]
|
Initial cost of the asset. |
required |
salvage
|
Union[int, float]
|
Value at the end of the depreciation. |
required |
life
|
int
|
Number of periods over which the asset is depreciated. |
required |
period
|
int
|
Period for which to calculate depreciation. |
required |
month
|
int
|
Number of months in the first year (default 12). |
12
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Depreciation for the specified period. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If period is not between 1 and life, or month not between 1 and 12. |
Usage Example
DB(1000000, 100000, 6, 1, 7) 186083.33333333334
Cost: O(n) where n is the period number.
Source code in shortfx/fxExcel/financial_formulas.py
DDB(cost: Union[int, float], salvage: Union[int, float], life: Union[int, float], period: int, factor: Union[int, float] = 2) -> float
¶
Calculate depreciation using the double-declining balance method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cost
|
Union[int, float]
|
Initial cost of the asset. |
required |
salvage
|
Union[int, float]
|
Salvage value at the end of useful life. |
required |
life
|
Union[int, float]
|
Number of periods over which the asset is depreciated. |
required |
period
|
int
|
Period for which to calculate depreciation. |
required |
factor
|
Union[int, float]
|
Rate at which the balance declines (default 2 for double-declining). |
2
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Depreciation for the specified period. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If period is not between 1 and life. |
Example
DDB(2400, 300, 10, 1) 480.0
Cost: O(n) where n is the period number.
Source code in shortfx/fxExcel/financial_formulas.py
DISC(settlement, maturity, pr, redemption, basis=0)
¶
Calculate the discount rate for a security.
Description: Returns the discount rate for a security. The discount rate is the difference between the redemption value and the price, expressed as a percentage of the redemption value.
Args: settlement (datetime.date): The security's settlement date. maturity (datetime.date): The security's maturity date. pr (float): The security's price per $100 face value. redemption (float): The security's redemption value per $100 face value. basis (int, optional): The type of day count basis to use (0-4). Default is 0.
Returns: float: The discount rate.
Raises: ValueError: If settlement >= maturity, or if pr <= 0 or redemption <= 0.
Usage Example: >>> from datetime import date >>> DISC(date(2007, 1, 25), date(2007, 6, 15), 97.975, 100) 0.0520
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
DOLLARDE(fractional_dollar, fraction)
¶
Convert a dollar price expressed as a fraction into a decimal dollar price.
Description: Converts a dollar price expressed as a fraction into a dollar price expressed as a decimal number. This is useful for converting bond prices.
Args: fractional_dollar (float): A number expressed as an integer part and a fraction part. fraction (int): The integer to use as the denominator of the fraction.
Returns: float: The dollar price as a decimal number.
Raises: ValueError: If fraction < 1.
Usage Example: >>> DOLLARDE(1.02, 16) 1.125 >>> DOLLARDE(1.1, 32) 1.3125
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
DOLLARFR(decimal_dollar, fraction)
¶
Convert a decimal dollar price into a fractional dollar price.
Description: Converts a dollar price expressed as a decimal number into a dollar price expressed as a fraction. This is useful for converting bond prices.
Args: decimal_dollar (float): A decimal number. fraction (int): The integer to use as the denominator of the fraction.
Returns: float: The dollar price as a fraction.
Raises: ValueError: If fraction < 1.
Usage Example: >>> DOLLARFR(1.125, 16) 1.02 >>> DOLLARFR(1.3125, 32) 1.1
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
DURATION(settlement: datetime, maturity: datetime, coupon: float, yld: float, frequency: int, basis: int = 0) -> float
¶
Return the Macaulay duration for an assumed par value of 100.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settlement
|
datetime
|
Settlement date. |
required |
maturity
|
datetime
|
Maturity date. |
required |
coupon
|
float
|
Annual coupon rate. |
required |
yld
|
float
|
Annual yield. |
required |
frequency
|
int
|
Number of coupon payments per year (1, 2, or 4). |
required |
basis
|
int
|
Day count basis (0=30/360, 1=actual/actual). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Macaulay duration. |
Example
from datetime import datetime DURATION(datetime(2025, 1, 1), datetime(2030, 1, 1), 0.08, 0.09, 2) 4.2
Cost: O(n) where n is the number of coupons.
Source code in shortfx/fxExcel/financial_formulas.py
EFFECT(nominal_rate: float, npery: int) -> float
¶
Calculate the effective annual interest rate.
Description
Returns the effective annual interest rate, given the nominal annual interest rate and the number of compounding periods per year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nominal_rate
|
float
|
Nominal interest rate. |
required |
npery
|
int
|
Number of compounding periods per year. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Effective annual interest rate. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If nominal_rate < 0 or npery < 1. |
Usage Example
EFFECT(0.0525, 4) 0.053543247176560884
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
FV(rate: float, nper: int, pmt: Union[int, float], pv: Union[int, float] = 0, type: int = 0) -> float
¶
Calculate the future value of an investment.
Description
Returns the future value of an investment based on periodic, constant payments and a constant interest rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
Interest rate per period. |
required |
nper
|
int
|
Total number of payment periods. |
required |
pmt
|
Union[int, float]
|
Payment made each period (cannot change over the life of the investment). |
required |
pv
|
Union[int, float]
|
Present value, or the lump-sum amount that a series of future payments is worth now (default 0). |
0
|
type
|
int
|
When payments are due (0 = end of period, 1 = beginning of period). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Future value of the investment. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If nper is negative. |
Usage Example
FV(0.06/12, 10, -200, -500, 1) 2581.40 FV(0.12/12, 12, -1000) 12682.50
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
FVSCHEDULE(principal: Union[int, float], schedule: List[float]) -> float
¶
Calculate future value with a variable interest rate schedule.
Description
Returns the future value of an initial principal after applying a series of compound interest rates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
principal
|
Union[int, float]
|
Present value. |
required |
schedule
|
List[float]
|
Array of interest rates to apply. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Future value after applying all interest rates. |
Usage Example
FVSCHEDULE(1, [0.09, 0.11, 0.10]) 1.3308900000000001
Cost: O(n) where n is the number of rates in schedule.
Source code in shortfx/fxExcel/financial_formulas.py
INTRATE(settlement, maturity, investment, redemption, basis=0)
¶
Calculate the interest rate for a fully invested security.
Description: Returns the interest rate for a fully invested security. This is the interest rate earned on a security that is purchased and held to maturity.
Args: settlement (datetime.date): The security's settlement date. maturity (datetime.date): The security's maturity date. investment (float): The amount invested in the security. redemption (float): The amount to be received at maturity. basis (int, optional): The type of day count basis to use (0-4). Default is 0.
Returns: float: The interest rate.
Raises: ValueError: If settlement >= maturity, or if investment <= 0 or redemption <= 0.
Usage Example: >>> from datetime import date >>> INTRATE(date(2008, 2, 15), date(2008, 5, 15), 1000000, 1014420) 0.0578
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
IPMT(rate: float, per: int, nper: int, pv: Union[int, float], fv: Union[int, float] = 0, type: int = 0) -> float
¶
Calculate the interest payment for a given period.
Description
Returns the interest payment for a given period for an investment based on periodic, constant payments and a constant interest rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
Interest rate per period. |
required |
per
|
int
|
Period for which you want to find the interest (must be between 1 and nper). |
required |
nper
|
int
|
Total number of payment periods. |
required |
pv
|
Union[int, float]
|
Present value. |
required |
fv
|
Union[int, float]
|
Future value (default 0). |
0
|
type
|
int
|
When payments are due (0 = end of period, 1 = beginning of period). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Interest payment for the period. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If per is not between 1 and nper. |
Usage Example
IPMT(0.1/12, 1, 3*12, 8000) -66.66666666666667
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
IRR(values: List[Union[int, float]], guess: float = 0.1) -> float
¶
Calculate the internal rate of return for a series of cash flows.
Description
Returns the internal rate of return for a series of cash flows represented by the numbers in values. These cash flows do not have to be even, but they must occur at regular intervals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
List[Union[int, float]]
|
Array of cash flows. Must contain at least one positive and one negative value. |
required |
guess
|
float
|
Estimate for what the rate will be (default 0.1). |
0.1
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Internal rate of return. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values do not contain at least one positive and one negative value. |
Usage Example
IRR([-70000, 12000, 15000, 18000, 21000, 26000]) 0.0866309480589569
Cost: O(n*m) where n is iterations and m is the number of cash flows.
Source code in shortfx/fxExcel/financial_formulas.py
ISPMT(rate, per, nper, pv)
¶
Calculate the interest paid during a specific period of an investment.
Description: Calculates the interest paid (or received) for a specified period of a loan (or investment) with even principal payments. This function is used for calculating the interest portion of a payment when principal is paid evenly.
Args: rate (float): The interest rate per period. per (int): The period for which to find the interest (must be between 1 and nper). nper (int): The total number of payment periods. pv (float): The present value or principal.
Returns: float: The interest paid during the period.
Usage Example: >>> ISPMT(0.1/12, 1, 3*12, 8000000) -66666.67
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
MDURATION(settlement: datetime, maturity: datetime, coupon: float, yld: float, frequency: int, basis: int = 0) -> float
¶
Return the modified duration for an assumed par value of 100.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settlement
|
datetime
|
Settlement date. |
required |
maturity
|
datetime
|
Maturity date. |
required |
coupon
|
float
|
Annual coupon rate. |
required |
yld
|
float
|
Annual yield. |
required |
frequency
|
int
|
Number of coupon payments per year (1, 2, or 4). |
required |
basis
|
int
|
Day count basis (0=30/360, 1=actual/actual). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Modified duration. |
Example
from datetime import datetime MDURATION(datetime(2025, 1, 1), datetime(2030, 1, 1), 0.08, 0.09, 2) 4.0
Cost: O(n) where n is the number of coupons.
Source code in shortfx/fxExcel/financial_formulas.py
MIRR(values: List[Union[int, float]], finance_rate: float, reinvest_rate: float) -> float
¶
Calculate the modified internal rate of return.
Description
Returns the modified internal rate of return for a series of periodic cash flows. MIRR considers both the cost of the investment and the interest received on reinvestment of cash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
List[Union[int, float]]
|
Array of cash flows. |
required |
finance_rate
|
float
|
Interest rate paid on money used in cash flows. |
required |
reinvest_rate
|
float
|
Interest rate received on cash flows as they are reinvested. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Modified internal rate of return. |
Usage Example
MIRR([-120000, 39000, 30000, 21000, 37000, 46000], 0.10, 0.12) 0.1260941303659051
Cost: O(n) where n is the number of cash flows.
Source code in shortfx/fxExcel/financial_formulas.py
NOMINAL(effect_rate: float, npery: int) -> float
¶
Calculate the nominal annual interest rate.
Description
Returns the nominal annual interest rate, given the effective rate and the number of compounding periods per year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
effect_rate
|
float
|
Effective interest rate. |
required |
npery
|
int
|
Number of compounding periods per year. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Nominal annual interest rate. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If effect_rate < 0 or npery < 1. |
Usage Example
NOMINAL(0.053543, 4) 0.0525000113314875
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
NPER(rate: float, pmt: Union[int, float], pv: Union[int, float], fv: Union[int, float] = 0, type: int = 0) -> float
¶
Calculate the number of periods for an investment.
Description
Returns the number of periods for an investment based on periodic, constant payments and a constant interest rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
Interest rate per period. |
required |
pmt
|
Union[int, float]
|
Payment made each period (cannot change). |
required |
pv
|
Union[int, float]
|
Present value, or the lump-sum amount. |
required |
fv
|
Union[int, float]
|
Future value, or a cash balance you want after the last payment (default 0). |
0
|
type
|
int
|
When payments are due (0 = end of period, 1 = beginning of period). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Number of periods. |
Usage Example
NPER(0.12/12, -100, -1000, 10000, 1) 59.673865674320484
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
NPV(rate: float, *values: Union[int, float]) -> float
¶
Calculate the net present value of an investment.
Description
Calculates the net present value of an investment by using a discount rate and a series of future payments (negative values) and income (positive values).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
Discount rate over one period. |
required |
*values
|
Union[int, float]
|
Arguments representing the payments and income. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Net present value. |
Usage Example
NPV(0.10, -10000, 3000, 4200, 6800) 1188.4434123352216
Cost: O(n) where n is the number of values.
Source code in shortfx/fxExcel/financial_formulas.py
ODDFPRICE(settlement, maturity, issue, first_coupon, rate, yld, redemption, frequency, basis=0)
¶
Calculate the price per $100 face value of a security with an odd first period.
Description: Returns the price per $100 face value of a security having an odd (short or long) first coupon period. This is used for bonds where the first coupon period differs from the standard period.
Args: settlement (datetime.date): The security's settlement date. maturity (datetime.date): The security's maturity date. issue (datetime.date): The security's issue date. first_coupon (datetime.date): The security's first coupon date. rate (float): The security's annual coupon rate. yld (float): The security's annual yield. redemption (float): The security's redemption value per $100 face value. frequency (int): The number of coupon payments per year (1, 2, or 4). basis (int, optional): The type of day count basis to use (0-4). Default is 0.
Returns: float: The price per $100 face value.
Raises: ValueError: If dates are invalid or parameters are out of range.
Usage Example: >>> from datetime import date >>> ODDFPRICE(date(2008, 11, 11), date(2021, 3, 1), date(2008, 10, 15), ... date(2009, 3, 1), 0.0785, 0.0625, 100, 2) 113.597717
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 | |
ODDFYIELD(settlement, maturity, issue, first_coupon, rate, pr, redemption, frequency, basis=0)
¶
Calculate the yield of a security with an odd first period.
Description: Returns the yield of a security that has an odd (short or long) first period. This function uses iterative methods to find the yield that matches the price.
Args: settlement (datetime.date): The security's settlement date. maturity (datetime.date): The security's maturity date. issue (datetime.date): The security's issue date. first_coupon (datetime.date): The security's first coupon date. rate (float): The security's annual coupon rate. pr (float): The security's price per $100 face value. redemption (float): The security's redemption value per $100 face value. frequency (int): The number of coupon payments per year (1, 2, or 4). basis (int, optional): The type of day count basis to use (0-4). Default is 0.
Returns: float: The yield.
Raises: ValueError: If dates are invalid or parameters are out of range.
Usage Example: >>> from datetime import date >>> ODDFYIELD(date(2008, 11, 11), date(2021, 3, 1), date(2008, 10, 15), ... date(2009, 3, 1), 0.0785, 113.597717, 100, 2) 0.0625
Cost: O(n) where n is iterations to converge (typically < 100)
Source code in shortfx/fxExcel/financial_formulas.py
1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 | |
ODDLPRICE(settlement, maturity, last_interest, rate, yld, redemption, frequency, basis=0)
¶
Calculate the price per $100 face value of a security with an odd last period.
Description: Returns the price per $100 face value of a security having an odd (short or long) last coupon period.
Args: settlement (datetime.date): The security's settlement date. maturity (datetime.date): The security's maturity date. last_interest (datetime.date): The security's last coupon date. rate (float): The security's annual coupon rate. yld (float): The security's annual yield. redemption (float): The security's redemption value per $100 face value. frequency (int): The number of coupon payments per year (1, 2, or 4). basis (int, optional): The type of day count basis to use (0-4). Default is 0.
Returns: float: The price per $100 face value.
Raises: ValueError: If dates are invalid or parameters are out of range.
Usage Example: >>> from datetime import date >>> ODDLPRICE(date(2008, 2, 7), date(2008, 6, 15), date(2007, 10, 15), ... 0.0375, 0.0405, 100, 2) 99.878456
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 | |
ODDLYIELD(settlement, maturity, last_interest, rate, pr, redemption, frequency, basis=0)
¶
Calculate the yield of a security with an odd last period.
Description: Returns the yield of a security that has an odd (short or long) last period. This function uses iterative methods to find the yield that matches the price.
Args: settlement (datetime.date): The security's settlement date. maturity (datetime.date): The security's maturity date. last_interest (datetime.date): The security's last coupon date. rate (float): The security's annual coupon rate. pr (float): The security's price per $100 face value. redemption (float): The security's redemption value per $100 face value. frequency (int): The number of coupon payments per year (1, 2, or 4). basis (int, optional): The type of day count basis to use (0-4). Default is 0.
Returns: float: The yield.
Raises: ValueError: If dates are invalid or parameters are out of range.
Usage Example: >>> from datetime import date >>> ODDLYIELD(date(2008, 2, 7), date(2008, 6, 15), date(2007, 10, 15), ... 0.0375, 99.878456, 100, 2) 0.0405
Cost: O(n) where n is iterations to converge (typically < 100)
Source code in shortfx/fxExcel/financial_formulas.py
1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 | |
PDURATION(rate: float, pv: Union[int, float], fv: Union[int, float]) -> float
¶
Calculate the number of periods required for an investment to reach a specified value.
Description
Returns the number of periods required by an investment to reach a specified value at a constant interest rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
Interest rate per period. |
required |
pv
|
Union[int, float]
|
Present value of the investment. |
required |
fv
|
Union[int, float]
|
Future value of the investment. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Number of periods. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If rate <= 0, pv <= 0, or fv <= 0. |
Usage Example
PDURATION(0.025, 2000, 2200) 3.8654790948275353
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
PMT(rate: float, nper: int, pv: Union[int, float], fv: Union[int, float] = 0, type: int = 0) -> float
¶
Calculate the payment for a loan.
Description
Calculates the payment for a loan based on constant payments and a constant interest rate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
Interest rate for the loan. |
required |
nper
|
int
|
Total number of payments for the loan. |
required |
pv
|
Union[int, float]
|
Present value (the total amount that a series of future payments is worth now). |
required |
fv
|
Union[int, float]
|
Future value (cash balance after the last payment, default 0). |
0
|
type
|
int
|
When payments are due (0 = end of period, 1 = beginning of period). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Payment amount. |
Usage Example
PMT(0.08/12, 10, 10000) -1037.0320893438879
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
PPMT(rate: float, per: int, nper: int, pv: Union[int, float], fv: Union[int, float] = 0, type: int = 0) -> float
¶
Return the principal payment for a given period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
Interest rate per period. |
required |
per
|
int
|
Period for which to calculate payment (1-based). |
required |
nper
|
int
|
Total number of payment periods. |
required |
pv
|
Union[int, float]
|
Present value (loan amount). |
required |
fv
|
Union[int, float]
|
Future value (default 0). |
0
|
type
|
int
|
Payment timing (0=end of period, 1=beginning of period). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Principal payment for the period. |
Example
PPMT(0.08/12, 1, 10*12, 10000) -75.62
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
PRICE(settlement: datetime, maturity: datetime, rate: float, yld: float, redemption: Union[int, float], frequency: int, basis: int = 0) -> float
¶
Return the price per $100 face value of a security that pays periodic interest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settlement
|
datetime
|
Settlement date. |
required |
maturity
|
datetime
|
Maturity date. |
required |
rate
|
float
|
Annual coupon rate. |
required |
yld
|
float
|
Annual yield. |
required |
redemption
|
Union[int, float]
|
Redemption value per $100 face value. |
required |
frequency
|
int
|
Number of coupon payments per year (1, 2, or 4). |
required |
basis
|
int
|
Day count basis (0=30/360, 1=actual/actual). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Price per $100 face value. |
Example
from datetime import datetime PRICE(datetime(2025, 2, 15), datetime(2032, 11, 15), 0.0575, 0.065, 100, 2) 92.89
Cost: O(n) where n is the number of coupons.
Source code in shortfx/fxExcel/financial_formulas.py
PRICEDISC(settlement: datetime, maturity: datetime, discount: float, redemption: Union[int, float], basis: int = 0) -> float
¶
Return the price per $100 face value of a discounted security.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settlement
|
datetime
|
Settlement date. |
required |
maturity
|
datetime
|
Maturity date. |
required |
discount
|
float
|
Security's discount rate. |
required |
redemption
|
Union[int, float]
|
Redemption value per $100 face value. |
required |
basis
|
int
|
Day count basis (0=30/360, 1=actual/actual). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Price per $100 face value. |
Example
from datetime import datetime PRICEDISC(datetime(2025, 2, 16), datetime(2025, 3, 1), 0.0525, 100) 99.79
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
PRICEMAT(settlement: datetime, maturity: datetime, issue: datetime, rate: float, yld: float, basis: int = 0) -> float
¶
Return the price per $100 face value of a security that pays interest at maturity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settlement
|
datetime
|
Settlement date. |
required |
maturity
|
datetime
|
Maturity date. |
required |
issue
|
datetime
|
Issue date. |
required |
rate
|
float
|
Interest rate at date of issue. |
required |
yld
|
float
|
Annual yield. |
required |
basis
|
int
|
Day count basis (0=30/360, 1=actual/actual). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Price per $100 face value. |
Example
from datetime import datetime PRICEMAT(datetime(2025, 2, 15), datetime(2025, 4, 13), datetime(2024, 11, 11), 0.061, 0.061) 99.98
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
PV(rate: float, nper: int, pmt: Union[int, float], fv: Union[int, float] = 0, type: int = 0) -> float
¶
Calculate the present value of an investment.
Description
Returns the present value of an investment: the total amount that a series of future payments is worth now.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
Interest rate per period. |
required |
nper
|
int
|
Total number of payment periods. |
required |
pmt
|
Union[int, float]
|
Payment made each period. |
required |
fv
|
Union[int, float]
|
Future value (cash balance after the last payment, default 0). |
0
|
type
|
int
|
When payments are due (0 = end of period, 1 = beginning of period). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Present value. |
Usage Example
PV(0.08/12, 12*20, 500) -59777.14551580659
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
RATE(nper: int, pmt: Union[int, float], pv: Union[int, float], fv: Union[int, float] = 0, type: int = 0, guess: float = 0.1) -> float
¶
Calculate the interest rate per period of an annuity.
Description
Returns the interest rate per period of an annuity. RATE is calculated by iteration and can have zero or more solutions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nper
|
int
|
Total number of payment periods. |
required |
pmt
|
Union[int, float]
|
Payment made each period. |
required |
pv
|
Union[int, float]
|
Present value. |
required |
fv
|
Union[int, float]
|
Future value (default 0). |
0
|
type
|
int
|
When payments are due (0 = end of period, 1 = beginning of period). |
0
|
guess
|
float
|
Initial guess for the rate (default 0.1). |
0.1
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Interest rate per period. |
Usage Example
RATE(4*12, -200, 8000) 0.0077010094049834785
Cost: O(n) where n is the number of iterations needed for convergence.
Source code in shortfx/fxExcel/financial_formulas.py
RECEIVED(settlement, maturity, investment, discount, basis=0)
¶
Calculate the amount received at maturity for a fully invested security.
Description: Returns the amount received at maturity for a fully invested security. This calculates the redemption value based on the investment and discount rate.
Args: settlement (datetime.date): The security's settlement date. maturity (datetime.date): The security's maturity date. investment (float): The amount invested in the security. discount (float): The security's discount rate. basis (int, optional): The type of day count basis to use (0-4). Default is 0.
Returns: float: The amount received at maturity.
Raises: ValueError: If settlement >= maturity or if investment <= 0.
Usage Example: >>> from datetime import date >>> RECEIVED(date(2008, 2, 15), date(2008, 5, 15), 1000000, 0.0575) 1014584.65
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
RRI(nper: int, pv: Union[int, float], fv: Union[int, float]) -> float
¶
Calculate an equivalent interest rate for the growth of an investment.
Description
Returns an equivalent interest rate for the growth of an investment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nper
|
int
|
Number of periods for the investment. |
required |
pv
|
Union[int, float]
|
Present value of the investment. |
required |
fv
|
Union[int, float]
|
Future value of the investment. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Interest rate. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If nper <= 0 or pv == 0. |
Usage Example
RRI(96, 10000, 11000) 0.0010099828308729896
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
SLN(cost: Union[int, float], salvage: Union[int, float], life: Union[int, float]) -> float
¶
Calculate straight-line depreciation of an asset for one period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cost
|
Union[int, float]
|
Initial cost of the asset. |
required |
salvage
|
Union[int, float]
|
Salvage value at the end of useful life. |
required |
life
|
Union[int, float]
|
Number of periods over which the asset is depreciated. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Straight-line depreciation per period. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If life is zero or negative. |
Example
SLN(30000, 7500, 10) 2250.0
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
SYD(cost: Union[int, float], salvage: Union[int, float], life: int, per: int) -> float
¶
Calculate sum-of-years digits depreciation.
Description
Returns the sum-of-years' digits depreciation of an asset for a specified period.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cost
|
Union[int, float]
|
Initial cost of the asset. |
required |
salvage
|
Union[int, float]
|
Value at the end of depreciation. |
required |
life
|
int
|
Number of periods over which the asset is depreciated. |
required |
per
|
int
|
Period for which to calculate depreciation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Depreciation for the specified period. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If per is not between 1 and life. |
Usage Example
SYD(30000, 7500, 10, 1) 4090.909090909091
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
TBILLEQ(settlement, maturity, discount)
¶
Calculate the bond-equivalent yield for a Treasury bill.
Description: Returns the bond-equivalent yield for a Treasury bill. This converts the discount rate to a bond-equivalent yield for comparison with coupon securities.
Args: settlement (datetime.date): The Treasury bill's settlement date. maturity (datetime.date): The Treasury bill's maturity date. discount (float): The Treasury bill's discount rate.
Returns: float: The bond-equivalent yield.
Raises: ValueError: If settlement >= maturity or if discount <= 0.
Usage Example: >>> from datetime import date >>> TBILLEQ(date(2008, 3, 31), date(2008, 6, 1), 0.0914) 0.0944
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
TBILLPRICE(settlement, maturity, discount)
¶
Calculate the price per $100 face value for a Treasury bill.
Description: Returns the price per $100 face value for a Treasury bill based on the discount rate.
Args: settlement (datetime.date): The Treasury bill's settlement date. maturity (datetime.date): The Treasury bill's maturity date. discount (float): The Treasury bill's discount rate.
Returns: float: The price per $100 face value.
Raises: ValueError: If settlement >= maturity or if discount <= 0.
Usage Example: >>> from datetime import date >>> TBILLPRICE(date(2008, 3, 31), date(2008, 6, 1), 0.09) 98.45
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
TBILLYIELD(settlement, maturity, pr)
¶
Calculate the yield for a Treasury bill.
Description: Returns the yield for a Treasury bill based on its price.
Args: settlement (datetime.date): The Treasury bill's settlement date. maturity (datetime.date): The Treasury bill's maturity date. pr (float): The Treasury bill's price per $100 face value.
Returns: float: The yield.
Raises: ValueError: If settlement >= maturity or if pr <= 0.
Usage Example: >>> from datetime import date >>> TBILLYIELD(date(2008, 3, 31), date(2008, 6, 1), 98.45) 0.0914
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
VDB(cost: Union[int, float], salvage: Union[int, float], life: Union[int, float], start_period: Union[int, float], end_period: Union[int, float], factor: Union[int, float] = 2, no_switch: bool = False) -> float
¶
Calculate depreciation using the double-declining balance or other method.
Description
Returns the depreciation of an asset for any period you specify, including partial periods, using the double-declining balance method or some other method you specify.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cost
|
Union[int, float]
|
Initial cost of the asset. |
required |
salvage
|
Union[int, float]
|
Value at the end of depreciation. |
required |
life
|
Union[int, float]
|
Number of periods over which the asset is depreciated. |
required |
start_period
|
Union[int, float]
|
Starting period for depreciation calculation. |
required |
end_period
|
Union[int, float]
|
Ending period for depreciation calculation. |
required |
factor
|
Union[int, float]
|
Rate at which the balance declines (default 2 for double-declining). |
2
|
no_switch
|
bool
|
If True, don't switch to straight-line depreciation. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Depreciation for the specified period range. |
Usage Example
VDB(2400, 300, 10, 0, 1) 480.0
Cost: O(n) where n is the period range.
Source code in shortfx/fxExcel/financial_formulas.py
XIRR(values: List[Union[int, float]], dates: List[datetime], guess: float = 0.1) -> float
¶
Return the internal rate of return for a schedule of cash flows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
List[Union[int, float]]
|
Series of cash flows. |
required |
dates
|
List[datetime]
|
Schedule of payment dates. |
required |
guess
|
float
|
Initial guess for the rate (default 0.1). |
0.1
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Internal rate of return. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values and dates have different lengths. |
Example
from datetime import datetime values = [-10000, 2750, 4250, 3250, 2750] dates = [datetime(2008, 1, 1), datetime(2008, 3, 1), ... datetime(2008, 10, 30), datetime(2009, 2, 15), datetime(2009, 4, 1)] round(XIRR(values, dates), 4) 0.3733
Cost: O(n*m) where n is iterations and m is the number of cash flows.
Source code in shortfx/fxExcel/financial_formulas.py
XNPV(rate: float, values: List[Union[int, float]], dates: List[datetime]) -> float
¶
Return the net present value for a schedule of cash flows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rate
|
float
|
Discount rate to apply. |
required |
values
|
List[Union[int, float]]
|
Series of cash flows. |
required |
dates
|
List[datetime]
|
Schedule of payment dates. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Net present value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If values and dates have different lengths. |
Example
from datetime import datetime values = [-10000, 2750, 4250, 3250, 2750] dates = [datetime(2008, 1, 1), datetime(2008, 3, 1), ... datetime(2008, 10, 30), datetime(2009, 2, 15), datetime(2009, 4, 1)] round(XNPV(0.09, values, dates), 2) 2086.65
Cost: O(n) where n is the number of cash flows.
Source code in shortfx/fxExcel/financial_formulas.py
YIELD(settlement: datetime, maturity: datetime, rate: float, pr: Union[int, float], redemption: Union[int, float], frequency: int, basis: int = 0) -> float
¶
Return the yield of a security that pays periodic interest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settlement
|
datetime
|
Settlement date. |
required |
maturity
|
datetime
|
Maturity date. |
required |
rate
|
float
|
Annual coupon rate. |
required |
pr
|
Union[int, float]
|
Price per $100 face value. |
required |
redemption
|
Union[int, float]
|
Redemption value per $100 face value. |
required |
frequency
|
int
|
Number of coupon payments per year (1, 2, or 4). |
required |
basis
|
int
|
Day count basis (0=30/360, 1=actual/actual). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Annual yield. |
Example
from datetime import datetime YIELD(datetime(2025, 2, 15), datetime(2032, 11, 15), 0.0575, 95.04, 100, 2) 0.065
Cost: O(n*m) where n is iterations and m is number of coupons.
Source code in shortfx/fxExcel/financial_formulas.py
YIELDDISC(settlement: datetime, maturity: datetime, pr: Union[int, float], redemption: Union[int, float], basis: int = 0) -> float
¶
Return the annual yield for a discounted security.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settlement
|
datetime
|
Settlement date. |
required |
maturity
|
datetime
|
Maturity date. |
required |
pr
|
Union[int, float]
|
Price per $100 face value. |
required |
redemption
|
Union[int, float]
|
Redemption value per $100 face value. |
required |
basis
|
int
|
Day count basis (0=30/360, 1=actual/actual). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Annual yield. |
Example
from datetime import datetime YIELDDISC(datetime(2025, 2, 16), datetime(2025, 3, 1), 99.795, 100) 0.0525
Cost: O(1)
Source code in shortfx/fxExcel/financial_formulas.py
YIELDMAT(settlement: datetime, maturity: datetime, issue: datetime, rate: float, pr: Union[int, float], basis: int = 0) -> float
¶
Return the annual yield of a security that pays interest at maturity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settlement
|
datetime
|
Settlement date. |
required |
maturity
|
datetime
|
Maturity date. |
required |
issue
|
datetime
|
Issue date. |
required |
rate
|
float
|
Interest rate at date of issue. |
required |
pr
|
Union[int, float]
|
Price per $100 face value. |
required |
basis
|
int
|
Day count basis (0=30/360, 1=actual/actual). |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Annual yield. |
Example
from datetime import datetime YIELDMAT(datetime(2025, 3, 15), datetime(2025, 11, 3), datetime(2024, 11, 8), 0.0625, 100.0123) 0.0609
Cost: O(1)