0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Juliaを使用したVasicekモデルの解説

Posted at

コード

using Random, Distributions, Plots

function simulate_vasicek(r₀, a, b, σ, T, dt)
    N = Int(T / dt)
    r = zeros(N+1)
    r[1] = r₀
    for t in 1:N
        Z = randn()
        dr = a * (b - r[t]) * dt + σ * sqrt(dt) * Z
        r[t+1] = r[t] + dr
    end
    return r, 0:dt:T
end

# パラメータ設定
r₀ = 0.03     # 初期短期金利 3%
a  = 0.1      # 平均回帰速度
b  = 0.05     # 長期平均金利 5%
σ  = 0.01     # ボラティリティ 1%
T  = 5.0      # シミュレーション期間(年)
dt = 0.01     # タイムステップ

# 実行と可視化
r_path, time = simulate_vasicek(r₀, a, b, σ, T, dt)
plot(time, r_path, xlabel="年", ylabel="短期金利", title="Vasicekモデルの短期金利シミュレーション")

出力結果

スクリーンショット 2025-07-02 12.15.40.png

Vasicekモデル

短期金利の変動を記述する数理モデルの一つ。将来の短期金利の動きの傾向が分かる。

コード

using Random, Distributions, Plots

・Random: 乱数生成に必要(ブラウン運動などに使用)
・Distributions: 正規分布などの確率分布を扱う
・Plots: グラフ描画用パッケージ(plot()などで使用)

function simulate_vasicek(r₀, a, b, σ, T, dt)

Vasicekモデルに従って短期金利 r_t をシミュレーションします。
・r₀: 初期金利(年率)
・a: 金利が平均に戻る強さ(平均回帰係数)
・b: 金利の長期平均(平均回帰先)
・σ: ボラティリティ(揺れの強さ)
・T: 総シミュレーション期間(年)
・dt: タイムステップ(小さくするほど精密)

    N = Int(T / dt)

・タイムステップの数を計算
・例:T = 5年, dt = 0.01(=1.2週間)なら N = 500 ステップ

    r = zeros(N+1)

・金利の履歴を格納する配列 r を初期化
・r は長さ N+1 の配列(最初の1点も含めるため)

    r[1] = r₀

・初期金利を設定
・時間0における金利 r₀ を記録

    for t in 1:N

・シミュレーションループの開始
・タイムステップごとに金利を更新していく

        Z = randn()

・標準正規乱数の生成(Z \sim \mathcal{N}(0,1))

        dr = a * (b - r[t]) * dt + σ * sqrt(dt) * Z
記号 説明
dr 時刻 t から t + dt までの短期金利の変化量(デルタr)
a 平均回帰速度(Mean reversion speed):金利が長期平均へ戻る速さ。大きいほど早く平均に戻る
b 長期平均金利(Long-term mean level):金利が長期的に向かう水準(中心)
r[t] 時刻 t における現在の短期金利
dt 微小な時間幅(例えば、0.01年=約3.65日)
σ ボラティリティ(Volatility):金利の揺れの大きさ。変動の不確実性を表す
Z 標準正規分布からの乱数(Z ~ N(0, 1)):ブラウン運動の一ステップを表すランダム性
sqrt(dt) 時間ステップの平方根:ブラウン運動は時間の平方根スケーリングを持つ
        r[t+1] = r[t] + dr

在の金利から次の時刻の金利を更新

    return r, 0:dt:T

金利の推移と対応する時刻(0, 0.01, …, T)を返す

r_path, time = simulate_vasicek(r₀, a, b, σ, T, dt)

・シミュレーション実行
・短期金利の時間推移 r_path と時刻 time が返される

plot(time, r_path, xlabel="年", ylabel="短期金利", title="Vasicekモデルの短期金利シミュレーション")

グラフ描画(グラフに表示されなかった。)
・横軸: 年
・縦軸: 短期金利
・タイトル: “Vasicekモデルの短期金利シミュレーション”

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?