量化交易之hft篇 - alpha因子 (MaAlpha)
原创
©著作权归作者所有:来自51CTO博客作者ErwinSmith的原创作品,请联系作者获取转载授权,否则将追究法律责任
#pragma once
#include <stdint.h>
//#include <vector>
#include "../../Includes/WTSDataDef.hpp"
USING_NS_OTP;
namespace hftalphas {
typedef unique_ptr<vector<WTSTickData>> TicksUPtr;
class MaAlpha {
public:
MaAlpha() = default;
~MaAlpha() = default;
public:
static int32_t alphaValue(const TicksUPtr& ticks, const uint32_t length, const uint32_t unitValue = 1);
};
}
#include "TQZHftMa.h"
#include <iostream>
namespace hftalphas {
int32_t MaAlpha::alphaValue(const TicksUPtr& ticks, const uint32_t length, const uint32_t unitValue) {
if (!ticks->size())
return 0;
if (ticks->size() < length)
return 0;
double sumValue(0);
size_t beginIndex(ticks->size() - length);
for (size_t i(beginIndex); i < static_cast<size_t>(ticks->size()); i++)
sumValue += ticks->at(i).price();
double maValue(sumValue / length);
int32_t alphaValue(0);
WTSTickData lastTick = ticks->at(ticks->size() - 1);
if (lastTick.price() > maValue)
alphaValue = unitValue;
else if (lastTick.price() < maValue)
alphaValue = -1 * unitValue;
return alphaValue;
}
}