diff --git a/docs/make.jl b/docs/make.jl index 8dba104d..b68149a7 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -12,13 +12,26 @@ makedocs(; assets=String[] ), pages=[ - # "Home" => "index.md", - # "Guide" => "guide.md", - # "Contracts" => "contracts.md", - # "Models, Valuation, and Fitting" => "models.md", - # "API Reference" => "api.md", - # "Migration Guide" => "migration.md", - # "FAQs" => "faq.md", + "Home" => "index.md", + "Guide" => [ + "Introduction" => "introduction.md", + "Models, Valuation, and Fitting" => "models.md", + "Contracts" => "contracts.md", + "Rates" => "Rates.md", + "Migration Guide" => "migration.md", + ], + "Modules" => [ + "FinanceModels" => "API/FinanceModels.md", + "FinanceCore" => "API/FinanceCore.md", + "Spline" => "API/Spline.md", + "Fit" => "API/Fit.md", + "Yield" => "API/Yield.md", + "Bond" => "API/Bond.md", + "Equity" => "API/Equity.md", + "Option" => "API/Option.md", + "Volatility" => "API/Volatility.md", + ], + "FAQs" => "faq.md", ], warnonly=true ) diff --git a/docs/src/API/Bond.md b/docs/src/API/Bond.md new file mode 100644 index 00000000..1b436b2d --- /dev/null +++ b/docs/src/API/Bond.md @@ -0,0 +1,19 @@ +# FinanceModels.Bond API Reference + +```@index +Modules = [FinanceModels.Bond] +``` + +## Exported API +```@autodocs +Modules = [FinanceModels.Bond] +Private = false +``` + +## Unexported API +```@autodocs +Modules = [FinanceModels.Bond] +Public = false +``` + +Please [open an issue](https://github.com/JuliaActuary/FinanceModels.jl/issues) if you encounter any issues or confusion with the package. diff --git a/docs/src/API/Equity.md b/docs/src/API/Equity.md new file mode 100644 index 00000000..cc2765a6 --- /dev/null +++ b/docs/src/API/Equity.md @@ -0,0 +1,19 @@ +# FinanceModels.Equity API Reference + +```@index +Modules = [FinanceModels.Equity] +``` + +## Exported API +```@autodocs +Modules = [FinanceModels.Equity] +Private = false +``` + +## Unexported API +```@autodocs +Modules = [FinanceModels.Equity] +Public = false +``` + +Please [open an issue](https://github.com/JuliaActuary/FinanceModels.jl/issues) if you encounter any issues or confusion with the package. diff --git a/docs/src/API/FinanceCore.md b/docs/src/API/FinanceCore.md new file mode 100644 index 00000000..9d499c09 --- /dev/null +++ b/docs/src/API/FinanceCore.md @@ -0,0 +1,19 @@ +# FinanceCore API Reference + +```@index +Modules = [FinanceCore] +``` + +## Exported API +```@autodocs +Modules = [FinanceCore] +Private = false +``` + +## Unexported API +```@autodocs +Modules = [FinanceCore] +Public = false +``` + +Please [open an issue](https://github.com/JuliaActuary/FinanceModels.jl/issues) if you encounter any issues or confusion with the package. diff --git a/docs/src/API/FinanceModels.md b/docs/src/API/FinanceModels.md new file mode 100644 index 00000000..41fec671 --- /dev/null +++ b/docs/src/API/FinanceModels.md @@ -0,0 +1,19 @@ +# FinanceModels API Reference + +```@index +Modules = [FinanceModels] +``` + +## Exported API +```@autodocs +Modules = [FinanceModels] +Private = false +``` + +## Unexported API +```@autodocs +Modules = [FinanceModels] +Public = false +``` + +Please [open an issue](https://github.com/JuliaActuary/FinanceModels.jl/issues) if you encounter any issues or confusion with the package. diff --git a/docs/src/API/Fit.md b/docs/src/API/Fit.md new file mode 100644 index 00000000..06ddc825 --- /dev/null +++ b/docs/src/API/Fit.md @@ -0,0 +1,19 @@ +# FinanceModels.Fit API Reference + +```@index +Modules = [FinanceModels.Fit] +``` + +## Exported API +```@autodocs +Modules = [FinanceModels.Fit] +Private = false +``` + +## Unexported API +```@autodocs +Modules = [FinanceModels.Fit] +Public = false +``` + +Please [open an issue](https://github.com/JuliaActuary/FinanceModels.jl/issues) if you encounter any issues or confusion with the package. diff --git a/docs/src/API/Option.md b/docs/src/API/Option.md new file mode 100644 index 00000000..0ddc0fa1 --- /dev/null +++ b/docs/src/API/Option.md @@ -0,0 +1,19 @@ +# FinanceModels.Option API Reference + +```@index +Modules = [FinanceModels.Option] +``` + +## Exported API +```@autodocs +Modules = [FinanceModels.Option] +Private = false +``` + +## Unexported API +```@autodocs +Modules = [FinanceModels.Option] +Public = false +``` + +Please [open an issue](https://github.com/JuliaActuary/FinanceModels.jl/issues) if you encounter any issues or confusion with the package. diff --git a/docs/src/API/Spline.md b/docs/src/API/Spline.md new file mode 100644 index 00000000..bdf404e6 --- /dev/null +++ b/docs/src/API/Spline.md @@ -0,0 +1,19 @@ +# FinanceModels.Spline API Reference + +```@index +Modules = [FinanceModels.Spline] +``` + +## Exported API +```@autodocs +Modules = [FinanceModels.Spline] +Private = false +``` + +## Unexported API +```@autodocs +Modules = [FinanceModels.Spline] +Public = false +``` + +Please [open an issue](https://github.com/JuliaActuary/FinanceModels.jl/issues) if you encounter any issues or confusion with the package. diff --git a/docs/src/API/Volatility.md b/docs/src/API/Volatility.md new file mode 100644 index 00000000..564b9870 --- /dev/null +++ b/docs/src/API/Volatility.md @@ -0,0 +1,19 @@ +# FinanceModels.Volatility API Reference + +```@index +Modules = [FinanceModels.Volatility] +``` + +## Exported API +```@autodocs +Modules = [FinanceModels.Volatility] +Private = false +``` + +## Unexported API +```@autodocs +Modules = [FinanceModels.Volatility] +Public = false +``` + +Please [open an issue](https://github.com/JuliaActuary/FinanceModels.jl/issues) if you encounter any issues or confusion with the package. diff --git a/docs/src/API/Yield.md b/docs/src/API/Yield.md new file mode 100644 index 00000000..3fcd7311 --- /dev/null +++ b/docs/src/API/Yield.md @@ -0,0 +1,19 @@ +# FinanceModels.Yield API Reference + +```@index +Modules = [FinanceModels.Yield] +``` + +## Exported API +```@autodocs +Modules = [FinanceModels.Yield] +Private = false +``` + +## Unexported API +```@autodocs +Modules = [FinanceModels.Yield] +Public = false +``` + +Please [open an issue](https://github.com/JuliaActuary/FinanceModels.jl/issues) if you encounter any issues or confusion with the package. diff --git a/docs/src/Rates.md b/docs/src/Rates.md new file mode 100644 index 00000000..373f8aae --- /dev/null +++ b/docs/src/Rates.md @@ -0,0 +1,62 @@ +## Rates + +We should first discuss `Rate`s, which are reexported from [`FinanceCore.jl`](https://github.com/JuliaActuary/FinanceCore.jl) + +Rates are types that wrap scalar values to provide information about how to determine `discount` and `accumulation` factors. These allow for explicit handling of rate compounding conventions which, if not explicit, is often a source of errors in practice. + +There are two `Frequency` types: + +- `Yields.Periodic(m)` for rates that compound `m` times per period (e.g. `m` times per year if working with annual rates). +- `Yields.Continuous()` for continuously compounding rates. + +#### Examples + +```julia +Continuous(0.05) # 5% continuously compounded +Periodic(0.05,2) # 5% compounded twice per period +``` + +These are both subtypes of the parent `Rate` type and are instantiated as: + +```julia +Rate(0.05,Continuous()) # 5% continuously compounded +Rate(0.05,Periodic(2)) # 5% compounded twice per period +``` + +Broadcast over a vector to create `Rates` with the given compounding: + +```julia +Periodic.([0.02,0.03,0.04],2) +Continuous.([0.02,0.03,0.04]) +``` + +Rates can also be constructed by specifying the `CompoundingFrequency` and then passing a scalar rate: + +```julia +Periodic(1)(0.05) +Continuous()(0.05) +``` + +#### Conversion + +Convert rates between different types with `convert`. E.g.: + +```julia +r = Rate(0.01,Periodic(12)) # rate that compounds 12 times per rate period (ie monthly) + +convert(Yields.Periodic(1),r) # convert monthly rate to annual effective +convert(Yields.Continuous(),r) # convert monthly rate to continuous +``` + +To get the scalar value out of the `Rate`, use `FinanceModels.rate(r)`: + +```julia-rel +julia> r = Rate(0.01,Periodic(12)); +julia> rate(r) +0.01 + +``` + +#### Arithmetic + +Adding, subtracting, multiplying, dividing, and comparing rates is supported. diff --git a/docs/src/api.md b/docs/src/api.md deleted file mode 100644 index f4149440..00000000 --- a/docs/src/api.md +++ /dev/null @@ -1,51 +0,0 @@ -# FinanceModels API Reference - -Please [open an issue](https://github.com/JuliaActuary/FinanceModels.jl/issues) if you encounter any issues or confusion with the package. - -## Rate Types - -When JuliaActuary packages return a rate, they will be of a `Rate` type, such as `Rate(0.05,Periodic(2))` for a 5% rate compounded twice per period. It is recommended to keep rates typed and use them throughout the ecosystem without modifying it. - -For example, if we construct a curve like this: - -```julia -# 2021-03-31 rates from Treasury.gov -rates =[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 -mats = [1/12, 2/12, 3/12, 6/12, 1, 2, 3, 5, 7, 10, 20, 30] - -curve = FinanceModels.CMT(rates,mats) -``` - -Then rates from this curve will be typed. For example: - -```julia -z = zero(c,10) -``` - -Now, `z` will be: `FinanceModels.Rate{Float64, Continuous}(0.01779624378877313, Continuous())` - -This `Rate` has both the rate an the compounding convention embedded in the datatype. - -You can now use that rate throughout the JuliaActuary ecosystem, such as with ActuaryUtilities.jl: - -```julia -using ActuaryUtilities -present_values(z,cashflows) -``` - -If you need to extract the rate for some reason, you can get the rate by calling `FinanceModels.rate(...)`. Using the above example, `FinanceModels.rate(z)` will return `0.01779624378877313`. - -```@index -``` - -## Exported API -```@autodocs -Modules = [FinanceModels, FinanceCore, FinanceModels.Bond, FinanceModels.Yield, FinanceModels.Spline, FinanceModels.Fit, FinanceModels.Volatility,FinanceModels.Option, FinanceModels.Equity] -Private = false -``` - -## Unexported API -```@autodocs -Modules = [FinanceModels, FinanceCore, FinanceModels.Bond, FinanceModels.Yield, FinanceModels.Spline, FinanceModels.Fit, FinanceModels.Volatility,FinanceModels.Option, FinanceModels.Equity] -Public = false -``` diff --git a/docs/src/contracts.md b/docs/src/contracts.md index d7c031eb..bc0e024c 100644 --- a/docs/src/contracts.md +++ b/docs/src/contracts.md @@ -1,13 +1,5 @@ # Contracts -## Page Contents - -```@contents -Pages = ["contracts.md"] -Depth = 4 -``` - - ## **Contracts** - A composable way to represent financial instruments Contracts are a composable way to represent financial instruments. They are, in essence, anything that is a collection of cashflows. Contracts can be combined to represent more complex instruments. For example, a bond can be represented as a collection of cashflows that correspond to the coupon payments and the principal repayment. @@ -96,22 +88,8 @@ Note that all contracts in FinanceModels.jl are currently *unit* contracts in th #### More complex Contracts -**When the cashflow depends on a model**. An example of this is a floating bond where the coupon paid depends on a view of forward rates. See [this section in the overview](guide.html#Contracts-that-depend-on-the-model-(or-multiple-models)) on projections for how this is handled. +**When the cashflow depends on a model**. An example of this is a floating bond where the coupon paid depends on a view of forward rates. See [this section in the overview](@ref Contracts-that-depend-on-the-model-(or-multiple-models)) on projections for how this is handled. ## Available Contracts & Modules -### `Bond` Module - -```@autodocs; canonical=false -Modules = [FinanceModels.Bond] -``` - -### Other Contracts - -- [Composite](@ref) -- [CommonEquity](@ref) -- [Forward](@ref) - -### Derivatives - -- [FinanceModels.Option](@ref) +See the Modules in the left navigation for details on available contracts/models/functions. diff --git a/docs/src/guide.md b/docs/src/introduction.md similarity index 100% rename from docs/src/guide.md rename to docs/src/introduction.md diff --git a/docs/src/migration.md b/docs/src/migration.md index c2f5a329..6636522d 100644 --- a/docs/src/migration.md +++ b/docs/src/migration.md @@ -37,7 +37,7 @@ quotes = ParYield.(rates,timepoints) model = fit(SmithWilson(),quotes) ``` -#### Discussion +#### Details of changes Previously the kind of contract, the implied quotes, the type of model, and how the fitting process worked were all combined into a single call (`Yields.Par`). This minimized the amount of code needed to construct a yield curve, but left it fairly cumbersome to extend the package. For example, for every new yield curve model, methods for `Par`, `CMT`, `OIS`, `Zero`, ... had to be defined. Additionally, all of the inputs needed to be yields - specifying a price was not available as an argument to fit. diff --git a/docs/src/models.md b/docs/src/models.md index d614f80c..d42fe29b 100644 --- a/docs/src/models.md +++ b/docs/src/models.md @@ -1,12 +1,5 @@ # Models, Valuation, Projections, and Fitting -## Page Contents - -```@contents -Pages = ["models.md"] -Depth = 4 -``` - ## Introduction Conceptually, we have an iterative process: @@ -61,13 +54,22 @@ Continuous()(0.05) Convert rates between different types with `convert`. E.g.: -```julia-repl -r = Rate(Yields.Periodic(12),0.01) # rate that compounds 12 times per rate period (ie monthly) +```julia +r = Rate(0.01,Periodic(12)) # rate that compounds 12 times per rate period (ie monthly) convert(Yields.Periodic(1),r) # convert monthly rate to annual effective convert(Yields.Continuous(),r) # convert monthly rate to continuous ``` +To get the scalar value out of the `Rate`, use `FinanceModels.rate(r)`: + +```julia-rel +julia> r = Rate(0.01,Periodic(12)); +julia> rate(r) +0.01 + +``` + #### Arithmetic Adding, subtracting, multiplying, dividing, and comparing rates is supported. @@ -115,7 +117,7 @@ See the [FinanceModels.jl Guide](@ref) for an example of creating a model from s ### Available Models - Option Valuation -- [`FinanceModels.Option.BlackScholesMerton`](@ref) +- [`FinanceModels.Equity.BlackScholesMerton`](@ref) ### Available Models - Volatility diff --git a/src/Contract.jl b/src/Contract.jl index c9c0c8f2..9ed3a1ac 100644 --- a/src/Contract.jl +++ b/src/Contract.jl @@ -342,6 +342,26 @@ struct CommonEquity <: FinanceCore.AbstractContract end module Option import ..FinanceCore: AbstractContract, Timepoint + +""" + EuroCall(contract,strike,maturity) + +A European call option on the given contract with the given strike and maturity. + +# Arguments + - contract::AbstractContract - The underlying contract. + - strike::Real - The strike price. + - maturity::Union{Real,Date} - The maturity of the option. + + Supertype Hierarchy +≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡ + + EuroCall{S,K,M} <: FinanceCore.AbstractContract <: Any + + + + +""" struct EuroCall{S<:AbstractContract,K<:Real,M<:Timepoint} <: AbstractContract underlying::S strike::K diff --git a/src/model/Equity.jl b/src/model/Equity.jl index cefbbc17..736e2f68 100644 --- a/src/model/Equity.jl +++ b/src/model/Equity.jl @@ -1,7 +1,7 @@ """ The `Equity` module provides equity-related model definitions. -See also: the [`Volatility`](@ref) module. +See also: the [`Volatility`](@ref FinanceModels.Volatility-API-Reference) module. """ module Equity import ..AbstractModel @@ -16,12 +16,12 @@ A struct representing the Black-Scholes-Merton model for equity prices. # Arguments - `r`: The risk-free rate. - `q`: The dividend yield. -- `σ`: The volatility model of the underlying asset (see [`Volatility`](@ref) module) +- `σ`: The volatility model of the underlying asset (see [`Volatility`](@ref FinanceModels.Volatility-API-Reference) module) # Fields - `r`: The risk-free rate. - `q`: The dividend yield. -- `σ`: The volatility model of the underlying asset (see [`Volatility`](@ref) module) +- `σ`: The volatility model of the underlying asset (see [`Volatility`](@ref FinanceModels.Volatility-API-Reference) module) When [`fit`](@ref FinanceModels.fit-Union{Tuple{F}, Tuple{Any, Any}, Tuple{Any, Any, F}} where F<:FinanceModels.Fit.Loss)ting, the volatility will be solved-for; volatility itself is a sub-model that will be optimized with a default optimization bound of `0.0 .. 10.0` diff --git a/src/model/Volatility.jl b/src/model/Volatility.jl index 784e4472..3396a637 100644 --- a/src/model/Volatility.jl +++ b/src/model/Volatility.jl @@ -4,6 +4,11 @@ import ..AbstractModel abstract type AbstractVolatilityModel <: AbstractModel end +""" + Volatility.Constant(σ) + +A constant volatility per period. If σ is not explicitly passed, then it is set to zero. +""" struct Constant{T} <: AbstractVolatilityModel σ::T end