diff --git a/example/ex6/CMakeLists.txt b/example/ex6/CMakeLists.txt index 2b933f7d..ce583825 100644 --- a/example/ex6/CMakeLists.txt +++ b/example/ex6/CMakeLists.txt @@ -10,6 +10,6 @@ xo_include_options2(${SELF_EXE}) # dependencies.. xo_self_headeronly_dependency(${SELF_EXE} xo_unit) -#xo_dependency(${SELF_EXE} reflect) +xo_dependency(${SELF_EXE} xo_flatstring) # end CMakeLists.txt diff --git a/example/ex6/ex6.cpp b/example/ex6/ex6.cpp index a3e7b723..3775cf3d 100644 --- a/example/ex6/ex6.cpp +++ b/example/ex6/ex6.cpp @@ -1,19 +1,39 @@ /** @file ex6.cpp **/ -#include "xo/unit/mpl/quantity.hpp" +#include "xo/unit/quantity.hpp" +#include "xo/unit/quantity_iostream.hpp" +#include "xo/flatstring/int128_iostream.hpp" #include int main () { - namespace u = xo::unit::units; - namespace qty = xo::unit::qty; - using namespace std; + using xo::qty::quantity; + namespace q = xo::qty::qty; + using xo::flatstring; - auto t1 = qty::milliseconds(25.0); - auto t1_usec = t1.with_unit(); - auto t1_sec = t1.with_unit(); + /* 20% volatility over 360 days */ + auto q1 = q::volatility_360d(0.2); + /* 10% volatility over 30 days */ + auto q2 = q::volatility_30d(0.1); - cerr << "t1: " << t1 << ", t1_usec: " << t1_usec << ", t1_sec: " << t1_sec << endl; + //quantity q2p = q2; + + /* 10% volatility per 30 days + * ~ (10% * sqrt(360/30)) volatility over 360 days + * ~ (10% * 3.4641) + * ~ 0.34641yr360^(-1/2) + */ + + auto sum = q1 + q2; + auto prod = q1 * q2; + + static_assert(sum.abbrev() == flatstring("yr360^(-1/2)")); + static_assert(prod.abbrev() == flatstring("yr360^-1")); + + std::cerr << "q1: " << q1 << std::endl; + std::cerr << "q2: " << q2 << std::endl; + std::cerr << "q1+q2: " << sum << std::endl; + std::cerr << "q1*q2: " << prod << std::endl; } /** end ex6.cpp */