Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various things to try to improve TTFX #138

Merged
merged 3 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ AccessibleOptimization = "d88a00a0-4a21-4fe4-a515-e2123c37b885"
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
BSplineKit = "093aae92-e908-43d7-9660-e50ee39d5a0a"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
FinanceCore = "b9b1ffdd-6612-4b69-8227-7663be06e089"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
OptimizationMetaheuristics = "3aafef2f-86ae-4776-b337-85a36adf0b55"
OptimizationOptimJL = "36348300-93cb-4f02-beb5-3c3902f8871e"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Transducers = "28d57a85-8fef-5791-bfe6-a80928e7c999"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
Expand All @@ -25,30 +24,23 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
MakieCore = "20f20a25-4f0e-4fdf-b5d1-57303727442b"

[extensions]
# name of extension to the left
# extension dependencies required to load the extension to the right
# use a list for multiple extension dependencies
FinanceModelsMakieCoreExt = "MakieCore"

[compat]
julia = "1.9" #Bsplinekit 0.16 is 1.8 or above and AccessibleOptimization's deps is 1.9
FinanceCore = "^2"
AccessibleOptimization = "^0.1.1"
Accessors = "^0.1"
BSplineKit = "^0.16"
FinanceCore = "^2"
IntervalSets = "^0.7"
Transducers = "^0.4"
MakieCore = "0.6"
Optimization = "^3.15"
OptimizationMetaheuristics = "^0.1.2"
OptimizationOptimJL = "^0.1.9"
Distributions = "^0.25"
AccessibleOptimization = "^0.1.1"
Accessors = "^0.1"
PrecompileTools = "^1.1"
Reexport = "^1.2"
StaticArrays = "^1.6"
Transducers = "^0.4"
UnicodePlots = "^3.6"


julia = "1.9"

[extras]
ActuaryUtilities = "bdd23359-8b1c-4f88-b89b-d11982a786f4"
Expand Down
3 changes: 1 addition & 2 deletions src/FinanceModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Dates
using Reexport
@reexport using FinanceCore
using FinanceCore: present_value, discount, accumulation
using OptimizationOptimJL
using OptimizationMetaheuristics
using StaticArrays
using IntervalSets
Expand All @@ -15,7 +14,7 @@ using Transducers
import BSplineKit
import UnicodePlots
using Transducers: @next, complete, __foldl__, asfoldable
import Distributions
import SpecialFunctions



Expand Down
2 changes: 1 addition & 1 deletion src/model/Yield.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ..BSplineKit
import UnicodePlots
import ..Bond: coupon_times

using FinanceCore: Continuous, Periodic, discount, accumulation, AbstractContract
using ..FinanceCore: Continuous, Periodic, discount, accumulation, AbstractContract

export discount, zero, forward, par, pv

Expand Down
9 changes: 8 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
N(x) = Distributions.cdf(Distributions.Normal(), x)
# all we need is cumulative normal, so avoid Distributions.jl dependency
# https://www.johndcook.com/blog/cpp_phi/

function ϕ(x)
return 0.5 * SpecialFunctions.erfc(-x * (0.5))
end

N(x) = ϕ(x)

Check warning on line 8 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L8

Added line #L8 was not covered by tests

function d1(S, K, τ, r, σ, q)
return (log(S / K) + (r - q + σ^2 / 2) * τ) /* (τ))
Expand Down
23 changes: 23 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,27 @@
rates = convert.(DecFP.Dec64, [0.01, 0.01, 0.03, 0.05, 0.07, 0.16, 0.35, 0.92, 1.40, 1.74, 2.31, 2.41] ./ 100)
y = fit(Spline.Linear(), CMTYield.(rates, mats), Fit.Bootstrap())
@test y isa FinanceModels.Yield.AbstractYieldModel
end

@testset "Normal CDF" begin
# https://www.johndcook.com/blog/cpp_phi/

x = [
-3,
-1,
0.0,
0.5,
2.1
]
target = [
0.00134989803163,
0.158655253931,
0.5,
0.691462461274,
0.982135579437
]
@testset "confirm accuracy" for i in 1:5
@test isapprox(FinanceModels.ϕ(x[i]), target[i], atol=1e-12)
end

end
Loading