xo-unit: example: + ex4 .. ex6

This commit is contained in:
Roland Conybeare 2024-04-03 17:25:20 -04:00
commit ba31d2c112
7 changed files with 116 additions and 0 deletions

View file

@ -0,0 +1,15 @@
# xo-unit/example/ex5/CMakeLists.txt
set(SELF_EXE xo_unit_ex5)
set(SELF_SRCS ex5.cpp)
add_executable(${SELF_EXE} ${SELF_SRCS})
xo_include_options2(${SELF_EXE})
# ----------------------------------------------------------------
# dependencies..
xo_self_dependency(${SELF_EXE} xo_unit)
xo_dependency(${SELF_EXE} reflect)
# end CMakeLists.txt

23
example/ex5/ex5.cpp Normal file
View file

@ -0,0 +1,23 @@
/** @file ex5.cpp **/
#include "xo/unit/quantity.hpp"
#include <iostream>
int
main () {
namespace u = xo::unit::units;
namespace qty = xo::unit::qty;
using namespace std;
/* 20% volatility over 250 days (approx number of trading days in one year) */
auto q1 = qty::volatility250d(0.2);
/* 10% volatility over 30 days */
auto q2 = qty::volatility30d(0.1);
auto sum = q1 + q2;
auto prod = q1 * q2;
cerr << "q1: " << q1 << ", q2: " << q2 << ", q1+q2: " << sum << ", q1*q2: " << prod << endl;
}
/** end ex5.cpp */