Hello everyone,
i've a problem that i can't solve: i've implemented some monthly strategies that use monthly bars. Now i want print the daily equity value of my backtest: i've created a AMM script that catch this value and relative date for every OnEndPeriod anche append it on csv file.
But if i set monthly time frame, the end of period is monthly and i can't print daily equity.
Than i think to adapt the backtest rule to use daily bars, but there is a problem: now i calculate every value using monthly time frame and, for example, if i want performance at 4 months i've "returnA = performance(close, 4);". If i convert the time frame from monhtly to daily, how can i write a code that use only the daily bars included in this 4 months?
I saw that many users use to aproximate one monthly bar to 21 daily bars (than, for performance at 4 months, use "returnA = performance (close, 4*21);" ), but this isn't correct and the result isn't comparable with the same code that use monthly time frame although in both systems i use rebalance every month.
I'm searching a solution that return the same result of monthly time frame or return me the daily equity value usin monthly time frame.
Hi QuantShare, thanks for your replay. I tried your solution, but i'm not sure that it works.
I opened a chart, i setted "monthly" timeframe in the chart to plot the function:
a = roc(4);
plot( a, "performance", colorRed);
For each bar, i wrote the value returned on the pane (for may '16, the bar was 2016/05/01).
I setted "daily" timeframe and i've plotted the function that have you posted and i've compared the value on the last bar of each month (such as, on may '16, the bar on the 2016/05/31) with the value earlier writed and they didn't correspond.
For example, if i set "MDY" ETF i obtain this result
performance at 4 months with monthly bars on 2016/05/01 - 13,2725
performance at 4 months with daily bars on 2016/05/31 - 3,73
Sorry there was a typo. The second parameter of the "timeframeapply" is the time frame.
It should be:
a = timeframedecompress(timeframeapply(31, roc(4))); //365 for yearly, 31 for monthly, 7 for weekly
Hi, now it works! I've tried your solution and the backtest based on monthly timeframe and daily trimeframe return the same result.
I'm not undestrading why some values aren't alike: Initial Cap and Net Profit are the same, the Yearly performance year by year are the same, but Drawdown and Annual Return are different (i think Sortino, Ulcera etc... not correspond because drawdown and annual return are different). The order flow is the same. Them are the result http://s33.postimg.org/699vh27b3/result.png
Have you some idea about?
Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.