量化交易之One Piece篇 - signals - SizeSignal.h & SizeSignal.cc

// SizeSignal.h

#pragma once

#include 
#include 

class SizeSignal
{
public:
    SizeSignal() = delete;

    SizeSignal(unsigned int windows);

    ~SizeSignal();

    void UpdateTick(TickSPtr tickSPtr);

    int SumBidSize();
    int SumAskSize();
    int SumDiff();
    int SumVolume();

    double AvgBidSize();
    double AvgAskSize();
    double AvgDiff();
    double AvgVolume();

    bool Check();

private:
    unsigned int m_windows;

    queue m_ticks;

    int m_sumBidSize;
    int m_sumAskSize;
    int m_sumVolume;

    bool m_isOk;
};

// SizeSignal.cc

#include 

SizeSignal::SizeSignal(unsigned int windows): m_windows(windows), m_isOk(false) {

}


SizeSignal::~SizeSignal() {
    while (!this->m_ticks.empty()) {
        this->m_ticks.pop();
    }
}

void SizeSignal::UpdateTick(TickSPtr tickSPtr) {
    if (this->m_ticks.size() < this->m_windows) {
        this->m_ticks.push(tickSPtr);
        this->m_sumAskSize += tickSPtr->AskSize();
        this->m_sumBidSize += tickSPtr->BidSize();
        this->m_sumVolume += tickSPtr->Volume();

        this->m_isOk = false;
        return;
    }

    this->m_ticks.push(tickSPtr);
    this->m_sumAskSize += tickSPtr->AskSize();
    this->m_sumBidSize += tickSPtr->BidSize();
    this->m_sumVolume += tickSPtr->Volume();

    TickSPtr firstTickSPtr = this->m_ticks.front();

    this->m_sumAskSize -= firstTickSPtr->AskSize();
    this->m_sumBidSize -= firstTickSPtr->BidSize();
    this->m_sumVolume -= firstTickSPtr->Volume();
    this->m_ticks.pop();

    this->m_isOk = true;
}


int SizeSignal::SumAskSize() {
    return this->m_sumAskSize;
}
int SizeSignal::SumBidSize() {
    return this->m_sumBidSize;
}

int SizeSignal::SumDiff() {
    return this->m_sumBidSize - this->m_sumAskSize;
}
int SizeSignal::SumVolume() {
    return this->m_sumVolume;
}

double SizeSignal::AvgBidSize() {
    return (0 != this->m_windows) ? (this->m_sumBidSize / this->m_windows) : 0;
}
double SizeSignal::AvgAskSize() {
    return (0 != this->m_windows) ? (this->m_sumAskSize / this->m_windows) : 0;
}

double SizeSignal::AvgDiff() {
    return (0 != this->m_windows) ? (this->SumDiff() / this->m_windows) : 0;
}
double SizeSignal::AvgVolume() {
    return (0 != this->m_windows) ? (this->SumVolume() / this->m_windows) : 0;
}

bool SizeSignal::Check() {
    return this->m_isOk;
}

你可能感兴趣的:(One,Piece,c++,one,piece,linux)