-
Notifications
You must be signed in to change notification settings - Fork 156
/
TSSWStochastic.h
63 lines (51 loc) · 2.17 KB
/
TSSWStochastic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/************************************************************************
* Copyright(c) 2011, One Unified. All rights reserved. *
* email: [email protected] *
* *
* This file is provided as is WITHOUT ANY WARRANTY *
* without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* This software may not be used nor distributed without proper license *
* agreement. *
* *
* See the file LICENSE.txt for redistribution information. *
************************************************************************/
#pragma once
#include <functional>
#include "RunningMinMax.h"
#include "TimeSeriesSlidingWindow.h"
namespace ou { // One Unified
namespace tf { // TradeFrame
// 14,3,1 is standard 14 periods, 3 slow average, 1 fast average
// TODO: implement the averaging
// TODO: implement CRTP?
class TSSWStochastic:
public RunningMinMax<TSSWStochastic,double>,
public TimeSeriesSlidingWindow<TSSWStochastic, Quote>
{
friend RunningMinMax<TSSWStochastic,double>;
friend TimeSeriesSlidingWindow<TSSWStochastic, Quote>;
public:
using fK_t = std::function<void( ptime, double, double, double)>; // ptime, indicator, min, max
TSSWStochastic( Quotes& quotes, time_duration tdWindowWidth );
TSSWStochastic( Quotes& quotes, size_t nPeriods, time_duration tdPeriodWidth, fK_t&& );
virtual ~TSSWStochastic();
double K() const { return m_k; };
double Size() const;
void Reset();
protected:
void Add( const Quote& quote );
void Expire( const Quote& quote );
//void PostUpdate();
private:
bool m_bAvailable;
double m_lastAdd;
double m_lastExpire;
double m_k;
ptime m_dtLatest;
fK_t m_fK;
void UpdateOnAdd( double min, double max );
};
} // namespace tf
} // namespace ou