-
Notifications
You must be signed in to change notification settings - Fork 7
/
PPO.cpp
executable file
·45 lines (33 loc) · 1.34 KB
/
PPO.cpp
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
/***************************************************************************
* (c) 2008-2011 Aleksandar Topuzović *
* <[email protected]>, <[email protected]> *
***************************************************************************/
#include "beagle/GP.hpp"
#include "PPO.hpp"
#include "ta.hpp"
#include <sstream>
#include <cmath>
#include <fstream>
using namespace Beagle;
// Primitive name: PPO
PPO::PPO() : Beagle::GP::Primitive(0, "PPO")
{ }
#ifdef BEAGLE_HAVE_RTTI
// Return value type: double
const std::type_info* PPO::getReturnType(Beagle::GP::Context& ioContext) const
{
return &typeid(Double);
}
#endif // BEAGLE_HAVE_RTTI
// Percentage Price Oscillator (PPO)
// PPO = (12-day EMA - 26-day EMA)/ 26-day EMA * 100
void PPO::execute(GP::Datum& outDatum, GP::Context& ioContext)
{
Double& lResult = castObjectT<Double&>(outDatum);
trading::Context& aContext = castObjectT<trading::Context&>(ioContext);
double ema_12_day = ema(aContext.database, aContext.dionica, aContext.datum, 12 );
double ema_26_day = ema(aContext.database, aContext.dionica, aContext.datum, 26 );
// std::cout << "12day: " << ema_12_day << ", 26day: " << ema_26_day << std::endl;
lResult = (ema_12_day - ema_26_day) / ema_26_day * 100;
// std::cout << "PPO: " << lResult << std::endl;
}