2017年1月28日 星期六

函數(_MonthlyProfit):過去第N個月的當月損益


這一篇文章根本就是用過去的一篇來做的修改,算是相同邏輯下的不同週期切割而已。

做個函數來取得以月為單位的損益數值。
函數名稱:_MonthlyProfit,參數 為 monthsAgo。參數輸入 0 可取得這個月的損益變化,輸入 1 則是上個月,2 則是上上個月... and so on。

函數(
數值、序列)程式碼如下:
input: monthsAgo(Numeric);
var: equity(0);
array: monthEquity[](0);


equity= i_OpenEquity;
array_setmaxindex(monthEquity, monthsAgo+1);


if month(D)<>month(D)[1] then
begin
  _arrayShift(monthEquity);
  monthEquity[1]= equity[1];
end;


if monthsAgo=0 then
  _monthlyProfit = equity - monthEquity[1]
else
  _monthlyProfit = monthEquity[monthsAgo] - monthEquity[monthsAgo+1];


效果:


熱門文章