xo-unit: ex6: volatility example with scale conversion
This commit is contained in:
parent
e09c6670bd
commit
b5b6485c2c
2 changed files with 29 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 <iostream>
|
||||
|
||||
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<u::microsecond>();
|
||||
auto t1_sec = t1.with_unit<u::second>();
|
||||
/* 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<nu::volatility_360d> 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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue