Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jialuechen committed Oct 10, 2024
1 parent c9fac8a commit d99655b
Show file tree
Hide file tree
Showing 22 changed files with 738 additions and 44 deletions.
1 change: 1 addition & 0 deletions docs/source/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ This section provides detailed documentation for TorchQuant APIs.
torchquantlib.calibration
torchquantlib.utils


For more information on specific modules and functions, please refer to the individual module pages.
136 changes: 136 additions & 0 deletions docs/source/torchquantlib.core.asset_pricing.bond.bond_pricer.rst
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}")
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.
13 changes: 6 additions & 7 deletions docs/source/torchquantlib.core.asset_pricing.bond.rst
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
torchquantlib.core.asset\_pricing.bond package
Bond
==============================================


.. toctree::
:maxdepth: 4

torchquantlib.core.asset\_pricing.bond.bond\_pricer module
----------------------------------------------------------

torchquantlib.core.asset_pricing.bond.bond_pricer
torchquantlib.core.asset_pricing.bond.fixed_income_forward
.. automodule:: torchquantlib.core.asset_pricing.bond.bond_pricer
:members:
:undoc-members:
:show-inheritance:

torchquantlib.core.asset\_pricing.bond.fixed\_income\_forward module
--------------------------------------------------------------------

.. automodule:: torchquantlib.core.asset_pricing.bond.fixed_income_forward
:members:
:undoc-members:
Expand Down
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.
8 changes: 5 additions & 3 deletions docs/source/torchquantlib.core.asset_pricing.money.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
torchquantlib.core.asset\_pricing.money package
Money Market
===============================================

.. toctree::
:maxdepth: 4

torchquantlib.core.asset_pricing.money.future_pricer

torchquantlib.core.asset\_pricing.money.future\_pricer module
-------------------------------------------------------------

.. automodule:: torchquantlib.core.asset_pricing.money.future_pricer
:members:
Expand Down
Loading

0 comments on commit d99655b

Please sign in to comment.