Skip to content

Commit

Permalink
review docs
Browse files Browse the repository at this point in the history
  • Loading branch information
felipenoris committed Mar 7, 2020
1 parent c926dc1 commit b3442ed
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
[codecov-img]: https://img.shields.io/codecov/c/github/JuliaFinance/BusinessDays.jl/master.svg?label=codecov&style=flat-square
[codecov-url]: http://codecov.io/github/JuliaFinance/BusinessDays.jl?branch=master
[docs-dev-img]: https://img.shields.io/badge/docs-dev-blue.svg?style=flat-square
[docs-dev-url]: https://JuliaFinance.github.io/BusinessDays.jl/dev
[docs-dev-url]: https://juliafinance.github.io/BusinessDays.jl/dev
[docs-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg?style=flat-square
[docs-stable-url]: https://JuliaFinance.github.io/BusinessDays.jl/stable
[docs-stable-url]: https://juliafinance.github.io/BusinessDays.jl/stable

A highly optimized *Business Days* calculator written in Julia language.
Also known as *Working Days* calculator.
Expand All @@ -32,4 +32,4 @@ julia> Pkg.add("BusinessDays")

## Documentation

Package documentation is hosted at https://JuliaFinance.github.io/BusinessDays.jl/stable.
Package documentation is hosted at https://juliafinance.github.io/BusinessDays.jl/stable.
45 changes: 29 additions & 16 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ julia> Pkg.add("BusinessDays")

This code was developed with a mindset of a Financial Institution that has a big *Fixed Income* portfolio. Many financial contracts, specially *Fixed Income instruments*, depend on a particular calendar of holidays to determine how many days exist between the valuation date and the maturity of the contract. A *Business Days* calculator is a small piece of software used to perform this important step of the valuation process.
While there are many implementations of *Business Days* calculators out there, the usual implementation is based on this kind of algorithm:
```R

```r
dt0 = initial_date
dt1 = final_date
holidays = vector_of_holidays
Expand All @@ -38,7 +39,8 @@ end while
This works fine for general use. But the performance becomes an issue if one must repeat this calculation many times. Say you have 50 000 contracts, each contract with 20 cash flows. If you need to apply this algorithm to each cash flow, you will need to perform it 1 000 000 times.

For instance, let's try out this code using *R* and *[QuantLib](https://github.com/lballabio/QuantLib)* ([RQuantLib](https://github.com/eddelbuettel/rquantlib)):
```R

```r
library(RQuantLib)
library(microbenchmark)

Expand All @@ -52,6 +54,7 @@ microbenchmark(businessDaysBetween("Brazil", from_vect, to_vect), times=1)
```

Running this code, we get the following: *(only the fastest execution is shown)*

```
Unit: milliseconds
expr min
Expand Down Expand Up @@ -111,33 +114,43 @@ It's important to point out that **cache is disabled by default**. So, in order
```julia
julia> using BusinessDays, Dates

julia> BusinessDays.initcache(:USSettlement) # creates cache for US Federal holidays, allowing fast computations
# creates cache for US Federal holidays, allowing fast computations
julia> BusinessDays.initcache(:USSettlement)

julia> isbday(:USSettlement, Date(2015, 1, 1)) # Calendars can be referenced using symbols
# Calendars can be referenced using symbols
julia> isbday(:USSettlement, Date(2015, 1, 1))
false

julia> isbday("USSettlement", Date(2015, 1, 1)) # ... and also strings
# ... and also strings
julia> isbday("USSettlement", Date(2015, 1, 1))
false

julia> isbday(BusinessDays.USSettlement(), Date(2015, 1, 1)) # but for the best performance, use a singleton instance
# but for the best performance, use a singleton instance
julia> isbday(BusinessDays.USSettlement(), Date(2015, 1, 1))
false

julia> tobday(:USSettlement, Date(2015, 1, 1)) # Adjust to next business day
# Adjust to next business day
julia> tobday(:USSettlement, Date(2015, 1, 1))
2015-01-02

julia> tobday(:USSettlement, Date(2015, 1, 1); forward = false) # Adjust to last business day
# Adjust to last business day
julia> tobday(:USSettlement, Date(2015, 1, 1); forward = false)
2014-12-31

julia> advancebdays(:USSettlement, Date(2015, 1, 2), 1) # advances 1 business day
# advances 1 business day
julia> advancebdays(:USSettlement, Date(2015, 1, 2), 1)
2015-01-05

julia> advancebdays(:USSettlement, Date(2015, 1, 2), -1) # goes back 1 business day
# goes back 1 business day
julia> advancebdays(:USSettlement, Date(2015, 1, 2), -1)
2014-12-31

julia> bdays(:USSettlement, Date(2014, 12, 31), Date(2015, 1, 5)) # counts the number of business days between dates
# counts the number of business days between dates
julia> bdays(:USSettlement, Date(2014, 12, 31), Date(2015, 1, 5))
2 days

julia> bdayscount(:USSettlement, Date(2014, 12, 31), Date(2015, 1, 5)) # same as above, but returns integer
# same as above, but returns integer
julia> bdayscount(:USSettlement, Date(2014, 12, 31), Date(2015, 1, 5))
2

julia> isbday(:USSettlement, [Date(2014,12,31),Date(2015,1,1),Date(2015,1,2),Date(2015,1,3),Date(2015,1,5)])
Expand Down Expand Up @@ -245,10 +258,10 @@ the [MIT License](https://raw.githubusercontent.com/JuliaFinance/BusinessDays.jl

## Alternative Packages

* Ito.jl: http://aviks.github.io/Ito.jl/time.html
* [Ito.jl](http://aviks.github.io/Ito.jl/time.html)

* FinancialMarkets.jl: https://github.com/imanuelcostigan/FinancialMarkets.jl
* [FinancialMarkets.jl](https://github.com/imanuelcostigan/FinancialMarkets.jl)

* QuantLib.jl : https://github.com/pazzo83/QuantLib.jl
* [QuantLib.jl](https://github.com/pazzo83/QuantLib.jl)

* QuantLib C++ Library: https://github.com/lballabio/QuantLib
* [QuantLib C++ Library](https://github.com/lballabio/QuantLib)

0 comments on commit b3442ed

Please sign in to comment.