Skip to content

Commit

Permalink
update models
Browse files Browse the repository at this point in the history
  • Loading branch information
jialuechen committed Oct 6, 2024
1 parent 4ff2be7 commit a712835
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.3.0] - 2024-09-22
### Added
- Optimal Transport for Model Calibration

## [1.2.0] - 2024-09-22
### Added
- Seq2Seq PDE solvers
Expand Down
11 changes: 0 additions & 11 deletions examples/random_walk.py

This file was deleted.

2 changes: 1 addition & 1 deletion examples/vasicek.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import torch
from torchquantlib.models.interest_rate.vasicek_model import VasicekModel
from torchquantlib.models.interest_rate.vasicek import VasicekModel

spot_rate = torch.tensor(0.03)
kappa = torch.tensor(0.5)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_interest_rate_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch
from torchquantlib.models.interest_rate.vasicek_model import VasicekModel
from torchquantlib.models.interest_rate.vasicek import VasicekModel

def test_vasicek_model():
def test_vasicek():
spot_rate = torch.tensor(0.03)
kappa = torch.tensor(0.5)
theta = torch.tensor(0.04)
Expand Down
3 changes: 2 additions & 1 deletion torchquantlib/calibration/heston_calibration.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import torch
from torch import Tensor
from scipy.optimize import minimize
from torchquantlib.models.stochastic_volatility.heston import Heston

def heston_loss(params, market_prices, strikes, expiries, spot, rate):
kappa, theta, sigma, rho, v0 = params
model = HestonModel(spot, strikes, expiries, rate, kappa, theta, sigma, rho, v0)
model = Heston(spot, strikes, expiries, rate, kappa, theta, sigma, rho, v0)
model_prices = model.price_option('call')
loss = torch.sum((market_prices - model_prices) ** 2)
return loss
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions torchquantlib/calibration/vasicek_calibration.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import torch
from torch import Tensor
from scipy.optimize import minimize
from models.interest_rate import vasicek_model as VasicekModel
from models.interest_rate.vasicek import Vasicek

def vasicek_loss(params, market_rates, times):
kappa, theta, sigma = params
model = VasicekModel(market_rates[0], kappa, theta, sigma, times)
model = Vasicek(market_rates[0], kappa, theta, sigma, times)
model_rates = model.simulate()
loss = torch.sum((market_rates - model_rates) ** 2)
return loss
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch
from torch import Tensor

class LMMModel:
class LMM:
def __init__(self, forward_rates: Tensor, volatilities: Tensor, times: Tensor):
self.forward_rates = forward_rates
self.volatilities = volatilities
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch
from torch import Tensor

class VasicekModel:
class Vasicek:
def __init__(self, spot_rate: Tensor, kappa: Tensor, theta: Tensor, sigma: Tensor, time: Tensor):
self.spot_rate = spot_rate
self.kappa = kappa
Expand Down

0 comments on commit a712835

Please sign in to comment.