在C++中使用指数移动平均线对 P&Q 规则进行编码
Coding the P&Q rule using Exponential Moving Average in C++
我正在开发一个使用C++作为练习的小型交易机器人。他将首先收到基本信息,如我们的资本和日常股票价值(以迭代表示)。
这是我的Trade
类:
class Trade
{
private:
int capital_;
int days_; // Total number of days of available stock prices
int daysInTrading_; // Increments as days go by.
std::list<int> stockPrices_; // Contains stock prices day after day.
int currentStock_; // Current stock we are dealing with.
int lastStock_; // Last stock dealt with
int trend_;
int numOfStocks_; // Amount of stock options in our possession
float EMA_; // Exponential Moving Average
float lastEMA_; // Last EMA
public:
// functions
};
正如你从最后两个属性中可以看出的那样,我使用的是指数移动平均原理和趋势跟踪算法。
我在这篇论文里读到了这件事http://www.cis.umac.mo/~fstasp/paper/jetwi2011.pdf(主要在第3页),并希望实现他们与我们共享的伪代码;它是这样的:
Repeat
Compute EMA(T)
If no position opened
If EMA(T) >= P
If trend is going up
Open a long position
Else if trend is going down
Open a short position
Else if any position is opened
If EMA(¬T) >= Q
Close position
If end of market
Close all opened position
Until market close
到目前为止,我是这样做的:
void Trade::scanTrend()
{
if (this->numOfStocks_ == 0) // If no position is opened
{
this->EMA_ = this->calcEMA(); // Calculates the EMA
if (this->EMA_ >= this->currentStock_) // If EMA(T) >= P
{
if (this->EMA_ > this->lastEMA_) // If trend is going up
// Trend is going up, open a long position
else if (this->EMA_ < this->lastEMA_) // If trend is going down
// Trend is going down, open a short position
}
}
else // Else if any position is opened
{
this->EMA_ = this->calcEMA();
// How may I represent closing positions?
}
this->lastEMA_ = this->EMA_;
}
我的问题来自于不理解"打开"answers"关闭"一个职位的行为。这和买卖股票有关系吗?到目前为止,我所拥有的似乎与伪代码相符吗?
p将是第一次观测和当前观测之间的变化。如果P是正的,那么你可以假设P<0.
Q也是EMA的一个变化,但用于知道何时平仓,它是第一次观察的最高(最低)EMA值与当前上升(下降)趋势的EMA值之间的差值。
相关文章:
- 如何确定我已使用非编码文件到达 EOF?
- 此代码是否违反一个定义规则
- 生成文件不对文件使用隐式规则
- 变量可能尚未初始化[MIRA 2012规则9.1,强制性]
- 静态结构和一个定义规则
- 使用 MATLAB 编码器生成C++代码:编译错误"undefined reference to `rgb2gray_tbb_real64'"
- 在卡萨布兰卡形成编码参数的列表
- 尽管遵循了规则,内存泄漏在哪里
- 使用C++进行游程编码
- 如何将不同的可执行文件合并到一个窗口框架中进行编码?像浏览器一样
- 使用已使用 java 编码的 openssl 解码数据
- 这是关于成员访问规则的正确摘要吗
- uint_not_usable_without_attribute在业力规则中使用数字生成器时静态断言失败
- 增强精神解析器规则以检测语句中的特殊结尾
- boost 是否有按特殊类型值编码状态"compact optional"?
- 如何在CPP的给定目录中列出UTF编码的文件名?
- 在C++中使用指数移动平均线对 P&Q 规则进行编码
- 联合攻击战斗机(JSF)的排名C++编码标准的强制性规则
- 谷歌C++编码风格,没有例外规则.多线程呢?
- F-35飞行器C++编码标准AV规则6的澄清;文件.编号2RDU00001修订版C