-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9fac8a
commit d99655b
Showing
22 changed files
with
738 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
docs/source/torchquantlib.core.asset_pricing.bond.bond_pricer.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
Bond Pricer | ||
=========== | ||
|
||
.. automodule:: torchquantlib.core.asset_pricing.bond.bond_pricer | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
This module provides implementations for various bond pricing models. | ||
|
||
Zero Coupon Bond | ||
---------------- | ||
|
||
.. autofunction:: torchquantlib.core.asset_pricing.bond.bond_pricer.zero_coupon_bond | ||
|
||
Usage Example | ||
^^^^^^^^^^^^^ | ||
|
||
.. code-block:: python | ||
import torch | ||
from torchquantlib.core.asset_pricing.bond.bond_pricer import zero_coupon_bond | ||
face_value = torch.tensor(1000.0) | ||
rate = torch.tensor(0.05) | ||
maturity = torch.tensor(5.0) | ||
price = zero_coupon_bond(face_value, rate, maturity) | ||
print(f"Zero Coupon Bond Price: {price.item():.2f}") | ||
Coupon Bond | ||
----------- | ||
|
||
.. autofunction:: torchquantlib.core.asset_pricing.bond.bond_pricer.coupon_bond | ||
|
||
Usage Example | ||
^^^^^^^^^^^^^ | ||
|
||
.. code-block:: python | ||
from torchquantlib.core.asset_pricing.bond.bond_pricer import coupon_bond | ||
face_value = torch.tensor(1000.0) | ||
coupon_rate = torch.tensor(0.06) | ||
rate = torch.tensor(0.05) | ||
periods = torch.tensor(10) | ||
price = coupon_bond(face_value, coupon_rate, rate, periods) | ||
print(f"Coupon Bond Price: {price.item():.2f}") | ||
Callable Bond | ||
------------- | ||
|
||
.. autofunction:: torchquantlib.core.asset_pricing.bond.bond_pricer.callable_bond | ||
|
||
Usage Example | ||
^^^^^^^^^^^^^ | ||
|
||
.. code-block:: python | ||
from torchquantlib.core.asset_pricing.bond.bond_pricer import callable_bond | ||
face_value = torch.tensor(1000.0) | ||
coupon_rate = torch.tensor(0.06) | ||
rate = torch.tensor(0.05) | ||
periods = torch.tensor(10) | ||
call_price = torch.tensor(1050.0) | ||
call_period = torch.tensor(5) | ||
price = callable_bond(face_value, coupon_rate, rate, periods, call_price, call_period) | ||
print(f"Callable Bond Price: {price.item():.2f}") | ||
Putable Bond | ||
------------ | ||
|
||
.. autofunction:: torchquantlib.core.asset_pricing.bond.bond_pricer.putable_bond | ||
|
||
Usage Example | ||
^^^^^^^^^^^^^ | ||
|
||
.. code-block:: python | ||
from torchquantlib.core.asset_pricing.bond.bond_pricer import putable_bond | ||
face_value = torch.tensor(1000.0) | ||
coupon_rate = torch.tensor(0.06) | ||
rate = torch.tensor(0.05) | ||
periods = torch.tensor(10) | ||
put_price = torch.tensor(950.0) | ||
put_period = torch.tensor(5) | ||
price = putable_bond(face_value, coupon_rate, rate, periods, put_price, put_period) | ||
print(f"Putable Bond Price: {price.item():.2f}") | ||
Convertible Bond | ||
---------------- | ||
|
||
.. autofunction:: torchquantlib.core.asset_pricing.bond.bond_pricer.convertible_bond | ||
|
||
Usage Example | ||
^^^^^^^^^^^^^ | ||
|
||
.. code-block:: python | ||
from torchquantlib.core.asset_pricing.bond.bond_pricer import convertible_bond | ||
face_value = torch.tensor(1000.0) | ||
coupon_rate = torch.tensor(0.06) | ||
rate = torch.tensor(0.05) | ||
periods = torch.tensor(10) | ||
conversion_ratio = torch.tensor(20) | ||
conversion_price = torch.tensor(55.0) | ||
price = convertible_bond(face_value, coupon_rate, rate, periods, conversion_ratio, conversion_price) | ||
print(f"Convertible Bond Price: {price.item():.2f}") | ||
Stochastic Rate Bond | ||
-------------------- | ||
|
||
.. autofunction:: torchquantlib.core.asset_pricing.bond.bond_pricer.stochastic_rate_bond | ||
|
||
Usage Example | ||
^^^^^^^^^^^^^ | ||
|
||
.. code-block:: python | ||
import torch | ||
from torchquantlib.core.asset_pricing.bond.bond_pricer import stochastic_rate_bond | ||
face_value = torch.tensor(1000.0) | ||
coupon_rate = torch.tensor(0.06) | ||
rate = torch.tensor([0.05, 0.052, 0.054, 0.056, 0.058]) | ||
periods = torch.tensor(5) | ||
price = stochastic_rate_bond(face_value, coupon_rate, rate, periods) | ||
print(f"Stochastic Rate Bond Price: {price.item():.2f}") |
47 changes: 47 additions & 0 deletions
47
docs/source/torchquantlib.core.asset_pricing.bond.fixed_income_forward.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
Fixed Income Forward | ||
==================== | ||
|
||
.. automodule:: torchquantlib.core.asset_pricing.bond.fixed_income_forward | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
This module provides implementation for pricing fixed income forward contracts. | ||
|
||
Fixed Income Forward | ||
-------------------- | ||
|
||
.. autofunction:: torchquantlib.core.asset_pricing.bond.fixed_income_forward.fixed_income_forward | ||
|
||
Usage Example | ||
^^^^^^^^^^^^^ | ||
|
||
.. code-block:: python | ||
import torch | ||
from torchquantlib.core.asset_pricing.bond.fixed_income_forward import fixed_income_forward | ||
face_value = torch.tensor(1000.0) | ||
rate = torch.tensor(0.05) | ||
time_to_maturity = torch.tensor(2.0) | ||
forward_rate = torch.tensor(0.06) | ||
forward_price = fixed_income_forward(face_value, rate, time_to_maturity, forward_rate) | ||
print(f"Fixed Income Forward Price: {forward_price.item():.2f}") | ||
Formula | ||
^^^^^^^ | ||
|
||
The forward price of a fixed income security is calculated using the following formula: | ||
|
||
.. math:: | ||
Forward Price = Face Value * e^{(Forward Rate - Current Rate) * Time to Maturity} | ||
Where: | ||
- Face Value is the notional amount of the fixed income security | ||
- Forward Rate is the interest rate agreed upon for the forward contract | ||
- Current Rate is the current market interest rate | ||
- Time to Maturity is the time until the forward contract expires (in years) | ||
|
||
Note that this formula assumes continuous compounding. For discrete compounding, a different formula would be required. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
docs/source/torchquantlib.core.asset_pricing.money.future_pricer.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
Future Pricer | ||
============= | ||
|
||
.. automodule:: torchquantlib.core.asset_pricing.money.future_pricer | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
This module provides implementation for pricing futures contracts. | ||
|
||
|
||
.. autofunction:: torchquantlib.core.asset_pricing.money.future_pricer.future_pricer | ||
|
||
Usage Example | ||
^^^^^^^^^^^^^ | ||
|
||
.. code-block:: python | ||
import torch | ||
from torchquantlib.core.asset_pricing.money.future_pricer import future_pricer | ||
spot = torch.tensor(100.0) | ||
rate = torch.tensor(0.05) | ||
expiry = torch.tensor(1.0) | ||
futures_price = future_pricer(spot, rate, expiry) | ||
print(f"Futures Price: {futures_price.item():.2f}") | ||
Formula | ||
^^^^^^^ | ||
|
||
The theoretical price of a futures contract is calculated using the following formula: | ||
|
||
.. math:: | ||
Futures Price = Spot Price * e^{(risk-free rate * time to expiry)} | ||
Where: | ||
- Spot Price is the current market price of the underlying asset | ||
- risk-free rate is the annualized risk-free interest rate | ||
- time to expiry is the time until the futures contract expires (in years) | ||
|
||
Note: | ||
- This model assumes perfect markets with no transaction costs or taxes. | ||
- For commodities or dividend-paying stocks, additional factors would need to be considered in the pricing model. | ||
- The formula uses continuous compounding. | ||
|
||
Limitations | ||
^^^^^^^^^^^ | ||
|
||
The future pricer implemented in this module has some limitations: | ||
|
||
1. It assumes continuous compounding, which may not always reflect real-world scenarios. | ||
2. It does not account for dividends, which can affect the futures price for stock index futures. | ||
3. It does not consider storage costs or convenience yields, which are important factors for commodity futures. | ||
4. The model assumes perfect markets without transaction costs, taxes, or other frictions. | ||
|
||
For more complex scenarios or specific types of futures contracts, you may need to modify the pricing model or use more advanced techniques. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.