initial implementation
This commit is contained in:
commit
1078c49269
30 changed files with 2131 additions and 0 deletions
102
src/process/BrownianMotion.cpp
Normal file
102
src/process/BrownianMotion.cpp
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/* @file BrownianMotion.cpp */
|
||||
|
||||
#include "xo/reflect/TaggedPtr.hpp"
|
||||
//#include "time/Time.hpp"
|
||||
#include "BrownianMotion.hpp"
|
||||
#include <cmath>
|
||||
|
||||
namespace xo {
|
||||
using xo::time::utc_nanos;
|
||||
using xo::scope;
|
||||
using xo::xtag;
|
||||
|
||||
namespace process {
|
||||
double
|
||||
BrownianMotionBase::variance_dt(nanos dt) const
|
||||
{
|
||||
constexpr uint64_t c_sec_per_day = (24L * 3600L);
|
||||
constexpr double c_day_per_sec = (1.0 / c_sec_per_day);
|
||||
|
||||
/* time-to-horizon in nanos */
|
||||
double dt_sec = std::chrono::duration<double>(dt).count();
|
||||
double dt_day = dt_sec * c_day_per_sec;
|
||||
|
||||
return this->vol2_day_ * dt_day;
|
||||
} /*variance_dt*/
|
||||
|
||||
double
|
||||
BrownianMotionBase::exterior_sample_impl(utc_nanos t,
|
||||
BrownianMotionBase::event_type const & lo,
|
||||
double x0)
|
||||
{
|
||||
constexpr bool c_logging_enabled = false;
|
||||
|
||||
scope log(XO_DEBUG(c_logging_enabled));
|
||||
|
||||
/* sample brownian motion starting at t0;
|
||||
* offset by lo.second
|
||||
*/
|
||||
|
||||
utc_nanos lo_tm = lo.first;
|
||||
double lo_x = lo.second;
|
||||
|
||||
nanos dt = (t - lo_tm);
|
||||
|
||||
/* variance at horizon t, relative to value at lo.first */
|
||||
double var = this->variance_dt(dt);
|
||||
|
||||
/* scale for variance of B(t) - B(lo) */
|
||||
double dx = ::sqrt(var) * x0;
|
||||
|
||||
double sample = lo_x + dx;
|
||||
|
||||
log && log("result",
|
||||
xtag("start-time", this->t0()),
|
||||
xtag("vol2-day", this->vol2_day()),
|
||||
xtag("lo.tm", lo_tm),
|
||||
xtag("lo.x", lo_x),
|
||||
xtag("dt-us", std::chrono::duration_cast<std::chrono::microseconds>(dt).count()),
|
||||
xtag("var", var),
|
||||
xtag("dx", dx));
|
||||
|
||||
return sample;
|
||||
} /*exterior_sample_impl*/
|
||||
|
||||
// ----- BrownianMotion -----
|
||||
|
||||
#ifdef NOT_IN_USE
|
||||
utc_nanos
|
||||
BrownianMotion::hitting_time(double const & a,
|
||||
event_type const & lo)
|
||||
{
|
||||
/* (1)
|
||||
* probability density function p1(s)
|
||||
* giving hitting time for brownian motion starting at 0,
|
||||
* first time to reach a constant barrier a:
|
||||
*
|
||||
* a^2
|
||||
* - ---
|
||||
* a 2.s
|
||||
* p1(s) = ------------- . e
|
||||
* sqrt(2.pi.s^3)
|
||||
*
|
||||
* (2)
|
||||
* we also know probability density function p2(s)
|
||||
* giving hitting time for brownian motion starting at 0,
|
||||
* first time to reach expanding barrier a + ct:
|
||||
* (i.e. T2 = inf{t : B(t) = c.t + a, t > 0})
|
||||
*
|
||||
* (c.s + a)^2
|
||||
* - -----------
|
||||
* a 2.s
|
||||
* p2(s) = -------------- . e
|
||||
* sqrt(2.pi.s^3)
|
||||
*
|
||||
*/
|
||||
} /*hitting_time*/
|
||||
#endif
|
||||
|
||||
} /*namespace process*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end BrownianMotion.cpp */
|
||||
19
src/process/CMakeLists.txt
Normal file
19
src/process/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# xo-process/src/process/CMakeLists.txt
|
||||
|
||||
set(SELF_LIB process)
|
||||
set(SELF_SRCS
|
||||
BrownianMotion.cpp ExpProcess.cpp Realization.cpp UpxEvent.cpp UpxToConsole.cpp
|
||||
init_process.cpp)
|
||||
|
||||
xo_add_shared_library3(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# external dependencies
|
||||
|
||||
# note: changes to xo_dependency() calls here
|
||||
# must coordinate with find_dependency() calls
|
||||
# in xo-process/cmake/processConfig.cmake.in
|
||||
#
|
||||
xo_dependency(${SELF_LIB} reflect)
|
||||
#xo_dependency(${SELF_LIB} webutil)
|
||||
#xo_dependency(${SELF_LIB} callback)
|
||||
69
src/process/ExpProcess.cpp
Normal file
69
src/process/ExpProcess.cpp
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/* @file ExpProcess.cpp */
|
||||
|
||||
#include "xo/reflect/TaggedPtr.hpp"
|
||||
#include "xo/reflect/StructReflector.hpp"
|
||||
//#include "time/Time.hpp"
|
||||
#include "ExpProcess.hpp"
|
||||
|
||||
namespace xo {
|
||||
using reflect::Reflect;
|
||||
using reflect::StructReflector;
|
||||
using reflect::TaggedRcptr;
|
||||
using xo::scope;
|
||||
using xo::xtag;
|
||||
|
||||
namespace process {
|
||||
void
|
||||
ExpProcess::reflect_self()
|
||||
{
|
||||
StructReflector<ExpProcess> sr;
|
||||
|
||||
if (sr.is_incomplete()) {
|
||||
REFLECT_MEMBER(sr, scale);
|
||||
REFLECT_MEMBER(sr, exponent_process);
|
||||
}
|
||||
} /*self_reflect*/
|
||||
|
||||
/* note: lo is a sample from the exponentiated process;
|
||||
* must take log to get sample from the exponent process
|
||||
*/
|
||||
ExpProcess::value_type
|
||||
ExpProcess::exterior_sample(utc_nanos t,
|
||||
event_type const & lo)
|
||||
{
|
||||
constexpr bool c_logging_enabled = false;
|
||||
|
||||
scope log(XO_DEBUG(c_logging_enabled));
|
||||
|
||||
double lo_value = lo.second;
|
||||
double log_lo_value = ::log(lo.second / this->scale_);
|
||||
|
||||
double e
|
||||
= (this->exponent_process_->exterior_sample
|
||||
(t,
|
||||
event_type(lo.first, log_lo_value)));
|
||||
|
||||
double retval = this->scale_ * ::exp(e);
|
||||
|
||||
log && log("result",
|
||||
xtag("t", t),
|
||||
xtag("lo.tm", lo.first),
|
||||
xtag("lo.value", lo_value),
|
||||
xtag("log(lo.value/m)", log_lo_value),
|
||||
xtag("m", this->scale_),
|
||||
xtag("e", e),
|
||||
xtag("retval", retval));
|
||||
|
||||
return retval;
|
||||
} /*exterior_sample*/
|
||||
|
||||
TaggedRcptr
|
||||
ExpProcess::self_tp()
|
||||
{
|
||||
return Reflect::make_rctp(this);
|
||||
} /*self_tp*/
|
||||
|
||||
} /*namespace process*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end ExpProcess.cpp */
|
||||
5
src/process/Realization.cpp
Normal file
5
src/process/Realization.cpp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/* Realization.cpp */
|
||||
|
||||
#include "Realization.hpp"
|
||||
|
||||
/* end Realization.cpp */
|
||||
45
src/process/UpxEvent.cpp
Normal file
45
src/process/UpxEvent.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* @file UpxEvent.cpp */
|
||||
|
||||
#include "UpxEvent.hpp"
|
||||
#include "xo/reflect/StructReflector.hpp"
|
||||
#include "xo/indentlog/scope.hpp"
|
||||
#include "xo/indentlog/print/tag.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::reflect::StructReflector;
|
||||
using xo::tostr;
|
||||
using xo::xtag;
|
||||
|
||||
namespace process {
|
||||
UpxEvent::UpxEvent() = default;
|
||||
|
||||
void
|
||||
UpxEvent::reflect_self()
|
||||
{
|
||||
StructReflector<UpxEvent> sr;
|
||||
|
||||
if (sr.is_incomplete()) {
|
||||
//REFLECT_MEMBER(sr, contents);
|
||||
REFLECT_MEMBER(sr, tm);
|
||||
REFLECT_MEMBER(sr, upx);
|
||||
}
|
||||
} /*reflect_self*/
|
||||
|
||||
void
|
||||
UpxEvent::display(std::ostream & os) const
|
||||
{
|
||||
os << "<UpxEvent"
|
||||
<< xtag("tm", this->tm())
|
||||
<< xtag("x", this->upx())
|
||||
<< ">";
|
||||
} /*display*/
|
||||
|
||||
std::string
|
||||
UpxEvent::display_string() const {
|
||||
return tostr(*this);
|
||||
} /*display_string*/
|
||||
|
||||
} /*namespace process*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end UpxEvent.cpp */
|
||||
15
src/process/UpxToConsole.cpp
Normal file
15
src/process/UpxToConsole.cpp
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/* @file UpxToConsole.cpp */
|
||||
|
||||
#include "UpxToConsole.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace process {
|
||||
ref::rp<UpxToConsole>
|
||||
UpxToConsole::make()
|
||||
{
|
||||
return new UpxToConsole();
|
||||
} /*make*/
|
||||
|
||||
UpxToConsole::UpxToConsole() = default;
|
||||
} /*namespace process*/
|
||||
} /*namespace xo*/
|
||||
40
src/process/init_process.cpp
Normal file
40
src/process/init_process.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* file init_process.cpp
|
||||
*
|
||||
* author: Roland Conybeare, Sep 2022
|
||||
*/
|
||||
|
||||
#include "init_process.hpp"
|
||||
#include "xo/printjson/init_printjson.hpp"
|
||||
|
||||
#include "UpxEvent.hpp"
|
||||
#include "xo/subsys/Subsystem.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::process::UpxEvent;
|
||||
|
||||
void
|
||||
InitSubsys<S_process_tag>::init()
|
||||
{
|
||||
UpxEvent::reflect_self();
|
||||
} /*init*/
|
||||
|
||||
InitEvidence
|
||||
InitSubsys<S_process_tag>::require()
|
||||
{
|
||||
InitEvidence retval;
|
||||
|
||||
/* direct subsystem dependencies for process/
|
||||
*
|
||||
* UpxEventStore --uses-> printjson (via reactor/EventStore.hpp)
|
||||
*/
|
||||
retval ^= InitSubsys<S_printjson_tag>::require();
|
||||
|
||||
/* process/'s own initialization code */
|
||||
retval ^= Subsystem::provide<S_process_tag>("process", &init);
|
||||
|
||||
return retval;
|
||||
} /*require*/
|
||||
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end init_process.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue