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