-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathTSSWRealizedVolatility.h
56 lines (48 loc) · 2.36 KB
/
TSSWRealizedVolatility.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
/************************************************************************
* Copyright(c) 2012, 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 <OUCommon/Delegate.h>
#include "TimeSeriesSlidingWindow.h"
namespace ou { // One Unified
namespace tf { // TradeFrame
// calculation from Intro HF Finance, pg 41
// page 43 has another version of realized volatility as the standard deviation fo the returns about the sample mean
// which is not implemented here, due to extra computational complexity, but may have a viable solution based upon subsequent formulae
// the book indicates that Realized Volatility should be computed from a homogenous time series (top of page 44)
// delta T should be 15min to 2hr
class TSSWRealizedVolatility:
public TimeSeriesSlidingWindow<TSSWRealizedVolatility, Price>,
public Prices
{
friend TimeSeriesSlidingWindow<TSSWRealizedVolatility, Price>;
public:
TSSWRealizedVolatility( Prices& prices, time_duration tdWindowWidth, double p );
~TSSWRealizedVolatility( void );
void SetScaleFactor( time_duration tdScaledWidth ) { m_tdScaledWidth = tdScaledWidth; CalcScaleFactor(); };
time_duration GetScaleFactor( void ) { return m_tdScaledWidth; };
protected:
void Add( const Price& price );
void Expire( const Price& price );
void PostUpdate( void );
private:
unsigned int m_n;
double m_dblSum;
double m_dblP;
ptime m_dt;
time_duration m_tdScaledWidth;
double m_dblScaleFactor;
void CalcScaleFactor( void );
};
} // namespace tf
} // namespace ou