Re: [amibroker] Re: AIRAP - fitness function
Hi Scott -- If by edge you mean expectancy, then it is well understood as being very important and often discussed in this forum. Or do you have a different, and quantifiable, definition of edge? Thanks, Howard On Wed, Sep 8, 2010 at 9:48 AM, sdwcyberdude scwalker1...@gmail.com wrote: Good points. I strive to spend 90% of my focus on deriving and measuring the underlying edge, why does it exist, when did it exist does it still exist, how is it captured + measured. Last 10% is spent on the system metrics, etc. The big dog, The Edge, seems not to be discussed very much by many people. Regards, Scott --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, tf28373 tom...@... wrote: I strongly agree. This is the moment when Ulcer Performance Index steps in - check this one out, since it is based on measuring risk in the terms of drawdown regarding its duration. By the way thanks for your comments about Omega - it seems that on the one hand AIRAP can add something positive into system performance analysis, on the other - it has some drawbacks. Anyway my mind is still overoccupied by the idea of deriving the system virtues and equity line features from simple mean - deviation analysis (together with using such indicators like profit factor, power factor, expectation). Have you ever ponder on this one? --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, sdwcyberdude scwalker1986@ wrote: Tomasz, I also use and see value in the Max DD, however, I believe it is should only be a secondary measure. Think of a 10 year backtest. System X has 1 drawdown of 30% (max), and many small drawdown never exceeding 5%. System Y has 1 drawdown of 25% (max), and 10+ other drawdowns between 20 and 23%. Which system is more stable? I will invest risk capital in System X, which has the higher max drawdown, but much fewer drawdowns of depth. I would love to have a measure of drawdown that more directly and intuitively measures the depth and frequency of drawdowns per unit of time. Correlation of the equity curve also gets at that point. Regarding the Omega, I am relying on a friend who studied both the advanced math and models and uncover significant concerns with the Omega (I seem to recall in was bias issues around skewness and kurtosis, but I might be wrong), however it was unpublished work for hedge funds. He also developed a proprietary alternative. Sorry I can't be more helpful on that one. Kind Regards, Scott --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, tf28373 tomfid@ wrote: Hi Scott Thanks for response. I agree that the Sortino ratio is a kind of solution to the typical Sharp ratio disadvantages (like penalization high moments, which for me is irrational). Nevertheless, there is no max dd taken into account, which confuses me a bit. However, I might be too devoted to this risk measure (max dd) - what do you think? Is mean and its variance better/sufficient values as far as the characteristics of equity line is considered? (This is what brain123 was supporting in many discussions.) One should be careful if it is built upon the Omega, which I believe introduces other problems. That is an interesting point - can you elaborate a bit on this one? In fact I was hoping to get this kind of information when starting this thread as - frankly speaking - I don't feel familiar with plain maths enough to analyse it... Looking forward to your response. Regards Tomasz --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, sdwcyberdude scwalker1986@ wrote: Tomasz, Thanks for raising this question (and for the good work you do). The Sortino Ratio is a well regarding improvement upon the Sharpe; I urge you to consider adding the Sortino to the base metric array. Is there a reason you passed on it earlier? The Sharpe ratio has a lot of problems and I was not familiar with the AIRAP. One should be careful if it is built upon the Omega, which I believe introduces other problems. Regards, Scott --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, tf28373 tomfid@ wrote: Hello everyone I have been working on the choose of fitness function following the Howard Bundy's advices in his Quantitative Trading Systems and come across M. Sharma's Alternative Investments Risk Adjusted Performance (AIRAP). The equation of it is as following: AIRAP = [ E pi*(1+TRi)(1-c) ] 1/(1-c) - 1, where TRi - ith period total fund return (in my opinon it can also be ith trade net return), c - risk aversion parameter (author suggests to set its value to c=4), i=1,...,N - number of periods (as for me it can be number of trades), pi - the probability of the ith period's total return
Re: [amibroker] double sort
Hi tstudent -- Your question does not say how you will be using the result. If it will be assigned to ProfitScore, try this: rrr = rsi; // however you do this ret = weeklyreturn; // however you do this PositionScore = 1000*rrr + ret; // adjusted as necessary so the numbers come out with the meaning you want PositionScore will be sorted in order of rrr, with ties broken by ret. Thanks, Howard On Mon, Sep 6, 2010 at 12:55 PM, tstudent tstud...@gmail.com wrote: How i do a double sort? For example i want give a priority to: 1) stocks with worst rsi 2) sort stocks within point one for best 1 week return Thanks
Re: [amibroker] Re: Req afl code for SAR use in best way for intraday trading
Hi Ford -- Backtesting is important. In-sample backtesting results have no relation to future performance. Out-of-sample testing is the only way to get an estimate of future performance. Look for the 60% in out-of-sample runs. Thanks for listening, Howard On Sun, Sep 5, 2010 at 7:33 AM, ford7k for...@yahoo.com wrote: Hi Reinsley many thanks for the code. Now I will try to test this manually. then try backtesting if it suits to find statistical success rate(if above 60%,i will use it). regards ford --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, reinsley reins...@... wrote: |// sar TS accel = Param(Acceleration, 0.02, 0, 1, 0.001); mx = Param(Max. acceleration, 0.2, 0, 1, 0.001); f_sar = SAR(accel,mx); colordots = IIf(f_sar *L*,*colorBrightGreen*,IIf(f_sar *H*,*colorRed*,*colorWhite*)); *Buy* = Cross(*C*,f_sar); *Buy* = Ref(*Buy*,-1); *BuyPrice* = *O*; *Sell* = Cross(f_sar,*C*); *Sell* = Ref(*Sell*,-1); *SellPrice* = *O*; SetBarsRequired(-2,-2); SetChartOptions(0, *chartShowDates*); Plot(*C*,\nClose,*colorWhite*,64); Plot(f_sar,\nf_sar,colordots,*styleDots*|*styleNoLine*); PlotShapes(IIf(*Buy*,*shapeUpArrow*,*shapeNone*),*colorGreen*,0,*L*,-15); PlotShapes(IIf(*Buy*,*shapeHollowUpArrow*,*shapeNone*),*colorWhite*,0,*L*,-15); PlotShapes(IIf(*Buy*,*shapeHollowSmallCircle*,*shapeNone*),*colorWhite*,0,*BuyPrice*,0); PlotShapes(IIf(*Sell*,*shapeDownArrow*,*shapeNone*),*colorRed*,0,*H*,-15); PlotShapes(IIf(*Sell*,*shapeHollowDownArrow*,*shapeNone*),*colorWhite*,0,*H*,-15); PlotShapes(IIf(*Sell*,*shapeHollowSmallCircle*,*shapeNone*),*colorWhite*,0,*SellPrice*,0);| Le 04/09/2010 14:47, ford7k a écrit : Hi afl experts, Can somebody kindly provide me the afl code for using SAR for intraday trading. Does it help to combine SAR with any other indicator for better results? thanks ford
Re: [amibroker] State of Advanced Amibroker (again)
Hi Frank -- Yes, it is possible. I completed a large project that was taking a lot of my time and competing with work on Advanced AmiBroker. I'll try to finish writing in time for the editors and printers to finish their portions, then get the book to me before Christmas. Thanks, Howard On Sat, Sep 4, 2010 at 2:54 AM, frankphd_us frankphd...@yahoo.com wrote: Hi Howard, any chance for christmas? Thanks and regards frankphd_us
Re: [amibroker] Dynamic volatility based profittarget
Hi Zozu -- If you want a profit target of, say, 2.5 percent, the ApplyStop statement wants a positive 2.5 for the third argument. (See the help files or reference manual.) Plot the array ProfitTarget to see what the values being computed by the ROC statement are. Multiply that array by whatever factor is required to give you the amount of profit target you want to use. Thanks, Howard On Thu, Sep 2, 2010 at 6:07 AM, zozuzoza zoz...@gmail.com wrote: Hi, Does anyone have an idea how to implement dynamic, volatility based profittarget? When the instrument drops more, the profittarget is higher. I tried the following but it does not work. ProfitTarget= -ROC(15); ApplyStop(stopTypeProfit,stopModePercent,ProfitTarget,1,True,0 ); Thanks, Zozu
Re: [amibroker] Looking for a suitable Intraday data supplier
Hi Bing -- If the data need not be accurate, why bother collecting it -- just set up a random number generator to make it up. (Grin) Even though you need only snapshot data, I recommend that you use data supplied by a data vendor (as compared with a broker). I use DTNIQ and like it. eSignal is well regarded also. Both have interfaces to AmiBroker that will bring the data in automatically. You can run the AmiBroker program to collect and post the data with a real-time refresh interval or a run every time set to 30 minutes. Thanks, Howard On Thu, Aug 26, 2010 at 5:34 AM, bingk66 bing.k...@optusnet.com.au wrote: Hi all, I am looking for a intra day data supplier for US stocks. Basically my requirements are as follows. 1) I am looking for snapshot data for these stocks at regular intervals (say 30mins). In between those intervals, I am not interested in any sort of pricing whatsoever. 2) The pricing obtained at those intervals need not be very accurate. 3) The key requirement for me is that at those predefined intervals, I would like to collect the snapshot pricing for a large number of stocks. The code will read from a csv file which contains a large number of tickers and will loop through each ticker collecting its snapshot price. It is possible that the csv file can contain up to 200 tickers, so the data supplier will need to be able to provide timely request for snaphot data for these large number of tickers in a short space of time. I understand that esignal is very good, and could probably do the job. However, I understand that esignal will backfill the data, which is probably a good thing, but it is not something that I require, as I am really only looking for snapshot data at specified times and nothing else. Any suggestions ??
Re: [amibroker] AFL Query
Hi Meg -- Are there bars where the price changes 1% in one minute? Try lower the size of the change required to trigger the signal. Thanks, Howard On Sun, Aug 22, 2010 at 9:22 AM, Meg Nath meg.s...@gmail.com wrote: Hi All, I was trying to generate an AFL which indicated buy signals when there is a 1% change b/w the close price of adjacent bars in an 1 minute chart. It worked in EOD data but failed in 1minute data please help. Code is written below! thanks in advance _SECTION_BEGIN(Unnamed 17); for(i=0;iBarCount-1;i++) { a=Close[i]; b=Close[i+1]; Ca=b-a; d=.01*a; if(Cad) { Buy1=Close[i+1]; Buy=Buy1; } } _SECTION_END();
Re: [amibroker] what is the difference between these two code lines
Hi Ford -- Mubashar is correct. To expand a little on what he wrote -- The expression C EMA(C,13) defines a condition known as a level. The level is 1 (or, equivalently, True) for every bar where the Close of that bar is greater than the 13 period exponential moving average computed using the closing prices. The level is 0 (or False) for every bar where the Close is not greater. The expression Cross(C,EMA(C,13) defines a condition known as an impulse. The impulse is 1 on only those bars where the Close was less than the 13 bar EMA on the previous bar and is greater than the 13 bar EMA on the current bar. Trading system logic can use either levels or impulses. A common use of a level is as an overall market filter. For example, AllowLongs = CEMA(C,120); A common use of an impulse is as an entry or exit trigger. For example, BuySignal = Cross(C,EMA(C,13)); The two are combined to create an entry. Buy = AllowLongs AND BuySignal; AllowLongs will be true for many bars -- all of those bars where you are willing to take long positions. BuySignal will be true on only those bars where the closing price crosses up through the moving average. The Buy will be on the bars where the crossing takes place, provided AllowLongs is 1 or True. If you plot AllowLongs, you will see the level change from 0 to 1 and maintain that value for many bars. If you plot BuySignal, you will see the impulse on the single bars where the crossing takes place. Thanks, Howard On Sat, Aug 21, 2010 at 12:20 PM, Mubashar Virk mvir...@gmail.com wrote: Both lines cover the the latest/or the last cross. First line buys if/when(ever) Close is greater than 13- bar EMA of the Close. Second lines buys when close last crossed over the 13-bar EMA of the Close. If you are looking for the last cross only then use second line. On 8/21/2010 10:34 PM, kin ford7 wrote: hi friends what is difference between buy signals below given buy = c ema(c,13); or buy =cross(c,ema(c,13); To get latest cross over which is better please help ford
Re: [amibroker] Re: customized walk forward backtesting possible?
Hi Ade -- I may be misunderstanding, but I don't see that CBT will be involved. I'm thinking something like this may work -- all in pseudo-afl code. /// // ConditionSwitch.afl // // Determine the current condition // // Use whatever foreign series and indicators you need // to set Condition to an integer value // Condition = ; // // Use the switch statement to set the parameter values Switch (Condition) { Case 1: V1 = xxx; V2 = xxx; Break; Case 2: V1 = yyy; V2 = yyy; Break; } // Proceed with your trading system // using values of V1 and V2 that depend on broad conditions. Buy = something related to V1 and V2; Sell = ; / Or do you have something else in mind? Thanks, Howard On Fri, Au g 20, 2010 at 12:37 AM, adexie ade...@yahoo.com wrote: thanks Howard for your suggestion. I guess the difficult part for me is how to code it up. I found this online, http://www.amibroker.com/kb/2008/05/19/historical-portfolio-backtest-metrics/ but it's not very comprehensive on custom backtest. Do you know of any other documentation on this topic? Thanks very much. And btw, big fan of your trading system book! Ade --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Howard B howardba...@... wrote: Hi Ade -- You might add logic code to your afl that identifies the category of market condition, then sets the parameters the way you want them for that condition, and then continues on with the optimization. Perhaps using the Switch statement. Thanks, Howard On Thu, Aug 19, 2010 at 9:20 AM, adexie ade...@... wrote: Greetings all, I was wondering if anyone knows whether it is possible to do customized walk forward backtesting with afl code? So I have control over what parameter from IS to use in OS. For example, each time after a IS optimization, i would like to modify the parameter from the optimization based on current market condition and then use that in OS, Instead of directly use the best parameter in the OS test. Any input is greatly appreciated. Best, Ade
Re: [amibroker] Re: customized walk forward backtesting possible?
Hi Ade -- It looks like you want the trade list and statistics from all of the out-of-sample runs from a walk forward test. Is this correct? If so, several of us have been asking to have this functionality provided as a feature of AmiBroker. Thanks, Howard On Fri, Aug 20, 2010 at 2:37 PM, adexie ade...@yahoo.com wrote: Howard, Thank you for put the pseudo code together. It will be much easier to show what I meant. Please see in the code. /// // ConditionSwitch.afl // // Determine the current condition // // Use whatever foreign series and indicators you need // to set Condition to an integer value // Condition = 1 or 2; // // Use the switch statement to set the parameter values Switch (Condition) { Case 1: V1 = 1 * V1(Optimization results from 1/1/ 2010 to 1/31/2010); V2 = 1 * V2(Optimization results from 1/1/ 2010 to 1/31/2010); Break; Case 2: V1 = 2 * V1(Optimization results from 1/1/ 2010 to 1/30/2010); V2 = 2 * V2(Optimization results from 1/1/ 2010 to 1/30/2010); Break; } // Proceed with your trading system to use on Out of Sample trading on 2/1/2010 // using values of V1 and V2 that depend on broad conditions. Buy = something related to V1 and V2; Sell = ; and then repeat with V1 and V2 from Optimization results from 1/2/ 2010 to 2/1/2010, using the same logic to alter V1 and V2 and apply them on OS trading on 2/2/2010 repeat again with IS 1/3/2010 to 2/2/2010 and OS 2/3/2010... Not sure if writing the whole walk forward backtest part using CBT is the only way to do it. Since there's already automatic WF Backtest functionality in AB, it would be great if automatic WF BT can be controlled and manipulated in afl code. I appreciate your input. Have a great weekend! Ade --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Howard B howardba...@... wrote: Hi Ade -- I may be misunderstanding, but I don't see that CBT will be involved. I'm thinking something like this may work -- all in pseudo-afl code. Or do you have something else in mind? Thanks, Howard On Fri, Au g 20, 2010 at 12:37 AM, adexie ade...@... wrote: thanks Howard for your suggestion. I guess the difficult part for me is how to code it up. I found this online, http://www.amibroker.com/kb/2008/05/19/historical-portfolio-backtest-metrics/ but it's not very comprehensive on custom backtest. Do you know of any other documentation on this topic? Thanks very much. And btw, big fan of your trading system book! Ade --- In amibroker@yahoogroups.com amibroker%40yahoogroups.comamibroker% 40yahoogroups.com, Howard B howardbandy@ wrote: Hi Ade -- You might add logic code to your afl that identifies the category of market condition, then sets the parameters the way you want them for that condition, and then continues on with the optimization. Perhaps using the Switch statement. Thanks, Howard On Thu, Aug 19, 2010 at 9:20 AM, adexie adexie@ wrote: Greetings all, I was wondering if anyone knows whether it is possible to do customized walk forward backtesting with afl code? So I have control over what parameter from IS to use in OS. For example, each time after a IS optimization, i would like to modify the parameter from the optimization based on current market condition and then use that in OS, Instead of directly use the best parameter in the OS test. Any input is greatly appreciated. Best, Ade
Re: [amibroker] customized walk forward backtesting possible?
Hi Ade -- You might add logic code to your afl that identifies the category of market condition, then sets the parameters the way you want them for that condition, and then continues on with the optimization. Perhaps using the Switch statement. Thanks, Howard On Thu, Aug 19, 2010 at 9:20 AM, adexie ade...@yahoo.com wrote: Greetings all, I was wondering if anyone knows whether it is possible to do customized walk forward backtesting with afl code? So I have control over what parameter from IS to use in OS. For example, each time after a IS optimization, i would like to modify the parameter from the optimization based on current market condition and then use that in OS, Instead of directly use the best parameter in the OS test. Any input is greatly appreciated. Best, Ade
Re: [amibroker] Walkforward vs. Backtest special case question
Hi Ray -- I would interpret your statement has no parameters to optimize to mean that all of the choices of logic and parameters have been hard-coded into the algorithm. To optimize means, to me, to generate a large number of alternatives, then choose the best based on a metric that describes my preferences. The emphasis is on to choose the best based on a metric that describes my preferences. To optimize is not fully defined without specification of the objective function that will be used to rank the alternatives. If, indeed, the algorithm you refer to in your posting in the only one that is being considered, then the generate and choose tasks have already been done. And the choosing was done using some metric, even if it was subjective. The walk forward process is important in validation of trading systems. It incorporates optimization. Among the benefits of walk forward testing are the many examples you get to see of the transition from testing to trading, and gathering a set of performance results that can be used as an estimate of future trading results and as a baseline for comparison of real-time trading. If you go directly from development to trading, you will be performing the out-of-sample tests with real money, you will be observing the transition from testing to trading with real money, and you will have no baseline by which to compare results. If you are comfortable doing that, then you can skip the validation. You might consider an alternative. Review the system you described. Select some logic and / or parameters that might be varied, with each variation being an alternative trading system. Write optimize statements to control those and run walk forward tests. If your first idea was, in fact, the best, then it will appear consistently at the top of the list in each walk forward step. You will have spent some amount of time but no money, you will have increased your confidence in your system, and you will have some estimates of expected performance. Thanks for listening, Howard On Sun, Aug 15, 2010 at 8:21 PM, raymondpconnolly raymondpconno...@gmail.com wrote: Hello all, I've designed a system that has no parameters to optimize. For this special case would a backtest be materially equivalent to a walkforward or perhaps even superior since there are no boundary distortions? If necessary I've added a dummy variable to allow an optimization for the walkforward but I would be interested in opinions on this special case situation in case the backtest is sufficient for validation. Regards, Ray
Re: [amibroker] Req Afl code for FFT and hints for better use
Hi Ford -- The length of the FFT lookback is so large that it does not have much value when used with financial time series. There are some other algorithms that attempt to compute the periods of dominant cycles. Search for John Ehlers in the AmiBroker forum postings and library (or read his books) for one idea. Some people like the (proprietary) work of Mark Jurik, for another. Other suggestions? Thanks, Howard On Mon, Aug 16, 2010 at 9:00 AM, ford7k for...@yahoo.com wrote: Hi friends, I saw the afl for FFT. iT HAS 1052 periods. CAN WE REDUCE IT? How to use this dominant cycle thing to buy or sell? It seems the real high comes late sometimes after cycle turn is already over. Thanks to our friend who gave forextsd link for tic tac articles. I wish we have something similar to that formula of tic. I am grateful for any hints and guidance from experience of seniuors in using FFT,with some protection,in which form-no idea. thanks ford best regards
Re: [amibroker] InSync
Hi Phil -- InSync is / was the name of a commercial program that computed the values of 10 or so traditional technical indicators and let them vote. I reviewed that program for one of the technical publications fifteen or more years ago. My conclusion was that the indicators they used were so closely correlated that having ten did not help. You can confirm this yourself using AmiBroker. As you are evaluating AmiBroker, read about the AddToComposite (ATC) function that is one of the methods you can use to accumulate data for use in insych-type indicators. There is an excellent paper, Introduction to the AmiBroker AddToComposite, written by Herman van den Bergen, describing use of ATC. Click the third link on this page: http://www.amibroker.org/userkb/2007/12/31/introduction-to-the-atc/ Thanks, Howard On Thu, Aug 12, 2010 at 8:16 AM, phild3581 ph...@charter.net wrote: Hi, I originally purchased amiBroker about 10 months ago and at that time, I believe I searched the AFL library and found an indicator called InSync (which I had used with superCharts). InSync is composed of a combination of various other indicators which when sync'd give a good indicator, in theory. Searching the library today, I am unable to find InSync. Does anyone know if it is deleted, where it is or if they have a copy? Thanks Phil
Re: [amibroker] The Speed of Optmization
Hi Kusnadi -- For an alternative method to insure that the second variable is always greater than the first, change this code: /// firstvar = Optimize(Firstvar,1,1,20,1); Secondvar = Optimize(Secondvar,1,1,firstvar,1); Buy = Sell = True; / to this code: /// firstvar = Optimize(Firstvar,1,1,20,1); VarIncrement = Optimize(VarIncrement,1,1,20,1); Secondvar = firstvar + VarIncrement; Buy = Sell = True; / Thanks, Howard On Thu, Aug 5, 2010 at 12:17 AM, Kusnady saw...@yahoo.co.id wrote: Dear friends, is there anyone having some experiences with parameter of optimization? Look at the afl below: / firstvar = Optimize(Firstvar,1,1,20,1); Secondvar = Optimize(Secondvar,1,1,firstvar,1); Buy = Sell = True; / I need the Secondvar is always less than firstvar, so above I put firstvar as the maximum of SecondVar optimize definition. But once optimized, the SecondVar can be bigger than firstvar This slowdown the optimization process.do you think so? Could you help me how to code efficiently, so the engine just take the firstvar as the maximum for secondvar instead of 20. Regards Kusnadi
Re: [amibroker] Re: Trading Systems, Position Sizing and Monte Carlo Analysis
Hi Keith -- I agree that there is no certainty, but at the point where a system has been designed, tested, and subjected to statistical tests of validity, a person can have confidence that a system is profitable. I would make the point that it is necessary for a trading system developer to believe that his or her system is profitable and is likely to continue to be profitable. The backtesting and validation not only shows that the system was profitable in the past, as you state, but if the testing was done properly, it also tells us that it is likely to be profitable in the future. There is no need to guess -- we can quantify the likelihood of future profitability and other trading metrics. There is no doubt that the characteristics of the price series being modeled can and will change over time, and the system will eventually become unprofitable. But continued monitoring of the system in real time can tell us whether the system continues to perform as expected and can tell us when the system has bitten the dust. I see the issue about scaling in a different light than you suggest. When scaling is a component of a trading system, the effect of the scaling is analyzed over the period the system is developed. It is a component of the entry logic, or the exit logic, or both. I do not see scaling as a technique that is applied only in real time and only as a protection from loss -- if that were the case, how could the effectiveness of a scaling method be tested? Without testing, and analysis of the results of the testing, how could a trader have confidence to implement a technique in an unknown situation? To trade a losing system? I don't know anyone who will knowingly make real-money trades with a system that is known to lose. (Let's agree to defer discussion of the possible equity-smoothing effect of adding a losing, but inversely correlated, system to a winning, but volatile, system.) To test a losing system? Of course we do -- at least I do most of the time. I have an idea, try it, and find that it fails in some area. I begin the process of studying it, learning about it, tweaking it, testing it, and repeat the tweaking and testing until the system looks promising. Most of the alternative systems tested during that process would be described as losing. The final step is always the same -- subject the system to tests of validity, robustness, and confidence. If it passes these, it is a candidate for trading, and I consider it to be a profitable system. Thanks for listening, Howard On Sat, Jul 31, 2010 at 5:14 PM, Keith McCombs kmcco...@engineer.comwrote: Howard -- I take issue with your statement, *Think about it this way -- You have a profitable system. If you reduce your position size when trades have some profit and, on average, the trades go on to be more profitable, you forfeit some of the potential profit. If you reduce your position size when trades have some profit and, on average, the trades go on to become losers, your exit logic needs to be revised.*. Nobody HAS a profitable system. One may have traded or tested a system that WAS profitable. But that does not mean the system IS profitable. Therefore, the fact that profits were reduced in the past from a historically profitable system, has very little meaning, as to what it tells us about the future, if/when it bites the dust. If a system that was profitable in the past becomes unprofitable when it is traded in the future, scaling (and for that matter using stops) may protect one from larger losses, or even complete financial calamity. In order to test if a system might be helped by scaling or stops, one should, I guess, test one that was unprofitable in the past. Of course, nobody wants to test a loosing system! The purpose of scaling and stops is to protect ones financial well being from what we do not know. No matter how well we design anything, including especially trading systems, there are always unknowns. Please realize that I am not saying that scaling and/or stops are advisable. I am just saying that it is very difficult to prove that they are not useful. Personally, I rarely use either scaling or stops. And when I do, it is not because of any analysis. But only because it makes me feel safer. -- Keith On 7/30/2010 10:37, Howard B wrote: Greetings -- Sohamdas wrote: Dr Bandy, what you said is true, about the second alternative. The risk conditions are violated, with further scale-ins,when we double up etc. But consider, if with each scale-in, we also move the stop loss point.In that scenario, the situation can morph into one, where the risk doesnt increase linearly with position,it increases slower than the growth of positions. --- I agree that the risk calculations change as the price moves in the direction that gives profit. But in order to keep to the original risk profile, the amount of the scale in is limited to the amount
Re: [amibroker] Re: Trading Systems, Position Sizing and Monte Carlo Analysis
wisely and when should systems be switched off, reoptimized, etc. If anybody knows some books on this, Iâ#65533;#65533;d be very happy to read up on it so if someone knows an author, please post! So far, having many systems with different logics is the direction Iâ#65533;#65533;m going right now. Something thatâ#65533;#65533;s worth having a look inside is this one: http://www.amazon.de/Trading-Systems-Development-Portfolio-Optimisation/dp/1905641796 again, itâ#65533;#65533;s scratching the topic only. The way I develop systems is always the same (If anyone doesnâ#65533;#65533;t agree with this approach, Iâ#65533;#65533;d like to know why) 1 contract, share, etc. Commissions excluded 3-5 (5max!) input parameters, such as indicators, maâ#65533;#65533;s: itâ#65533;#65533;ll result in a raw system with in-built exits and entries but no stops. Optimize the inputs for STABILITY, a profitable set of parameters with a stable surrounding region Plug-In Commissions Add filters Add stops/targets according to Sweeneyâ#65533;#65533;s MAE MFE Plug-in the position sizing algo, â#65533;#65533;the compounderâ#65533;#65533; Test out of sample Works fine for me. After this, I pretty much try to combine systems. Currently this is a bit troublesome in Ami, but I shall let you know when I have done enough research, unfortunately I believe itâ#65533;#65533;s gonna take me some months. What I believe to be very controversial is the topic â#65533;#65533;adding noiseâ#65533;#65533; to data. I donâ#65533;#65533;t think it reflects human emotion anymore. Same as dealing with a random sequence: a coin toss, e.g., can be displayed as a graph too, but itâ#65533;#65533;s still a normal distribution. So: When doing quant-trading and believing in it, you make one big assumption: Markets behave logically, sometimes. I found out that markets contain a large amount of noise, random behavior. But there are occasions when people get hit on the wrong spot and start buying or selling aggressively . Thatâ#65533;#65533;s the time when my systems jump in and make the kill - then Iâ#65533;#65533;m out. This behavior cannot be found in a random, probably noisy set of data. Monte Carlo pretty much changes the trade sequence only, right now I cannot really see why some people think itâ#65533;#65533;s so useful. It might give you a better estimate of a historic drawdown, but I achieve the same by multiplying my non-monte-carlo-drawdown with say 1.5â#65533;¦ Greetings from Germany, Matthias From: amibroker@yahoogroups.com amibroker%40yahoogroups.com [mailto: amibroker@yahoogroups.com amibroker%40yahoogroups.com] On Behalf Of Howard B Sent: Montag, 26. Juli 2010 16:33 To: amibroker@yahoogroups.com amibroker%40yahoogroups.com Subject: Re: [amibroker] Trading Systems, Position Sizing and Monte Carlo Analysis Hi Sohamdas -- In my opinion, this is definitely a topic that deserves discussion in the AmiBroker forum. What position sizing should be used during backtests? If you will be evaluating each trade for its characteristics -- entry efficiency, exit efficiency, and so forth, then each trade should be the same size. For stocks and ETFs that means the same dollar amount. For futures that means the same number of contracts. If you will be comparing equity growth over a period of time to other alternatives, then you will want position sizing and / or compounding to some degree. For example, if you want to compare the results of a trading system to buy and hold, you will want to take the same size position at the beginning if the test period for each alternative, then compare equity smoothness, growth, drawdown, etc. If you are planning to use aggressive position sizing, there are several things to consider. 1. I cannot state it too often -- your system must have a positive expectancy measured on strictly out-of-sample results. You absolutely cannot use in-sample results to estimate the likely future performance of a trading system in any event. And if aggressive position sizing is based on in-sample results, you will go bankrupt. 2. Traders should have a business plan in place. They should know when to quit -- either when they have enough that they no longer need to trade, or when they have lost so much that they can no longer trade or realize that they should pick another profession. 3. Aggressive position sizing depends on having: A. Positive expectancy. B. Understanding of risk. Both the risk that is acceptable for each trade from the account, and the risk associated with the trading system. Most trading systems have higher risk per trade than the account risk allows, so even taking a position that is everything you can afford to buy is aggressive
Re: [amibroker] Re: Trading Systems, Position Sizing and Monte Carlo Analysis
Greetings -- h3po wrote: I can see one problem with modelling equity curve via Bootstrapmethod described in the thread; the draws will be *independent** *(not correlated). This will give less severe drawdowns in a simulation if the real situation is that consequtive wins/losses are autocorrelated --- You can use statistical tests to determine the degree to which a time series (either / both the raw data and the equity curve resulting from trading it) is autocorrelated. If there is a positive autocorrelation, gains (in either price or equity) tend to follow gains and losses to follow losses. If a series is positively autocorrelated, trend following systems are more profitable than mean reversion systems. If there is a negative autocorrelation, gains then to follow losses and losses to follow gains. If a series is negatively autocorrelated, mean reversion systems are more profitable than trend following systems. Thanks, Howard On Tue, Jul 27, 2010 at 5:21 AM, h3po h3p...@gmail.com wrote: I can see one problem with modelling equity curve via Bootstrapmethod described in the thread; the draws will be *independent** *(not correlated). This will give less severe drawdowns in a simulation if the real situation is that consequtive wins/losses are autocorrelated Actully this gives idea for another interesting question: If one is able to model *stockprices* by means of a simple model, could this (monte carlo) simulated dataseries be valuable as additional data and be used as more OOS data or will it not give any new information in the testing process? (Asuming one is doing a WF test. If Yes, then this would be valuable for end-of-day trading system development as the amount of data here is usually limited). Has this been discussed on this forum before? best regards --- In amibroker@yahoogroups.com, sohamdas soham...@... wrote: It was such a solid read,that I took a lot of time to process it...almost a day(kiddin, didnt know, it would attract so many high quality replies this soon) Many thanks, folks. Especially Dr. Bandy, Matthias,Lionel, Raymond and others.. I am a programmer myself, and have a fair bit of mathematical background myself. In the past, I have developed a few trading systems(3 to be precise) and traded them myself. In essence, I found when delving with works of Vince, I found he uses the Kelly's Ratio extensively (till the pages I could crack, beyond which I lost my patience.) My experiments with Kelly's Ratio has yielded extremely mindshattering drawdowns, but yes, it does compound fairly quickly. So, my internet searches, with Fixed Fractional Ratio led to something called SubOptimal Ratio, in other words the Half-Kelly Ratio. But in some ways, I was not deeply convinced or sold on this. You see, in many ways, I am a believer in the axiom less-crowded-it-is-the-better-it-is. And this is not only in the way, of trading ideas, but also in methodologies. So my view is, out of an ensemble of 100 traders, 92 search for the Hail Mary Indicator/Entry/Setup and 6 of the rest search for the best possible exit. And I would say, you can have a worthless random entry, but a good exit, its possible you might have a better expectancy than with worthless exits. My belief, the pursuit of bettering entries and exits is surely a worthy one, but having a great rock solid position sizing and risk management built, can literally give the real edge to a trading system. My idea, of a really creative position sizing system is, the way Turtles built up their positions. A few of my own observations: 1. When you read it, on paper, it seems a pretty tame pyramiding, but doing it in reality, will quickly tell you how aggressive it is. 2. The position sizing is very apt for trend following. It creates a huge position and in such a pace as to take the maximum out of a trend(in my language: trend following is a slow system, not a bad system, slow system). 3. You can't use the same position sizing of building in 1/2 ATRs in fast trading systems(most notably, mean reversion systems).[Again, note fast trading system is not necessarily a good system. It just is... fast.] The market moves too quickly, in case of a bo failure. You need to have profit stops at place as well. So coming back to the scenario, I was thinking, the main gold might lie in having really unique position sizing methodology, which includes position sizing,pyramiding(scaling in), scaling out(in my limited opinion, gives a better and smoother equity curve when dealing with fast systems), and risk management. -- Which drives me to a very (I cant stress it enough) important pertinent and thought provoking point by Dr Bandy: Treat it like a business. Know when to quit. Doctor,I have got a piece of paper, which follows a series of steps I should take, if and when, god forbid a black swan strikes me.
Re: [amibroker] Re: Trading Systems, Position Sizing and Monte Carlo Analysis
Greetings -- Sohamdas wrote: Dr Bandy, what you said is true, about the second alternative. The risk conditions are violated, with further scale-ins,when we double up etc. But consider, if with each scale-in, we also move the stop loss point.In that scenario, the situation can morph into one, where the risk doesnt increase linearly with position,it increases slower than the growth of positions. --- I agree that the risk calculations change as the price moves in the direction that gives profit. But in order to keep to the original risk profile, the amount of the scale in is limited to the amount of the gain. That is, before scaling in, recalculate the position size permitted and scale in by that amount. The amount of additional position size allowed is usually much less than the original position was. My argument against scaling in is with schemes that take a full position at entry, then add an amount that is large relative to the initial position (100%, 50%, 33%, or 25% are typical). Unless the open profit supports the new position size of 200%, 150%, etc, the risk is now higher than originally permitted. It is OK to do this if you realize that by doing so you are using aggressive position sizing and have worked through the consequences. The original position could be taken at a position size that anticipates all of the scale in trades will be taken. This assures that risk will remain limited. But for those trades when the conditions necessary to add a scale in position do not occur, only a portion of the funds have been committed to the trade and the profit is less than it would have been if a full position was taken at the original signal. I think it is better to treat each signal -- the original and each scale in -- as a unique trading system. Work through the design, testing, and validation of each separately, then apply position sizing to each and to the portfolio that results from trading all of them. Be aware that all of these systems will be trading the same data series in the same direction, and an adverse price move will effect them all the same, increasing the risk rather than diversifying it. Think about it this way -- You have a profitable system with logic that gives you good entry signals. If you wait until the trade shows a profit to add to the position, you forfeit the profit from the funds that were not used at the initial signal. If the scale in portion gives better results than the original signal, then the entry logic needs to be revised. The same situation occurs at scale out. A commonly described technique is to take partial profits and reset the stop when some condition is met. In almost all of the tests I have run using this technique, the performance of the system over a period of many trades is poorer than if the entire position is held until the final exit signal. Think about it this way -- You have a profitable system. If you reduce your position size when trades have some profit and, on average, the trades go on to be more profitable, you forfeit some of the potential profit. If you reduce your position size when trades have some profit and, on average, the trades go on to become losers, your exit logic needs to be revised. Thanks, Howard
Re: [amibroker] Re: Trading Systems, Position Sizing and Monte Carlo Analysis
Greetings -- h3po wrote: Actully this gives idea for another interesting question: If one is able to model *stockprices* by means of a simple model, could this (monte carlo) simulated dataseries be valuable as additional data and be used as more OOS data or will it not give any new information in the testing process? (Asuming one is doing a WF test. If Yes, then this would be valuable for end-of-day trading system development as the amount of data here is usually limited). Has this been discussed on this forum before? --- In my opinion, synthetic or simulated prices have only one purpose. That is to investigate the superposition of signals -- such as combining a trend with one or more cycles with noise -- at the most basic level in order to understand superposition and decomposition. Synthetic price series have no value in testing trading systems. The algorithm portion of a trading system -- the model -- is the logic that is attempting to distinguish the signal from the noise. Recognizing the signal portion and issuing buy and sell orders is what makes the system profitable. Everything that the model does not specifically recognize and use to issue buy and sell orders is noise -- even if it is clearly identifiable as signal by some other method. The ratio of signal to noise in financial data is very low. Identifying the signal component among all the noise is very difficult. If I can generate synthetic price series that are adequate for system development, then I do not need to generate synthetic price series. If I am able to synthesize the signal well enough that I can develop a trading system based on it and trade that system profitable when using the actual data, then the logic I used to generate the synthetic price series describes the signal. I simply code that logic into a real trading system and use it. Synthetic price series based on random values will be random. No trading system can reliably and repeatedly extract profit from random series. The second law of thermodynamics applies here. My recommendation to avoid synthetic price series extends to reordering observed prices. Reordering, for example reordering the daily prices of IBM, in an attempt to give additional data for system testing destroys the time related components of the original series. If there was information in trends, patterns, seasonality, autocorrelation, intermarket correlation, etc, none of that exists in the newly created series. What could be left? In any event, these questions are easy to test. Develop a trading system on synthetic or reordered price series. Then test on out-of-sample actual data. If it is profitable, then the value is in the logic used to generate the synthetic data. It is valuable to add random noise to actual price series in order to test how well a trading system differentiates between noise and signal. But that is the answer to a different question. --- Thanks, Howard
Re: [amibroker] Re: Trading Systems, Position Sizing and Monte Carlo Analysis
Greetings -- Mike's comment is correct -- As for the value of Monte Carlo (MC) vs. Walk Forward Analysis (WFA). My view is that the two are not mutually exclusive, but rather are complimentary. Your out of sample (OOS) results from WFA are exactly the right kind of inputs for MC analysis. --- I would make the statement even stronger. The input to a Monte Carlo Analysis _must_ come from strictly out-of-sample results. One way to get these is from the OOS runs of walk forward analysis. Another is the trades observed after the system being tested has been finalized. Either paper trades or actual trades count, provided the system has not been modified during that period. Thanks, Howard
Re: [amibroker] Re: Trading Systems, Position Sizing and Monte Carlo Analysis
Greetings all -- Several people have mentioned Dr Van Tharp's book, The Definitive Guide to Position Sizing. I like Dr Tharp's work, I have corresponded with him about position sizing, and he was kind enough to mention me in his book. By all means, buy his book and study it -- there is a lot to like in it. But also read the threads on Aussie Stock Forums that discuss trading system design, position sizing, and specifically Dr Tharp's book. Here is the url to the home page of ASF: http://www.aussiestockforums.com I have a few reservations about his book. Dr Tharp begins by defining System Quality Number (SQN). 1. Then he states that he has registered SQN as a service mark. I seriously object to people trying to claim ownership of a well known idea. 2. SQN is essentially a t-statistic, as Dr. Tharp admits on one page early in the text. 3. He discusses the characteristics of trading systems that have SQNs with values from 1 to 7. It is valuable to calculate the t-statistic of a trading system as a metric. The book would have been valuable if it simply stopped there and discussed some realistic examples. But much of the remainder of the book went down an unrealistic path. Just for fun, look at a table of t-statistics. Look up the probability of a one-tailed t-statistic being greater than +2.0 for a test that has 20 or more observations -- it is about 2.9%. This assumes that the observations come a normal distribution, which may or may not be the case for a trading system, but similar statistics can be computed that are not dependent on assumption about the distribution and the results are not different enough to alter my argument. The point is that the probability that a trading system has results that exceed random by enough that the t-statistic is greater than 2.0 is about 2.9%. He continues on to suggest that trading system developers search for systems that have scores of 3, 4, even 7, and that is the part that concerns me. I include a discussion of using the t-statistic as a metric in my advanced workshops. As part of that discussion, I hand out simulated closed trades that come from various distributions with various t-statistics. If you provide an experienced trader with a system that trades frequently, limits losses on losing trades, and has a t-statistic of 3.0 (truly out-of-sample), he or she can own Manhattan in a couple of years. If anyone knows of a system that has a t-statistic (SQN) greater than 3.0 on 20 or more out-of-sample trades, please call me so we can form a partnership and retire very rich very soon. To recap -- buy and study Dr Tharp's book, but be aware of the unreasonable assumptions he makes and the impossible task he sets. Thanks for listening, Howard
Re: [amibroker] Re: Trading Systems, Position Sizing and Monte Carlo Analysis
Greetings -- MK wrote: I believe that is called Bootstrapping. In Monte Carlo you have to first guess the distribution of trades - more assumptions. --- This response is about assumptions about the distribution (not about bootstrapping). It is not necessary, or even advisable, or even good practice, to make assumptions about the distribution of the trades. It is important that the trades from which the Monte Carlo Analysis draws its data are representative of the trades the system under study produces. There are techniques for determining the theoretical distribution that is closest to the observed data, but you do not need to use them unless you are planning a mathematical analysis. Even then, many of the theoretical distributions do not lend themselves to closed form solutions. If you are going to use Monte Carlo Analysis, begin with as many closed trades as you can generate (always out-of-sample only). About 100 is a reasonable minimum number. There is probably no need to go beyond 1000. Using a spreadsheet, sort the trades from worst loss to best gain, then form a Cumulative Distribution (CDF) from the data. It will look like a smooth s shaped curve going from the lower left to the upper right. The horizontal axis has the worst trade as its leftmost value and the best as it rightmost value. The vertical axis has 0 as its lowermost value and 1.00 as its uppermost value. Look it statistics texts or do an Internet search for more details. [The CDF is the integral of the probability density function (pdf). The way the normal distribution graph is usually displayed is a pdf.] Once you have the CDF, you can select a new trade whenever you need it by using a uniform random number generator. Generate a random number, look up the corresponding value of the trade using the CDF. Essentially you generate a uniform random number, go up the vertical axis to that value, go across until you bump into the CDF, go down to the horizontal axis, and read off the value for that trade. Repeat as often as necessary. This gives sampling with replacement. You can generate as many trades as you want -- not necessarily the same number you used to build the CDF. If you prefer sampling without replacement, build a two dimensional array. Column 1 has the trades. Column 2 has values generated from a uniform random number. Sort the two columns on column 2. Keep an index into the table. Every time you need a new trade, pick the one at the index, then increment the index. For a repeated run, use a fresh set of random numbers in column 2, resort, and start selecting values from the beginning again. Thanks for listening, Howard
Re: [amibroker] Re: Trading Systems, Position Sizing and Monte Carlo Analysis
this is a very specialized topic already. There not many books found on this, that’s why I spend so much time thinking about it: Nothing to be found means a lot to be made and understanding it in great detail might give me/you a larger edge. Especially a scientific approach that is not based on gut-feel, is missing. This is what I am currently working on: Portfolio Management in terms of Trading Systems. So to say, have a trading systems farm, probably 3-5 systems on one underlying to have a very smooth equity curve. This includes diversification across a) methodology (Mean Reversion, Trendfollowing, Breakouts,etc.) and b) timeframe (day-trading, swing trading, position trading). Well, I have found 2-3 books on this topic, all of them sort of scratching the surface, mentioning the topic, but that’s it. So how can systems be combined wisely and when should systems be switched off, reoptimized, etc. If anybody knows some books on this, I’d be very happy to read up on it so if someone knows an author, please post! So far, having many systems with different logics is the direction I’m going right now. Something that’s worth having a look inside is this one: http://www.amazon.de/Trading-Systems-Development-Portfolio-Optimisation/dp/1905641796 again, it’s scratching the topic only. The way I develop systems is always the same (If anyone doesn’t agree with this approach, I’d like to know why) 1 contract, share, etc. Commissions excluded 3-5 (5max!) input parameters, such as indicators, ma’s: it’ll result in a raw system with in-built exits and entries but no stops. Optimize the inputs for STABILITY, a profitable set of parameters with a stable surrounding region Plug-In Commissions Add filters Add stops/targets according to Sweeney’s MAE MFE Plug-in the position sizing algo, “the compounder†Test out of sample Works fine for me. After this, I pretty much try to combine systems. Currently this is a bit troublesome in Ami, but I shall let you know when I have done enough research, unfortunately I believe it’s gonna take me some months. What I believe to be very controversial is the topic “adding noise†to data. I don’t think it reflects human emotion anymore. Same as dealing with a random sequence: a coin toss, e.g., can be displayed as a graph too, but it’s still a normal distribution. So: When doing quant-trading and believing in it, you make one big assumption: Markets behave logically, sometimes. I found out that markets contain a large amount of noise, random behavior. But there are occasions when people get hit on the wrong spot and start buying or selling aggressively . That’s the time when my systems jump in and make the kill - then I’m out. This behavior cannot be found in a random, probably noisy set of data. Monte Carlo pretty much changes the trade sequence only, right now I cannot really see why some people think it’s so useful. It might give you a better estimate of a historic drawdown, but I achieve the same by multiplying my non-monte-carlo-drawdown with say 1.5… Greetings from Germany, Matthias From: amibroker@yahoogroups.com amibroker%40yahoogroups.com [mailto: amibroker@yahoogroups.com amibroker%40yahoogroups.com] On Behalf Of Howard B Sent: Montag, 26. Juli 2010 16:33 To: amibroker@yahoogroups.com amibroker%40yahoogroups.com Subject: Re: [amibroker] Trading Systems, Position Sizing and Monte Carlo Analysis Hi Sohamdas -- In my opinion, this is definitely a topic that deserves discussion in the AmiBroker forum. What position sizing should be used during backtests? If you will be evaluating each trade for its characteristics -- entry efficiency, exit efficiency, and so forth, then each trade should be the same size. For stocks and ETFs that means the same dollar amount. For futures that means the same number of contracts. If you will be comparing equity growth over a period of time to other alternatives, then you will want position sizing and / or compounding to some degree. For example, if you want to compare the results of a trading system to buy and hold, you will want to take the same size position at the beginning if the test period for each alternative, then compare equity smoothness, growth, drawdown, etc. If you are planning to use aggressive position sizing, there are several things to consider. 1. I cannot state it too often -- your system must have a positive expectancy measured on strictly out-of-sample results. You absolutely cannot use in-sample results to estimate the likely future performance of a trading system in any event. And if aggressive position sizing is based on in-sample results, you will go bankrupt. 2. Traders should have a business plan in place. They should know when to quit -- either when they have enough
Re: [amibroker] Re: Trading Systems, Position Sizing and Monte Carlo Analysis
Greetings -- MK wrote: What is the benefit of scaling in and out vs. treating them as separate systems? They basically are separate system. - I agree that entries made from secondary signals, or whatever you would call the signals that trigger the scale in, are a separate system. Test them separately. In my experience and research, neither scaling in nor scaling out often improve a system. This is based on an understanding that risk is fully assessed before the initial portion of the trade is entered, and that the full amount of the trade as determined by the risk calculation is not taken until the final scale in has been triggered. That is, if three scale ins are perm itted, then the initial position must be taken with only 25% of the amount permitted by the risk calculation. If the alternative is to take a full position at the first signal, and then add as the trade is in progress through scale in trades, the risk guidelines will have been violated. Thanks for listening, Howard
Re: [amibroker] Trading Systems, Position Sizing and Monte Carlo Analysis
Hi Sohamdas -- In my opinion, this is definitely a topic that deserves discussion in the AmiBroker forum. What position sizing should be used during backtests? If you will be evaluating each trade for its characteristics -- entry efficiency, exit efficiency, and so forth, then each trade should be the same size. For stocks and ETFs that means the same dollar amount. For futures that means the same number of contracts. If you will be comparing equity growth over a period of time to other alternatives, then you will want position sizing and / or compounding to some degree. For example, if you want to compare the results of a trading system to buy and hold, you will want to take the same size position at the beginning if the test period for each alternative, then compare equity smoothness, growth, drawdown, etc. If you are planning to use aggressive position sizing, there are several things to consider. 1. I cannot state it too often -- your system must have a positive expectancy measured on strictly out-of-sample results. You absolutely cannot use in-sample results to estimate the likely future performance of a trading system in any event. And if aggressive position sizing is based on in-sample results, you will go bankrupt. 2. Traders should have a business plan in place. They should know when to quit -- either when they have enough that they no longer need to trade, or when they have lost so much that they can no longer trade or realize that they should pick another profession. 3. Aggressive position sizing depends on having: A. Positive expectancy. B. Understanding of risk. Both the risk that is acceptable for each trade from the account, and the risk associated with the trading system. Most trading systems have higher risk per trade than the account risk allows, so even taking a position that is everything you can afford to buy is aggressive. C. The ability to use leverage. Brokers allow use of margin, and some ETFs have leverage. By using these, it is possible to get 12 to 20 times leverage trading stocks and ETFs in an ordinary brokerage account. D. Frequent trading, because that provides frequent compounding. For most trading systems, the final equity of an account is a multiple of the initial equity that can be computed from: terminal_equity = (1 + expectancy) ^ number_of_trades where expectancy is the average percentage gain per trade. There are two general schemes for aggressive position sizing. As you dig into the math, you will see that they are closely related. The first is fixed fraction, popularized by Ralph Vince. The second is fixed ratio, popularized by Ryan Jones. Both men have written books and papers describing their methods, and you can do an Internet search on each phrase and get a lot of information. The essence of both methods is to increase position size when the system is operating profitably. In gambling terminology, you are betting the run of the table. When winning, increase; when losing, pull back. Both of these are betting schemes called anti-martingale. Ralph Vince has also popularized the notion of optimal f -- that fixed fraction that should be bet on each play to maximize the terminal equity. The fraction of the account used for each play is determined by the largest anticipated drawdown or trade loss. He, and everyone else who is working with real money, shows that the fraction bet on each play Must be less than optimal f if the account is to remain solvent. In fact, the fraction must be much less than optimal f if the account is avoid large drawdowns. Trading at optimal f essentially guarantees drawdowns in the 80 percent range. Ryan Jones essentially creates two sub-accounts. One is the original stake, say $100,000. The other is the profits from trading. Ryan waits until there are some profits, then uses a high percentage of the profits for each trade. The two methods converge mathematically. Some traders prefer to begin using one method, then switch to the other as profits accumulate. Before you consider using an aggressive position sizing scheme, and buying all the stock you can afford is aggressive, please read my other comments in both this forum and Aussie Stock Forums related to trading system development and position sizing. And read both Vince's and Ryan's books, and other material you can find on the Internet. The input to the simulators that model either fixed fraction or fixed ratio need is a list of closed trade results. These are individual trades, each the same size. Monte Carlo Analysis is used to rearrange the sequence of trades many times. The position sizing rules are applied to each sequence and the equity curve computed and drawn. Typically many sequences are used -- 1000 or more -- each of many trades -- 100 or more. After all 1000 runs, all of the equity curves are draw on a single chart and statistics computed that will allow you to estimate the final equity and probability of both going broke and
Re: [amibroker] Can I make buy signal based on date
Hi Timur -- Buydate = DateNum()==1100716; Buy = Buydate; Thanks, Howard On Wed, Jul 21, 2010 at 4:08 AM, TimurLangit i4...@yahoo.com wrote: Help me please. How is afl code to create buy signal based on specific date? Like 'buy=1 if date==July 16,2010'? Thank you so much, Timur
Re: [amibroker] Position Size vs. Max. Sys % Drawdown
Hi Ray -- The answer to your question is a couple of chapters in my next book, Advanced AmiBroker. While waiting for me to finish (no definite date for release), you might read: 1. any of Ralph Vince's books. All are worth reading. His most recent is The Leverage Space Trading Model. 2. Van Tharp's Trade Your Way to Financial Freedom. Get the second edition. In the first edition his explanation of expectancy is wrong. In the second, it is more nearly correct, but still non-standard. If you read his Definitive Guide to Position Sizing, be aware that all of his examples are artificial and unrealistic. There is a thread on Aussie Stocks Forum discussing that book with many of my comments. 3. Nassim Taleb's Fooled by Randomness. 4. David Aronson's Evidence Based Technical Analysis. Several authors correctly point out the importance of position sizing in the long-term profitability of a trading system. The very important point to keep in mind is that estimates of trading results used to determine the position sizing must come from unbiased out-of-sample data. Using in-sample data will seriously underestimate the risk and lead to significant losses or bankruptcy. There are two components to the risk analysis, and they must be kept in balance. One is the risk a trader is willing to take in his or her account on any single trade. The recommended maximum risk is often in the 1 or 2% range. If a person has a (notional) $100,000 trading account, 1% risk is $1000. This means that the trader should hold the maximum loss of any single trade to $1000. The other is the risk associated with the trading system. Measure the (out-of-sample) mean and standard deviation of trades, or mean and maximum adverse excursion of trades. The standard deviation or MAE is (almost) always significantly greater than the mean. Per trade risk is, or at least can be, determined as some multiple of standard deviation or MAE. If a trading system has an expectancy of 0.5% with a standard deviation of 1.5% (not an untypical ratio), and maximum risk is computed as 2 times standard deviation, the risk associated with this system is 3%. Assume the system gives a signal to buy some issue -- say an ETF that trades at $50.00 per share. The maximum risk is 3% or $1.50 per share. If the entire $100,000 is allocated, 2000 shares could be purchased. If the trade goes bad, $3000 could be lost. Since the $3000 risk associated with the trading system is greater than the $1000 risk associated with the account, the position size is too big. The maximum position size that can be taken is the ratio of the account risk to the trading system risk -- 1:3. To keep the two risk components in balance, the trader can take a position of 1/3 of $100,000, or 666 shares. Even without using leverage or margin, a trader who takes a position with all of the funds in his or her account is seriously at risk. In this example, the trader allocating all the funds is trading at 3 times leverage in a cash, un-leveraged, account All trading systems that have a non-zero probability of unlimited loss on any single trade have a non-zero probability of going bankrupt. The probability of that system going bankrupt increases to certainty as trading continues. Aggressive position sizing is necessary if a trader hopes to accumulate serious wealth. Ralph Vince developed / popularized optimal f, an algorithm to calculate the fraction of a trading account that should be bet on any single trade in order to maximize terminal wealth. Systems that trade at optimal f are expected to have drawdowns in the 80% range on their way to the final wealth. Trading at optimal f, or anywhere near it, will create drawdowns that most traders cannot tolerate. In fact, when applying statistical methods to determine whether a trading system is broken or not, most systems would appear to be broken before they recovered. As Vince points out, trading at a risk level higher than optimal f assures bankruptcy. And, as he points out in Leverage Space, if a multisystem is being traded (either multiple systems or multiple tradables), if any one of the systems is traded at a level higher than optimal f, the multisystem is assured of bankruptcy. The topic is a little more complex than explained here, but this should be a reasonable start. Thanks for listening, Howard On Tue, Jul 20, 2010 at 1:55 PM, raymondpconnolly raymondpconno...@gmail.com wrote: Hi Howard, When deciding on position size vs. Max. Sys % Drawdown is it advisable to use the minimum (minimum negative value) or the mean of Max. Sys % Drawdown? Does use of the control chart methodology you outline in the ATAA presentation alleviate the risk of a minimum Max. Sys % Drawdown scenario so that more aggressive position sizing can be taken based on mean rather than the minimum of Max. Sys % Drawdown ? My system seems be able to recover even when minimum Max. Sys % DD = -33% which based on OOS results occurs
Re: [amibroker] calculation of the t-stat of expectancy for the OOS periods of WF Simulation
Hi Ray -- The t-test is used to test whether two samples come from the same distribution. The example you may be referring to asks whether the expectancy of the out-of-sample results could have come from a random or unprofitable system. The null hypothesis (the one we want to say is very unlikely) is the OOS results came from a random system. Calculate the mean and standard deviation of the metric you are using -- expectancy, in this case -- for the OOS results. Calculate the mean and standard deviation for the other, random, distribution. The random mean of expectancy is 0.0. In this case, you can assume that the random standard deviation is the same as the OOS standard deviation. Use the count of data points from the OOS results, and assume the random results have the same count. Compute the t-statistic. Look in the precalculated table to see how likely it is that the OOS results came from the same distribution as the random results. You could make a similar test to see whether the IS and OOS results came from the same distribution. That test would require using all of the trades, IS and OOS, not just the OOS ones. It might be interesting, but that is not the test you probably want. I hope this helps, Thanks, Howard On Sat, Jul 17, 2010 at 7:09 PM, raymondpconnolly raymondpconno...@gmail.com wrote: Hi All, I'm looking for input on the calculation of the t-statistic of expectancy for the OOS periods of the walkforward simulation for the purposes of validation and control as put forward by Dr. Howard Bandy in his ATAA presention of October 2009. Many thanks to Howard for making available this excellent information. At first glance I thought this was a pretty straightforward matter ... until I got down to the nuts and bolts of the calculation. So let me explain what I've done and the questions I'm having: Assumptions: -t-statistic of expectancy (for the null hypothesis Ho: expectancy = 0 ) = ((mean)/(standard deviation))*sqrt(N-1) (1) - use data for each OOS period generated by Amibroker (no CBT generated data) Calculation Possibilities: 1.0 calculate the mean and standard deviation using the expectancy values for each OOS period 2.0 calculate the weighted mean and weighted standard deviation of expectancy where the weight for each OOS period is wt = (number of trades for the OOS period / total trades for all OOS periods) and where the weighted standard deviation is defined here: http://www.itl.nist.gov/div898/software/dataplot/refman2/ch2/weightsd.pdf 3.0 N = number of OOS periods 4.0 N = total trades for all OOS periods Observations and Questions: A) What is the correct combination of inputs from the possibilities above or from possibilities I have failed to recognize that yields the valid t-statistic ? B) comparing 1.0 and 2.0 above yeilds slightly different means in my case ( where the standard deviation in the average number of trades per OOS period is small). 2.0 above also yeilds the same result as calculating expectancy by the alternative method: Expectancy ($) = (TotalProfit - TotalLoss) / NumberOfTrades = NetProfit / NumberOfTrades over all OOS periods so my suspicion is that 2.0 above is the way to go C) with respect to 3.0 and 4.0 above I'm at a loss. I can see using the number of OOS periods as there are that many observations of expectancy however I can also see using total trades for all OOS periods since the results of all trades ultimately generate the expetancies over all OOS periods. Thanks for your input. Ray
Re: [amibroker] Re: Random Backtesting
Hi Joe -- The afl program that you posted has some problems other than the use of random() to set PositionScore. The code below was copied from the AmiBroker 5.30 User's Guide, then modified to use MTRandom() to set PositionScore. The afl compiler is the final arbiter of what works and how. Thanks, Howard // //PositionScoreExample.afl // //Taken from the AmiBroker 5.30 User's Guide //entry under Portfolio-level backtesting // //Modified to use a random PositionScore Portfolio-level back testing /* Portfolio-level back testing You can use new PositionScore variable to decide which trades should be entered if there are more entry signals on different securities than maximum allowable number of open positions or available funds. In such case AmiBroker will use the absolute value of PositionScore variable to decide which trades are preferred. See the code below. It implements simple MA crossover system, but with additional flavour of preferring entering trades on symbols that have low RSI value. If more buy signals occur than available cash/max. positions then the stock with lower RSI will be preferred. You can watch selection process if you backtest with Detailed log report mode turned on. */ SetOption(InitialEquity, 2 ); SetTradeDelays(1,1,1,1); RoundLotSize = 1; posqty = Optimize(PosQty, 4, 1, 20, 1 ); SetOption(MaxOpenPositions, posqty); // desired position size is 100% portfolio equity // divided by PosQty positions PositionSize = -100/posqty; // The system is very simple... // MA parameters could be optimized too... p1 = 10; p2 = 22; // simple MA crossover Short=Cross( MA(C,p1) , MA(C,p2) ); Buy=Cross( MA(C,p2) , MA(C,p1) ); // always in the market Sell=Short; Cover=Buy; // now additional score // that is used to rank equities // when there are more ENTRY signals that available // positions/cash //PositionScore = 100-RSI(); // prefer stocks that have low RSI; PositionScore = mtRandom()-0.50; /// On Thu, Jul 15, 2010 at 12:29 AM, j0etr4der j0etr4...@yahoo.com wrote: Howard, the documentation states, The score (PositionScore) for all securities is calculated first. Then all scores are sorted according to absolute value of PositionScore. Then top N are choosen to be traded. Has that changed? Joe --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Howard B howardba...@... wrote: Hi Mikey -- Positive values of PositionScore are used to rank issues to enter long positions. Negative values are used to rank issues to enter short positions. Try transforming the random numbers so that they run from -0.50 to +0.50. That is, try: PositionScore = random() - 0.50; MTRandom() is better than random(), so you may want to use it instead. You can read about it in the AmiBroker reference guide. Thanks, Howard On Wed, Jul 14, 2010 at 7:11 AM, mikk12345 mikk12...@... wrote: Hi, This is what i want to do. I have 10 stocks in my ticker list. I want to randomly select 5 long and 5 short each worth 100,000 and hold for 50 days in the backtester. Ive tried the following:- Buy= 1; Sell= 0; Short=1; Cover=0; ApplyStop(stopTypeNBar,stopModeBars,50,1); PositionScore=Random(); PositionSize=10; Ive put 1,000,000 in the equity box. This only returns long only. Best Regards, Mikey.
Re: [amibroker] Random Backtesting
Hi Mikey -- Positive values of PositionScore are used to rank issues to enter long positions. Negative values are used to rank issues to enter short positions. Try transforming the random numbers so that they run from -0.50 to +0.50. That is, try: PositionScore = random() - 0.50; MTRandom() is better than random(), so you may want to use it instead. You can read about it in the AmiBroker reference guide. Thanks, Howard On Wed, Jul 14, 2010 at 7:11 AM, mikk12345 mikk12...@yahoo.com wrote: Hi, This is what i want to do. I have 10 stocks in my ticker list. I want to randomly select 5 long and 5 short each worth 100,000 and hold for 50 days in the backtester. Ive tried the following:- Buy= 1; Sell= 0; Short=1; Cover=0; ApplyStop(stopTypeNBar,stopModeBars,50,1); PositionScore=Random(); PositionSize=10; Ive put 1,000,000 in the equity box. This only returns long only. Best Regards, Mikey.
Re: [amibroker] Optimization issues
Hi AJ -- Are the settings the same? Are the issues being tested the same? Are the individual values that give good results in the backtest included within the ranges of the optimization variables? Thanks, Howard On Sat, Jul 10, 2010 at 12:04 PM, AJ axjur...@gmail.com wrote: Good morning, I'm working on a small project where I have 4 variables. If I do a backtest with certain values I get the correct answer (in my particular case 60% gain 10%drawdown). However, when I do an optimization with these variables (the values that I used to get the right answer are within the values that I usein the optimization) the only result I get is 0 calmar, and the gains are 5%. Is there any reason why I would gt the right answer doing backtesting and completely diffrent results when optimizing? did I forget to set something? Thanks for your help, Augusto
Re: [amibroker] Re: Random Entries and Exits?
Greetings -- This is the code being referred to from my book, Quantitative Trading Systems. Thanks, Howard //EnterAtRandom.afl // //Entry a position at the close of a random bar. // //A random entry for use as a benchmark. // //Expect this entry to mirror the buy and hold. //It cannot be profitable taking long positions in //a declining market, or taking short positions //in a rising market. // //This code just waits a fixed number of bars to exit. //It can be used to test any of the exit systems. // //For market orders, enter and exit Market On Close //with no delay SetTradeDelays(0,0,0,0); BuyPrice = C; SellPrice = C; //Frequency is the number of entries per year. Frequency = Param(Entries per Year,12,1,100,1); //Repeatable is a switch. //True (1): the sequence of random numbers will be repeated. //False (0): each sequence is random. Repeatable = Param(Repeatable,0,0,1,1); //Seed is the number used to start the random sequence //when repeatable sequences are desired. Seed = Param(Seed,13331,1,9,1); //Generate a fraction, uniformly distributed //between 0.0 AND 0.9. NextRandom = IIf(Repeatable,Random(Seed),Random()); Buy = IIf(NextRandomFrequency/252,1,0); //The code for the exit being tested starts here. // //HoldBars is the number of bars to wait for exit. HoldBars = Param(HoldBars,3,1,100,1); Sell = BarsSince(Buy)=HoldBars; //The code for the exit being tested ends here. //Remove extra Buy and Sell signals. Buy = ExRem(Buy,Sell); Sell = ExRem(Sell,Buy); //Figure 7.5 Enter at Random /// end of afl On Wed, Jul 7, 2010 at 1:39 AM, reinsley reins...@yahoo.fr wrote: Hi, I don't know the last author. Best regards _SECTION_BEGIN(ct1); /* Coin Toss model , it has nothing to do with Technical OR Fundamental Analysis It has nothing to do with entry or exit rules. Here One books profits and losses at a predefined percent. This Model was Inspired by many authors --- a)Victor Sperandeo :- Methods of Wall Street Master b)Nasim Taleb :- Fooled by Randomness c)Ed Thorp:- #Beat the Market #Beat the Dealer d)William Poundstone :- Fortune's Formula thanks for AB codes and concepts by a)Dimitris Tsokakis b)Herman van den Bergen c)Anthony Faragasso d)Graham Kavanagh and countless good souls. Hearty thanks to Tomasz Janeczko for AB Platform. Disclaimer : any error in code or concept here belongs to me. This Amibroker Script is for educational purposes only. I cannot guarantee it's accuracy nor take any responsibility for your use of it. Use at your own risk. */ SetOption(InitialEquity, 5000); SetOption(CommissionMode, 2); //2 - $ per trade SetOption(CommissionAmount, 1.35); // commission in BPS per leg SetOption(MarginRequirement, 100);// no margin SetOption(UsePrevBarEquityForPosSizing, 1); SetOption(AllowSameBarExit,1); // Sq off Daily SetOption(PriceBoundChecking,0); SetTradeDelays( 0, 0, 0, 0 ); *RoundLotSize*=1; //Change this according to your needs [i did it for Nifty]. posSizeX = Optimize(posSizeX, 1, 1, 10, 1); winloss = Optimize(winloss, 50, 10, 50, 2);// Assumed probability of winning, higher the better winPercent = Optimize(winPercent, 1, 0.25, 10, 0.25);// higher the better lossPercent = winPercent/2; //Optimize(lossPercent, 0.5, 0.25, 10, 0.25);// lower the better //iterations = Optimize(iterations,1,1,20,1);// to test randomness at different levels, not used in any equation. HitRatio = mtRandomA() (winloss/100); //hit ratio *PositionSize* = -(posSizeX); //exposure of capital *Buy* = Day() != Ref(Day(), -1 ); // trade daily *Sell* = *Buy*; // Sq off Daily *Short*=*Cover*=0; *BuyPrice*=100; // to make it generic from EURUSD to Hangseng to Bovespa //if you win you get winPercent, if you loose you loose lossPercent *SellPrice*=IIf(HitRatio,*BuyPrice**(1+(winPercent/100)),*BuyPrice**(1 -(lossPercent/100)) ); Plot(Equity(),Equity : , 1,1); RequestTimedRefresh(1); SetChartBkGradientFill( ParamColor(BgTop, *colorWhite*),ParamColor( BgBottom,*colorViolet*)); _SECTION_END(); Le 07/07/2010 01:17, spacebass5000 a écrit : wow, how did I miss this... i have read and reread this book many times. thanks for the reminder!!! --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, notanaiqgenius notanaiqgen...@... notanaiqgen...@... wrote: If you happen to have Howard Bandy's book, Quantitative Trading Systems, you can see page 91-92 for an example
Re: [amibroker] Re: Random Entries and Exits?
Greetings -- Tomasz has added the Mersene Twister algorithm for generation of random numbers since my book Quantitative Trading Systems was printed. See the AmiBroker help files for mtrandom for details. mtrandom is a better algorithm than the one distributed with most language packages, including C++ and Excel. Also, download the pdf file from the link Addendum and Errata from this page: http://www.quantitativetradingsystems.com/book.html which has an example of using mtrandom. Thanks, Howard On Wed, Jul 7, 2010 at 4:34 AM, Howard B howardba...@gmail.com wrote: Greetings -- This is the code being referred to from my book, Quantitative Trading Systems. Thanks, Howard //EnterAtRandom.afl // //Entry a position at the close of a random bar. // //A random entry for use as a benchmark. // //Expect this entry to mirror the buy and hold. //It cannot be profitable taking long positions in //a declining market, or taking short positions //in a rising market. // //This code just waits a fixed number of bars to exit. //It can be used to test any of the exit systems. // //For market orders, enter and exit Market On Close //with no delay SetTradeDelays(0,0,0,0); BuyPrice = C; SellPrice = C; //Frequency is the number of entries per year. Frequency = Param(Entries per Year,12,1,100,1); //Repeatable is a switch. //True (1): the sequence of random numbers will be repeated. //False (0): each sequence is random. Repeatable = Param(Repeatable,0,0,1,1); //Seed is the number used to start the random sequence //when repeatable sequences are desired. Seed = Param(Seed,13331,1,9,1); //Generate a fraction, uniformly distributed //between 0.0 AND 0.9. NextRandom = IIf(Repeatable,Random(Seed),Random()); Buy = IIf(NextRandomFrequency/252,1,0); //The code for the exit being tested starts here. // //HoldBars is the number of bars to wait for exit. HoldBars = Param(HoldBars,3,1,100,1); Sell = BarsSince(Buy)=HoldBars; //The code for the exit being tested ends here. //Remove extra Buy and Sell signals. Buy = ExRem(Buy,Sell); Sell = ExRem(Sell,Buy); //Figure 7.5 Enter at Random /// end of afl On Wed, Jul 7, 2010 at 1:39 AM, reinsley reins...@yahoo.fr wrote: Hi, I don't know the last author. Best regards _SECTION_BEGIN(ct1); /* Coin Toss model , it has nothing to do with Technical OR Fundamental Analysis It has nothing to do with entry or exit rules. Here One books profits and losses at a predefined percent. This Model was Inspired by many authors --- a)Victor Sperandeo :- Methods of Wall Street Master b)Nasim Taleb :- Fooled by Randomness c)Ed Thorp:- #Beat the Market #Beat the Dealer d)William Poundstone :- Fortune's Formula thanks for AB codes and concepts by a)Dimitris Tsokakis b)Herman van den Bergen c)Anthony Faragasso d)Graham Kavanagh and countless good souls. Hearty thanks to Tomasz Janeczko for AB Platform. Disclaimer : any error in code or concept here belongs to me. This Amibroker Script is for educational purposes only. I cannot guarantee it's accuracy nor take any responsibility for your use of it. Use at your own risk. */ SetOption(InitialEquity, 5000); SetOption(CommissionMode, 2); //2 - $ per trade SetOption(CommissionAmount, 1.35); // commission in BPS per leg SetOption(MarginRequirement, 100);// no margin SetOption(UsePrevBarEquityForPosSizing, 1); SetOption(AllowSameBarExit,1); // Sq off Daily SetOption(PriceBoundChecking,0); SetTradeDelays( 0, 0, 0, 0 ); *RoundLotSize*=1; //Change this according to your needs [i did it for Nifty]. posSizeX = Optimize(posSizeX, 1, 1, 10, 1); winloss = Optimize(winloss, 50, 10, 50, 2);// Assumed probability of winning, higher the better winPercent = Optimize(winPercent, 1, 0.25, 10, 0.25);// higher the better lossPercent = winPercent/2; //Optimize(lossPercent, 0.5, 0.25, 10, 0.25);// lower the better //iterations = Optimize(iterations,1,1,20,1);// to test randomness at different levels, not used in any equation. HitRatio = mtRandomA() (winloss/100); //hit ratio *PositionSize* = -(posSizeX); //exposure of capital *Buy* = Day() != Ref(Day(), -1 ); // trade daily *Sell* = *Buy*; // Sq off Daily *Short*=*Cover*=0; *BuyPrice*=100; // to make it generic from EURUSD to Hangseng to Bovespa //if you win you get winPercent, if you loose you loose lossPercent *SellPrice*=IIf(HitRatio,*BuyPrice**(1
Re: [amibroker] How to reset the Backtester Results window?
Hi Michael -- Right-click in the Results window. This brings up a context menu. Left-click Clear Results List. Or did I mis-understand the question? Thanks, Howard On Wed, Jul 7, 2010 at 1:27 PM, michaels_musings michaels_musi...@yahoo.com wrote: I did something to mess up the display of the backtest output. After trying a variety of things to reset it, including trying all three Result list shows: (Trade list, Detailed log, Summary) and completely uninstalling all copies of AB and reinstalling, it is still showing the Entry signals(score): oddity (below) instead of the trade list. Since it's propagated through a full uninstall, is there something in the registry that might be causing this? Someone know of a config setting I messed up? Thanks, Michael Backtester Results window Use to Show: Ticker,Net Profit,Net % Profit,Exposure %,CAR,RAR,... Now Shows: Date Information 11/19/2009 5:12:00 AM Entry signals(score): Exit signals: 0 Open Positions: , Equity: 10, Cash: 10 11/19/2009 5:13:00 AM Entry signals(score): Exit signals: 0 Open Positions: , Equity: 10, Cash: 10 11/19/2009 5:14:00 AM Entry signals(score): Exit signals: 0 Open Positions: , Equity: 10, Cash: 10 continues on for 500,000 rows
Re: [amibroker] Intrady Time interval problem
Greetings -- On the Tools menu Preferences Intraday tab You can control whether the time associated with a bar is the start of the bar or the end of the bar. Thanks, Howard On Thu, Jul 1, 2010 at 1:04 AM, edakad1 edak...@yahoo.com wrote: Hi, I am facing a problem with intraday charts. Suppose the day session ends at 3.30 pm. I am using 5 min charts. Then the last bar should end at 3.30 pm. Instead I see the last bar close at 3:29:59 and there is another bar with a few ticks. It shows time 3.30. Plese help to resolve this issue. Thanks and regards
Re: [amibroker] Re: Percentile Rank of P/S Ratio
Hi Abbie -- I wrote a paper, Use of Fundamental Data in Active Investing, that discusses some the issues that arise when using fundamental data. You can download it for free from this site: http://www.blueowlpress.com/activities.html Thanks, Howard On Fri, Jun 18, 2010 at 1:44 AM, Paolo pcavat...@gmail.com wrote: Abbie, as far as I know yahoo doesn't provide historical fundamental data which you need for proper historical backtesting. Regarding the for cycle it looks fine. Paolo --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, sendfreetest sendfreet...@... wrote: Thank you for getting back to me with some information on how to tackle the Percentile Rank of P/S Ratio code. I was thinking of using Yahoo! historical data but your comments make me think their data may not be accurate enough? Any thoughts on good data? I will think over and try to implement your idea about using PositionScore. What I was working on is a for a cycle to calculate the percentile. (Most of the code I found in back posts of this group. ) Right now the code seems to work in an exploration. I've pasted it below. (As I am new to coding it may not be the prettiest.) I'll continue to work on the code to try to make it useful for actually testing the idea. --- Var = C / GetFnData(SalesPerShare); /* PERCENTILE RANK */ /* set watchlist , and indicator twice */ //Adapted From Count tickers in watchlist function - Anthony Faragasso listNum=1; // DEFINE WATCHLIST function CountTickersInWatchList( Listnum ) { // retrive comma-separated list of symbols in watch list list = GetCategorySymbols( categoryWatchlist, listnum ); for( i = 0; ( sym = StrExtract( list, i ) ) != ; i++ ) { if( i == 0 ) i = 0; else i = i ; } return i; } // Adapted from Ranking Ticker List - Nenapacwanfr list = GetCategorySymbols( categoryWatchlist, listnum ); for( i = 0; ( sym = StrExtract( list, i ) ) != ; i++ ) { SetForeign(sym); VarSet(MyInd+i, (C / GetFnData(SalesPerShare))); //INDICATOR - DEFINE Rank =1; for( j = 0; ( item = StrExtract( list, j ) ) != ; j++ ) { SetForeign(item); VarSet(ThisInd+j, (C / GetFnData(SalesPerShare))); //INDICATOR - DEFINE Rank=Rank + IIf( VarGet(MyInd+i) VarGet(ThisInd+j),1,0); RestorePriceArrays(); } VarSet(Rank+i,Rank); } Count=0; BreakLoop = False; for( k = 0; NOT(BreakLoop) ( ticker = StrExtract( list, k ) ) != ; k++ ) { if(Name()==ticker) Breakloop=True; else Count=Count+1; } Rank = VarGet(Rank+ Count); PercentRank = (1 - rank/CountTickersInWatchList(Listnum))*100; Filter = PercentRank 17 AND PercentRank 42; AddColumn(RANK,Rank); AddColumn(CountTickersInWatchList(Listnum),Total); AddColumn(Close,Close); AddColumn(PercentRank,Percentile Rank); AddColumn(C / GetFnData(SalesPerShare), P/S Ratio); --- Thanks again for your help, Abbie --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Paolo pcavatore@ wrote: First of all you need P/S data (or Sales per share and calculate the ratio) with enough historical range and clean data. A rare combination especially when talking about fundamentals. Secondly you can use Rotational backtesting with PositionScore being equal to the inverse of the P/S (the higher the better). Otherwise I would recommend using a for cycle calculating the percentile for each stock in your universe and use it to both rank your stocks for proper buy/sell rules and plot also the ranking as an indicator. Be careful 'cause for large number of stocks (500) it tends to be very slow. I hope it helps, Paolo --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, sendfreetest sendfreetest@ wrote: Hi, I really need coding assistance. I am attempting to code into AmiBroker Charles Kirkpatrick's trading methodology for testing. Kirkpatrick creates a percentile rank of stocks' price-to-sales ratio and uses it as a filter. He purchases only stocks with a percentile rank between the 17th and 42nd level. When a stocks price-to-sales percentile rank goes above 67 he sells. With AmiBroker's PERCENTILE function it seems to evaluate only one market's array to determine the percentile. Is their an AmiBroker funtion to evaluate say 100+ stocks P/S Ratio and give each a percentile rank. Thanks in advance for any help. Abbie
Re: [amibroker] Re: How to set the amount in ApplyStop(stopTypeTrailing, stopModePoint,amount,1,1,1)
Hi Jolly -- Something like this:? TrailingStopPercentage = 2.5; // percentage points ApplyStop(StopTypeTrailing,StopModePercent,TrailingStopPercentage,1); TrailingStopPercentage is a variable that you control completely -- you name it, you assign it a value, the value can be an expression including calculations using other variables. It can be used with Optimize. See the user's manual entry for ApplyStop. Thanks, Howard On Fri, Jun 18, 2010 at 6:34 AM, jollypollyanna jollypolly...@yahoo.comwrote: --- In amibroker@yahoogroups.com, Joe Bolton j0etr4...@... wrote: Greetings, Following the work-around for the trailing stop is the code I started for the trailing Applystop, but of course the code for the amount is wrong. What is there is the closest I could come to getting the right amount and it's very wrong. Thank you for any help you can provide. Best regards, Joe == Reading through this thread showed the issue had not been resolved in the thread . That being the *setting of amount outside the ApplyStop function*. I am thinking that amount cannot be initiated outside the ApplyStop function. If this is the case could someone please confirm this? If amount can be initiated outside of ApplyStop function, could a simple example be provided please. Thank you.
Re: [amibroker] read individual values
Hi Erich -- I still do not understand. Can you post (or send me privately) an afl that illustrates the condition? Include the settings that you are using. Thanks, Howard On Tue, Jun 15, 2010 at 10:44 AM, Erich Matos Rodrigues erich...@interjato.com.br wrote: Hi Prof. Howard, In this way they never agree and the difference is great. However, when I plot my trade system in range of bars chart, I look indicator value and it is same value that I choose in condition to buy or sell. Then, I think that in range of bar chart and in backtest with range of bar, I have same value. Perfect. But How to know value of CCI (14), for example, every time TS (in range of bar) to buy or sell? If I use explorer or function below, CCi (14) or other indicator, give results in range of DATE. Course will be different…. Then I think that need change in function. This value in example, I have in my range of bar chart, when I add CCI indicator in range of bar chart, but I´d like a spreadsheet with this indicator value when buy or sell. Thank you for your response, Erich Hi Erich -- I am still a little confused. You are permitted to have different values for parameters for an indicator that is displayed in a chart and for an indicator that it being tested in a backtest. They Can agree and they May agree, but they are not Required to agree. Is this the confusion? Thanks, Howard On Tue, Jun 15, 2010 at 4:37 AM, erichrod1 erich...@interjato.com.brerichrod%40interjato.com.br wrote: Hi, In fact it is little confuse and I didn't explain very well. I use only range of BARS, in chart and backtest. To improve my TS I´d like to know, for example, CCI value (in range of bars) when my TS buy or sell (in range of bars). This CCI value will be same that I see in range of bars chart. If I use explorer to do this, I choose range in bars (like I define in preferences, intraday, in Custom N-tick chart settings), but indicator results (value) are in range of dates... Amibroker buy or sell based in CCI value create from range of bars, right, but give me value from range of dates... After that, I tried to use backtest and a custom function to generate indicator value, but didn't work, trade system works very well in range of bars, but indicator value is always in range of date, different of value in chart, that is in range of bars also. I don't know if is possible. Thank you for your response, Erich Rodrigues --- In amibroker@yahoogroups.com amibroker%40yahoogroups.comamibroker% 40yahoogroups.com, Howard B howardba...@... wrote: Hi Erich -- Thanks for the kind words about my books. I am afraid I do not understand your question. Usually the backtest is made over a range of dates or bars. Can you express the rangebar range you want tested in dates or bars? You can export the results of a backtest or explore, including indicator values and Buy or Sell signals using AA's File Explore menus. Does that do what you need? Thanks, Howard
Re: [amibroker] Re: doubt with stops
Hi Gonzaga -- Check the users guide for ApplyStop. Your afl can have more than one exit, and it is common for a trading system to include both exits described by logic (Sell = xxx;) and by ApplyStop -- perhaps more than one of each. If you have several ApplyStop statements (profit target, trailing stop, maximum holding period), AmiBroker keeps them straight. If you have several logic exits, assign each its own variable name (SellCond1 = xyz; SellCond2 = wxy;), then combine them into one Sell statement (Sell = SellCond1 OR SellCond2;). The precedence and order in which stops and logic exits are applied and depends on settings. If you have very complicated exits, you might want to write looping code to handle them. This gives you complete control, assurance that you understand how they are being applied, and the ability to debug them using Plot and AddColumn statements. Thanks, Howard On Tue, Jun 15, 2010 at 4:42 PM, Gonzaga gonzag...@yahoo.es wrote: I've just realized that my problem my be related with the sell signal. For I use a profit stop, but also a sell condition; and both are different. So, how does combine sell conditions with stops? Could I have problems if I mix both? --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Gonzaga gonzag...@... wrote: Hi. I have an idiot doubt. Sometimes AFL gets me crazy :-) I have applied a very simple stop profit: //--- SetTradeDelays(1,1,1,1); // buy or sell after signal //SetOption(ActivateStopsImmediately,False); -- I don't know the use of this stoplevelp=1; ApplyStop(stopTypeProfit, stopModePercent, stoplevelp, 1);//1: exit intraday on same bar //--- So I though the profit stop sell the stock even in the day of buy, just 1% over buy price. But I see, it sells 1,3% over buyprice. or more.. In settings I have established a commission table of 0.005 per share, so I suppose that's not related. And, also, how does it work the axtivatestopsimmedately? Is there any good help file to study all these..? Thanks a lot..
Re: [amibroker] read individual values
Hi Erich -- Thanks for the kind words about my books. I am afraid I do not understand your question. Usually the backtest is made over a range of dates or bars. Can you express the rangebar range you want tested in dates or bars? You can export the results of a backtest or explore, including indicator values and Buy or Sell signals using AA's File Explore menus. Does that do what you need? Thanks, Howard On Mon, Jun 14, 2010 at 8:17 AM, erichrod1 erich...@interjato.com.brwrote: Hi Dr. Howard, I have your book and love it. It help me improve my backtests. Talking about how to read individual values in the portfolio-phase of the backtest, I have a question: How to use this custom objective function to take value IF TIMEFRAME IS RANGEBAR? I use this function in my tradesystem, that buy and sell in range bar, but function results are timed... Is it possible change this function to do this? Basically, I need export indicator value when my backtest says to buy or to sell. TIA, Erich Rodrigues --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Howard B howardba...@... wrote: Hi RZ -- My book Quantitative Trading Systems discusses objective functions in general, the importance of choosing one early in the system design process, the metrics built-in to AmiBroker, the process of designing multi-component custom objective functions, the custom backtest code necessary to implement custom objective functions, and the use of objective functions in optimization and walk forward testing. The objective function incorporates the subjective aspects of trading systems. Proper choice of the objective function guarantees that trading systems that are highly ranked by the search process and chosen by the walk forward process will be comfortable to trade. It would be difficult to overemphasize the importance that proper selection of objective function plays in trading system development. http://www.quantitativetradingsystems.com/ Thanks, Howard
Re: [amibroker] Self Adaptive Bollinger
Hi G -- If it does not violate any copyright or non-disclosure, post the TradeStation code and someone will translate it and post the equivalent AmiBroker code. If that would be in violation, then this is not the appropriate forum. Thanks, Howard On Sun, Jun 13, 2010 at 11:36 AM, googool123123 bfall...@yahoo.com wrote: I have Trade Station code for self adaptive Bollinger Bands. I was wondering if any one would be interested in translating it into Amibroker Language Thanks in Advance
Re: [amibroker] Divergence Indicator
Hi Vishvesh -- Please reply to an open thread rather than beginning a new one. In order to program an indicator for divergence, it must first be described as a formula. Description of the visual appearance is not adequate. Can you describe divergence as a formula? Thanks, Howard On Fri, Jun 11, 2010 at 11:43 AM, Vishvesh vishvesh.chau...@gmail.comwrote: [Attachment(s) #129281c24215e039_TopText from Vishvesh included below] When i say divergence it mean prices(low/high/close) have made newer reading but the RSI or MACD failed to do so. I have attached chart for ur perusal. Regards Vishvesh On Fri, Jun 11, 2010 at 10:12 PM, Howard B howardba...@gmail.com wrote: Hi Vishvesh -- If you can define divergence in an unambiguous way, it can be programmed. What is your definition? Thanks, Howard On Fri, Jun 11, 2010 at 10:11 AM, Vishvesh vishvesh.chau...@gmail.comwrote: Hello Friends, I was wondering is there AFL available which highlights the price bar when there is divergence in momentum (RSI,MACD) etc. Any help highly appreciated, Thanks Regards Vishvesh
Re: [amibroker] Limiting Drawdown in a Backtest
Hi RZ -- My book Quantitative Trading Systems discusses objective functions in general, the importance of choosing one early in the system design process, the metrics built-in to AmiBroker, the process of designing multi-component custom objective functions, the custom backtest code necessary to implement custom objective functions, and the use of objective functions in optimization and walk forward testing. The objective function incorporates the subjective aspects of trading systems. Proper choice of the objective function guarantees that trading systems that are highly ranked by the search process and chosen by the walk forward process will be comfortable to trade. It would be difficult to overemphasize the importance that proper selection of objective function plays in trading system development. http://www.quantitativetradingsystems.com/ Thanks, Howard On Fri, Jun 11, 2010 at 9:00 PM, i cs ics4...@yahoo.com.au wrote: Thank you Howard, re_Rowland and Mike Was trying to avoid the CBT but it looks like I gotta dive in. BTW Howard, which of your books would best cover this level of experience? Thanks for your help again RZ -- *From:* Howard B howardba...@gmail.com *To:* amibroker@yahoogroups.com *Sent:* Sat, 12 June, 2010 2:39:54 AM *Subject:* Re: [amibroker] Limiting Drawdown in a Backtest Hi RZ -- You can do this by creating a custom objective function. It could as simple as assigning the custom function a value of 0 whenever the parameter set results show maximum system drawdown exceeds 30%. Try this: / / / // //LimitDrawdown. afl // //Use CustomBacktester to limit //drawdown in trading systems. // //Howard Bandy //June 2010 // OptimizerSetEngine( cmae ); //The custom backtest code //to penalize results that do not //meet your specifications DesiredDDLimit = 30; SetCustomBacktestPr oc( ); if ( Status( action ) == actionPortfolio ) { bo = GetBacktesterObject (); bo.backtest( ); st = bo.getperformancest ats( 0 ); MaxSysDD = abs( st.getvalue( MaxSystemDrawdownPe rcent ) ); NetProfPct = st.getvalue( NetProfitPercent ); ObFn = ( MaxSysDD DesiredDDLimit ) * NetProfPct; bo.addcustommetric( FilteredNetProfit, ObFn ); } //The Buy and Sell signals MA1Len = Optimize( MA1Len, 5, 1, 100, 1 ); MA2Len = Optimize( MA2Len, 20, 1, 100, 1 ); MA1 = EMA( C, MA1Len ); MA2 = EMA( C, MA2Len ); Buy = Cross( MA1, MA2 ); Sell = Cross( MA2, MA1 ); e = Equity(); Plot( e, E, colorGreen, styleLine ); // end / / / / Thanks, Howard On Fri, Jun 11, 2010 at 6:37 AM, ics4mer ics4...@yahoo. com.auics4...@yahoo.com.au wrote: Hi, Doing a bit of backtesting lately, and I was wondering how to limit the drawdown while using another metric for the objective function. Lets say that I want to optimize for Net Profit, but I won't accept parameter sets that result in a drawdown of more than 30% I know it can be done (AB does anything). Could somebody give me a pointer please? I can't find explicit references to it in the archive, and I don't think I'm ready for some of the more intricate parts of the CBT. TIA RZ
Re: [amibroker] Divergence Indicator
Hi Vishvesh -- If you can define divergence in an unambiguous way, it can be programmed. What is your definition? Thanks, Howard On Fri, Jun 11, 2010 at 10:11 AM, Vishvesh vishvesh.chau...@gmail.comwrote: Hello Friends, I was wondering is there AFL available which highlights the price bar when there is divergence in momentum (RSI,MACD) etc. Any help highly appreciated, Thanks Regards Vishvesh
Re: [amibroker] Simple Code Difficulty
Here is the Buy part with plot statements to help visualize what is happening - //Buy20DayHigh.afl // //Buy when ema(c,5) ema(c,20) //and issue reached new 20 day high // //Howard Bandy //June 2010 // Cond1 = EMA( C, 5 ) EMA( C, 20 ); Cond2 = H Ref( HHV( H, 20 ), -1 ); Buy = Cond1 Cond2; Sell = 0; shapes = Buy * shapeUpArrow + Sell * shapeDownArrow; shapecolor = IIf( Buy, colorGreen, colorRed ); PlotShapes( shapes, shapecolor ); Plot ( Close, C, colorBlack, styleLine ); Plot ( Cond1, Cond1, colorGreen, styleLine | styleOwnScale, 0, 1.5 ); Plot( Cond2, Cond2, colorBlue, styleLine | styleOwnScale, 0, 2 ); Thanks, Howard On Fri, Jun 4, 2010 at 1:40 PM, abramway abram...@yahoo.com wrote: I'd just like to be able to get signals for Buy: When EMA(5)EMA(20) AND Stock @ Fresh 20-Day Highs. Exit: When EMA(20)EMA(5) OR Stock @ Fresh 10-Day Lows (haven't incorporated the second part yet) This is what my code reads now and its giving me the wrong signals. It gives me BUY signals before a new 20-Day high. Buy = EMA( Close , 5 ) EMA( Close , 20 ) AND High Ref( HHV( High , 20 ) , -20 ); Sell = EMA( Close , 20 ) EMA( Close , 5 ); Short = 0; Cover = 0; Thanks for the help
Re: [amibroker] Request For An AFL To Scan Open=High or Open=Low In Any Time Frame
See if this helps -- //OpensAtHigh.afl // //Identify that the opening price //on the first bar of the day //is the high of that bar. // //Howard Bandy //June 2010 // dn = Day(); FirstBar = dn != Ref( dn, -1 ); OpenAtHigh = FirstBar ( O == H ); Plot( C, C, colorBlack, styleCandle ); shapes = shapeUpArrow * OpenAtHigh; shapecolor = OpenAtHigh * colorGreen; PlotShapes( shapes, shapecolor ); -- Thanks, Howard On Wed, Jun 2, 2010 at 11:51 PM, FLOYD LEWIS fj...@yahoo.com wrote: Dear Seniors Greetings to you all Am new to Amibroker and equally new to the field of AFL writing. Does anyone on this group by any chance have an afl which can be run on any time frame including real time to explore and scan stocks which meet the condition of open=high or open=low for the first bar only. Definition of first bar - It could be any time frame in RT i.e. 3 min or hourly etc as per the selection but it should be the bar of the opening bell which should be scanned for the above condition and not the subsequent bars. Would sincerely appreciate if any one from this group could share the same. I hope i have been able to explain the requirement clearly. Thanks in advance. God Bless Regards
Re: [amibroker] Deleting database
Hi K -- Each database is a subdirectory to C:\Program Files\AmiBroker. For example, the small database that installs when AmiBroker is first installed is named Data. It is in C:\Program Files\AmiBroker\Data. Use Windows Explorer and you can see the folders where each ticker is stored according to its first character -- IBM is in \Data\I, 3M is in \Data\M, etc. If you really want to delete the entire database, use Windows Explorer to delete the subdirectory that holds the database you want to remove. If you plan to reconstruct the database with the same name but new data, and you want to be able to use the layouts and watchlists, copy the \Layout and \Watchlist subdirectories to a safe place before deleting the database. Thanks, Howard On Thu, Jun 3, 2010 at 3:57 PM, homosapeins85 ktha...@gmail.com wrote: How do I delete a database? Alternatively, is there a way to delete all the symbols from a database other than doing it manually for each symbol? Thanks, K
Re: [amibroker] Volatility bands
Hi Mithal, and all -- Not to discourage your efforts, but no one will be able to develop, test, and validate a trading system, then trade it with confidence, without having skills in both programming and statistics. Please, take the time to learn AmiBroker's afl. Thanks, Howard On Sat, Jun 5, 2010 at 12:46 PM, Infinity Home Loans infynh...@yahoo.comwrote: Hi Mubashar, I am not at all comfortable with writing a formula, as I do not have any coding background. I have tried using BB but they do not serve the purpose as I had expected. Can you please try and provide some support in building this formula as per the tradestation code mentioned earlier? Regards Mithil --- On *Sat, 5/6/10, Mubashar Virk mvir...@gmail.com* wrote: From: Mubashar Virk mvir...@gmail.com Subject: Re: [amibroker] Volatility bands To: amibroker@yahoogroups.com Date: Saturday, 5 June, 2010, 11:15 AM It should be easy provided you have custom atr formula. On 6/4/2010 12:47 PM, infynhome wrote: I am referring to the book Technical analysis for the trading professional by constance brown. She had mentioned about Volatility band formula written in tradestation language. I need this formula to be converted into afl language. Can somebody help me with this. Input: Coefdwn[2.1] ,Coefup[2. 3]; Plot1[Average[ [RSI[Close, 14]],6]]+ [Coefup*[ Average[TrueRang eCustom[[ RSI[Close, 14]],[RSI[ close,14] ]],14]]], Plot1]; Plot2[Average[ [RSI[Close, 14]],6]]- [Coefup*[ Average[TrueRang eCustom[[ RSI[Close, 14]],[RSI[ close,14] ]],14]]], Plot2]; Plot3[[RSI[Close, 14]], plot 3]; IF CheckAlert Then Begin IF Plot1 Crosses Above Plot2 or Plot1 Crosses Below Plot2 or Plot1 Crosses Above Plot3 or Plot1 Crosses Below Plot3 or Plot2 Crosses Above Plot3 or Plot2 Crosses Below Plot3 Then Alert = TRUE; End; thanks Mithil
Re: [amibroker] Loop for MA calculation
As requested -- //CalculateMovingAverageLooping.afl // //Calculate a simple moving average using looping code // //Howard Bandy //June 2010 // //In Formula Editor, click Apply Indicator. //Note that all three moving averages are the same //Plot the price series Plot( C, C, colorBlack, styleLine ); MALen = 10; //Assume the afl statement to be replicated is: MAAFL = MA( C, MALen ); //Plot the builtin simple moving average Plot( MAAFL, MAAFL, colorBlue, styleLine ); //A couple of ways to compute the simple moving //average using looping code follow. //This example is coded for clarity, rather than for efficiency // //Initialize the bars for which there are insufficient //bars for a full moving average to be the closing price //for each of those bars. for ( i = 0; i MALen; i++ ) { MALoop1[i] = C[i]; } //TempSum holds the sum of the values being averaged //TempSum is a scalar. for ( i = MALen; i BarCount; i++ ) { TempSum = 0; for ( j = 0; j MALen; j++ ) { TempSum = TempSum + C[i-j]; } MALoop1[i] = TempSum / MALen; } Plot( MALoop1, MALoop1, colorGreen, styleLine ); //This example is a little more efficient // for ( i = 0; i MALen; i++ ) { MALoop2[i] = C[i]; } TempSum = 0; for ( j = 0; j MALen; j++ ) { TempSum = TempSum + C[MALen-1-j]; } for ( i = MALen; i BarCount; i++ ) { //Drop off the oldest value and add the newest TempSum = TempSum - C[i-MALen] + C[i]; MALoop2[i] = TempSum / MALen; } Plot( MALoop2, MALoop2, colorRed, styleLine ); /// end
Re: [amibroker] State of Advanced Amibroker
Hi Frank -- Thanks for your interest in Advanced AmiBroker. I am still working on writing and editing the book. Time to work on it is in competition with my own trading and several other of my projects. I am making progress on the book, but have no definite release date. I will post notices when it goes to the printer and is available for pre-publication orders. Thanks, Howard On Sat, May 15, 2010 at 7:43 AM, frankphd_us frankphd...@yahoo.com wrote: Will the book be out in the foreseeable future - or is it postponed again? I couldn`t find any new announcements on the publisher`s site. Thanks frankphd_us
Re: [amibroker] Re: SP GICS clasifications
Hi Ara -- According to information from Norgate Premium Data, they will will have GICS data real soon now. Richard Dale, who often posts here, is their contact. Thanks, Howard On Fri, Apr 23, 2010 at 12:54 AM, Paolo pcavat...@gmail.com wrote: http://www.amibroker.org/userkb/2008/03/25/ascii-import-standard-and-poors-global-1200/ Let me know if it helps, Paolo --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Ara Kaloustian a...@... wrote: Does anyone know where I can find a list of stocks with their GICS codes so I can import them into AB? Thanks Ara
Re: [amibroker] Re: Taking 2 Trades in 1 Bar
Greetings -- You may need to use bars with finer resolution. Any assumptions of the order of any prices other than Open and Close are unreliable. Conservative trading system design assumes that prices happen in the order that is least favorable to the trader. For any single bar, you know four prices -- Open, High, Low, Close -- and the time at which two of those took place -- Open, Close. You have no information about the timing, or even the relative timing, of the High, the Low, or any other price. The possibilities for a single unambiguous trade within a single bar are: Buy (enter) at the Open, Sell (exit) at a limit or stop price, provided that price is within the Low to High range. Buy at Open, Sell at the Close. Buy at a limit or stop price within the Low to High range, Sell at the Close. Note that you cannot Buy at one intrabar price and Sell at another intrabar price, because you have no information about which happened first. The possibilities for two unambiguous trades within a single bar are: Buy at the Open, reverse to Short at a price within the Low to High Range, Cover at the Close. Thanks, Howard On Fri, Apr 16, 2010 at 3:18 AM, ang_60 ima_c...@yahoo.it wrote: --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Pmxgs pm...@... wrote: Hello, I also had the same issue and I found that if you choose SetBacktestMode( backtestRegularRawMulti ) AB allows you to do what you want, without using Custom backtester. By doing this, as the previous user said you can never be sure of the order of the trades, but if you are willing to accept this assumption it'll do what you want. Hello pmxgs, I tried your suggestion on the type of system commented here (that is, acting on the breakout of the previous bar's range), around this code(these are just trials, so I don't care about the chronological order of the trades): SetBacktestMode(backtestRegularRawMulti); Buy = Cover= H Ref(H, -1); Sell= Short = L Ref(L, -1); BuyPrice=CoverPrice = Max(O, Ref(H, -1)); SellPrice = ShortPrice = Min (O, Ref(L, -1)); but I still get just 1 trade per bar. Are you using some other settings? If it is not too much pain, could you give just a rough example of an AFL code taking 2 trades per bar? Greetings, Angelo.
Re: [amibroker] How to Change the Sort Order
Hi Alan -- In order to sort them into the order you want them in, you will need to assign each a number that will be used as the sort key. I assume you can define the key and do that. Assign that key to a variable. Use the AddColumn to list the variable. Run the Exploration. Click on the header for the column that has your sortkey. Thanks, Howard On Sat, Apr 10, 2010 at 1:45 AM, Alan a...@thenorthams.us wrote: In the first column of the results of my exploration is a list of Ticker Symbols. These symbols are listed alphabetically in ascending order. I would like to have these tickers listed in a certain specified order which would not be an alphabetical ascending or descending order but in an order of my own choosing. Is there a way to do this?
Re: [amibroker] Question about PositinScore in backtesting
Hi Tony -- There is a trading system methodology known as rotational trading where a watchlist is evaluated every bar and those issues that have the highest PositionScore are selected. To enable rotational trading, the afl needs this statement: EnableRotationalTrading(); When using rotational trading, Buy, Sell, Short, and Cover statements are ignored. Only PositionScore matters. Trading takes place at the Open or Close depending on the settings of BuyPrice, SellPrice, ShortPrice, and CoverPrice. Trading takes place with the delay between signal and execution according to the settings of SetTradeDelays(n,n,n,n); Rotational trading was very popular in the 1990s for switching among mutual funds, and continues to have some following. Rotational trading is a subset of general trading, and is limited by the inability to use Buy and Sell signal, Stops, Timed exits, and other techniques. Review the AmiBroker User's Guide for details. - If the afl does not have rotational trading enabled, then PositionScore is used to break ties only when new entries are being considered. In the situation you describe, the ten issues selected on day one from more than ten candidates are those that have the highest PositionScore on that day. On day two there are three available slots. The three that will be chosen are the three that have the highest PositionScore from among those candidates that have Buy signals that day. Issues that have already been purchased do not have their PositionScore evaluated and will not be sold simply because of a low PositionScore. After they have been sold due to a Sell signal, or execution of a stop, they then rejoin the pool of candidates and will have their PositionScore calculated in anticipation of competing for entry at the next Buy signal. Thanks, Howard On Sat, Apr 3, 2010 at 8:27 PM, Tony M pqj...@yahoo.com wrote: My formula generates a lot of signals every day, and my max position is set to 10. So I use a PositionScore to rank the stocks that have a buy signal and buy at the open the next day. On the first day of backtesting, the top ten stocks ranked by PositionScore are picked and bought. This is exactly what I want it to happen. At the closing of first day, three stocks meet the exit criteria and get sold. On the second day backtesting, there are total seven old positions and three new stocks are bought. However the three new stocks get selected are not the highest ranking stocks in the PositionScore list. The three stocks are ranked No. 3rd, 18th and 25th in the PositionScore list. This is very puzzling to me. My formula is very simple and is like this: BUY = condition1 and condition2 and condition3; PosQty = 10; SetOption(MaxOpenPositions, PosQty ); PositionSize = -100/PosQty; SetTradeDelays(1,0,0,0); BuyPrice = Open; Sell = sell_condition; SellPrice = Close; PositionScore=100-RSI(14); My question is why PositionScore works perfectly on the first day of backtesting, but not the days thereafter? I have been working on this question for quite a few days, but I just couldn't find an answer. Can anyone here help me on this? Thanks, Tony
Re: [amibroker] Re: Exponential Moving Average
Greetings -- There may be two questions in this thread. Question 1 -- What is the relationship between the smoothing constant and the lag. Given a Simple Moving Average with a lookback of SMALength (say, 10 bars), what is the smoothing constant for an Exponential Moving Average that performs approximately the same smoothing as the SMA? The name given to the smoothing constant is alpha. An EMA is defined by a recursive relationship, here based on Closing price, C: E[0] = C[0]; E[i] = alpha*C[i] + (1-alpha)*E[i-1]; i is the index that starts at the oldest data point and continues through the most recent data point. alpha is the smoothing constant that defines the EMA. alpha is approximately 2/(SMALength+1) A SMA using a lookback of 10 bars is roughly equivalent to an EMA using an alpha of 2/(10+1) = 2/11 = 0.1818. When a formula using an Exponential Moving Average is specified, it is defined by its lookback period, EMALength. For example: EMALength = 10; Sm = EMA(C,EMALength); Within the compiler, ELALength is used to compute alpha, and the series Sm is computed using the recursive relationship. You can compute your own EMA using this afl code: EMALength = 10; alpha = 2/(EMALength+1); CustomEMA[0] = C[0]; for (i=1; iBarCount; i++) { CustomEMA[i] = alpha*C[i] + (1-alpha)*CustomEMA[i-1]; } Plot(CustomEMA,CustomEMA,colorblue,styleline); Question 2 -- When optimizing a system based on the crossover of two moving averages, how to keep the length of the second period greater than the length of the first. FastLength = Optimize(FastLength,5,1,10,1); SlowIncrement = Optimize(SlowIncrement,1,1,20,1); SlowLength = FastLength + SlowIncrement; FastMA = EMA(C,FastLength); SlowMA = EMA(C,SlowLength); Buy = Cross(FastMA,SlowMA); Sell = Cross(SlowMA,FastMA); -- Thanks, Howard On Fri, Mar 26, 2010 at 9:31 PM, Mike sfclimb...@yahoo.com wrote: Keith, He was asking for the smoothing factor, not the period. The smoothing factor is a value between 0 and 1, as described in the document pointed to by his link. It is a good question. After some brief searching, I could not find the answer. Though, I suppose you could fire up a chart using a short period and do the math, as per the comments of DEMA. http://www.amibroker.com/guide/afl/afl_view.php?id=42 Mike --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Keith McCombs kmcco...@... wrote: It's settable by you. Right click in the chart that is displaying ema. Select edit formula, and find EMA(n) -- n is the period and you can set it to whatever you want. On 3/26/2010 18:48, mpdx58 wrote: Does anyone know what the smoothing factor is that Amibroker uses when calculating the exponential moving average? http://en.wikipedia.org/wiki/Exponential_smoothing#The_exponential_moving_average http://en.wikipedia.org/wiki/Exponential_smoothing#The_exponential_moving_average
Re: [amibroker] rotational trading buying time
Hi Donald -- Does something like this work for you? TradingDay = 15; dn = Day(); newMonth = (dn=TradingDay) (Ref(dn,-1)TradingDay); Thanks, Howard On Sat, Mar 20, 2010 at 7:36 AM, donald_brown_48367 donald_brown_48...@yahoo.com wrote: I have a rotational system that rotates at the beginnning of each month using this code; m = Month(); newMonth = m != Ref( m, -1); PositionScore = IIf(PositionScore 0, 0, PositionScore); // Long only PositionScore = IIf(newMonth, PositionScore, scoreNoRotate); Is there an easy way of changing the rotation to any particular day of the month, say the 15th? (Or nearest trading day if this falls on the weekend).
Re: [amibroker] AmiBroker as an intraday trading platform
Yes On Mon, Mar 8, 2010 at 3:38 AM, victorio91306 vabb...@socal.rr.com wrote: Is the AmiBroker software a viable platform to day trade The ESMINI.
Re: [amibroker] Amibroker Perspective
Hi Jchi -- Herman is right. When profits look too good to be true, the first thing I check for is a future leak -- using data in the trading system code that is available to the backtester that would not be available to the trader. Depending on the code used, checking this might be as easy as using the Code Check and Profile tool available from the Formula Editor's Tools menu. Included files (#include) are checked, but dlls are not checked by this tool. There are several ways you can adjust for commission and slippage. One is using the Backtester Settings tab from the Automatic Analysis dialog box. Another is add a slippage adjustment that you define to the BuyPrice and SellPrice variables. Thanks, Howard On Mon, Mar 8, 2010 at 8:31 AM, jchi18 inbox@gmail.com wrote: What has been people's experience with Amibroker in terms of accuracy? Initially, I found it very difficult to design a system that makes a decent profit. However, I have recently designed a system that would have netted me (through the backtester years 2000-2010) almost $1 billion dollars had I not put an positionsize restrictions on it. Now that seems obviously unrealistic. Now I made my positionsize a little more realistic (a scale of 10-30% of current equity). And I am still coming up with $29 million over the past ten years. I am wondering what I may be doing incorrectly. Here are some questions: 1. How accurate is amibroker with an EOD trend following design where I buy or short on the open after the trigger? 2. What sort of things do I have to be aware of to make the system more realistic? 3. How do you account for slippage in your EOD trading system? 4. On a different note, what is the most profit that you were able to backtest? I just want to understand and be realistic with what I have designed. I am a little naive because I have already started dreaming about my new found wealth. I would appreciate any thoughts.
Re: [amibroker] Adding Colums to Backtest
Hi Jchi -- I recommend that you do this in two steps. One -- write the trading system, including Buy and Sell statements. Use the Automatic Analysis Backtest button to run the backtest and get trading results. Two -- add AddColumn statements to the code. (See the reference materials for examples) Use the Explore button to get a listing in the Results window with a column for everything you want listed and a row for every bar you want that list to include. Thanks, Howard On Sat, Feb 27, 2010 at 8:16 AM, jchi18 inbox@gmail.com wrote: Is there a way to add columns to the backtest results that show: 1. The MACD at the time of trigger 2. RSI at the time of trigger Thanks.
Re: [amibroker] Few Newbie Questions
Hi Jchi -- High quality, low cost end-of-day data is available from several vendors. Two I recommend (I subscribe to them both) are: Quotes Plus -- http://qp2.com/joomla/index.php Norgate Premium Data -- http://www.premiumdata.net/ Read the reference materials related to BuyPrice, SellPrice, and TradeDelays. They work in combination. The pair of statements BuyPrice = Open; SetTradeDelays(0,x,x,x); uses the price of the open of the bar being processed. The pair of statements BuyPrice = Open; SetTradeDelays(1,x,x,x); uses the price of the open of the bar following the bar being processed. Thanks, Howard On Fri, Feb 26, 2010 at 3:58 PM, jchi18 inbox@gmail.com wrote: 1. When is the earliest I can download EOD data from Yahoo? i.e., when will today's data be available for download? 2. In the trades tab when performing automatic analysis, what does buy price mean if I set it to open? i.e., I perform a scan of my trading system and it says that a buy signal was found for 2/26/10. When it is set to buy at the open price, will amibroker get the open price of 2/26 or 2/27? 3. What is the best but reasonably priced way of getting accurate EOD data into amibroker? I understand that Yahoo is inaccurate. Feel free to contact me at inbox@gmail.com inbox.chi%40gmail.com. THanks.
Re: [amibroker] Re: Walk Forward IS/OOS Period Optimization?
Hi SpaceBass -- I would like to read your paper. Let us know how to get a copy. Thanks, Howard On Mon, Feb 22, 2010 at 9:39 PM, spacebass5000 spacebass5...@yahoo.comwrote: Awesome, lots to ponder. Thanks a lot for the input everyone! I'm actually writing a paper that looks at various Quant Trading models and need to hash out my OOS/IS periods. You all have been a big help. --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, spacebass5000 spacebass5...@... wrote: I was wondering if there was a way to optimize the In-Sample and Step time periods within AB. If not, can someone point me in the direction of a good resource on this topic?
Re: [amibroker] AddToComposite - using PremiumData
Hi Pat -- I regularly use AddToComposite with data from Norgate Premium Data without any difficulty. I suspect the problem is with the way ATC is being used, not with the data. Post the entire code so we can look at it. (Or make up a small program that fails to work correctly to illustrate your problem) Thanks, Howard On Sun, Feb 21, 2010 at 7:35 PM, patsgreatdeals patsgreatde...@yahoo.comwrote: Using AddToComposite along with PremiumData.net I get no results once the composite is built using Scan. I get the ~Composite calculated, but there is nothing in it. I used AddToComp a while back with no issues and used AMIQuote at that time. Now that I switched to premium data I am not getting any results. I am not saving the PremiumData in the native AMIBroker database, is this why I am not getting any results? Has anyone experienced this issue?
Re: [amibroker] Scale in and exit signal on the same bar
Hi Pedro -- For any single bar, you know the values of four data points -- Open, High, Low, and Close. You know the time of two data points -- Open and Close. There is no way to determine the sequence in which any prices other than Open and Close occur. You can, within one bar do any of these things: 1. Buy the Open. Then exit at a stop, at a limit, or at the Close. 2. Buy sometime within the bar at a stop or at a limit. Then sell at the Close. 3. Buy at the Open. Then sell at the Close. These have no scaling. You are certain of enough information to make one entry and one exit. You cannot rely on assumptions of prices that would both buy and sell within a single bar -- that is after the open but before the close. It sounds like you need bars with finer resolution, then take the actions you can be sure of without ambiguity in each bar. Thanks, Howard On Tue, Feb 23, 2010 at 6:55 AM, Pmxgs pm...@vizzavi.pt wrote: Hello, in the system I'm coding I have several scale in signals and it's working the way I expect, except at some bars which have both a scale in signal and the sell signal (profit target). I ran the backtest in the detailed log mode and from my understanding AB first closes the position (based on the sell signal) and then opens a new one (based on that scale in signal), which is not what I want. I want to scale in first and after that close the position. I should note that I'm not trading at the close nor at the open. I scale in at several prices inside each bar, and the scale in price in below the sell price (in the case of a long position). Is it possible to change the default behaviour of AB, so that it scales in first and only then, exit the position? (in these cases where we have both signals on the same bar) thanks, Pedro
Re: [amibroker] Re: Mutual funds are outperforming ETFs big time, but they sh...
Hi Kevin -- There are several difference between ETNs and ETFs. ETNs make up less than 1% of the ETF/ETN products. A few of them have reasonable volume, but most do not. There can be tracking error (and arbitrage opportunity for major players) with ETNs. ETNs are not equities, or baskets of equities, they are swaps. As you point out, there is greater counterparty risk with ETNs. Thanks, Howard On Tue, Feb 23, 2010 at 10:57 AM, kevin...@aol.com wrote: How about ETN's, shouldn't ETN's not have this issue?. of course they have other issues, like whether the underlying Bank stays in business Kevin
Re: [amibroker] Walk Forward IS/OOS Period Optimization?
Hi Joris, and all -- If the typical time a trade is held, and trading frequency is fairly constant, both of which I recommend, then constant time periods will have similar number of trades. Some of us carry on a lot of our lives using time to schedule -- how many dollars per year we earn, how many calories per day we eat, how many miles per week we run. So it does make sense to compare trading system performance over equal length time periods -- how many dollars per year the system makes. The logistics are considerably more complicated to run walk forward testing using number of trades rather than number of bars. Be careful when evaluating out-of-sample results. If the system is modified based on out-of-sample results, the data used to produce those OOS results is no longer out-of-sample, but is now part of the in-sample data. Subsequent test results, even when the previously OOS data was not explicitly included in the in-sample data mining, no longer give an unbiased estimate of future performance. Rather, the estimate of future performance is overestimated and of risk is underestimated. Thanks for listening, Howard
Re: [amibroker] Re: Pyramiding / ScaleIn Questions
Greetings all -- An earlier post in this thread: I also read Connor's book and found many of his strategies worked, probably because they were simple. I did not find that scaling in, as is being discussed in this thread, worked better than just buying a full position. Anyone else come up with the same conclusions? Larry I have done quite a lot of research into scaling in, scaling out, placing stops, moving stops to break even, and so forth. I have found very few situations where scaling in or scaling out was a better implementation technique than full entry and full exit. Thanks, Howard
Re: [amibroker] Walk Forward IS/OOS Period Optimization?
Hi SpaceBass -- The only way to determine the correct length for the in-sample period is by running experiments. The length needs to be long enough for the model to synchronize with the data and learn to recognize the signal. But not so long that the signal has changed significantly, making it hard to identify. And not so short that there is not enough signal to learn, resulting in a system that has synced to the noise. In a few words -- the length of the in-sample period should be as short as is practical and effective. Once the length of the in-sample period has been determined, the length of the out-of-sample period is easy. It is the length of time that the system remains profitable. There is no general relationship between the anything and the length of the in-sample period. There is no relationship between the length of the in-sample period and the length of the out-of-sample period. There is some controversy in the modeling and simulation field about whether the in-sample length is a legitimate variable in an optimization. While it can be dangerous to system validity to run an optimization on in-sample length, some trials using different lengths are necessary. Thanks for listening, Howard On Thu, Feb 18, 2010 at 7:23 PM, spacebass5000 spacebass5...@yahoo.comwrote: I was wondering if there was a way to optimize the In-Sample and Step time periods within AB. If not, can someone point me in the direction of a good resource on this topic?
Re: [amibroker] Walk Forward IS/OOS Period Optimization?
Hi Herman, and all -- The issue determining the length of the in-sample period is not the number of trades, but the number of data points it takes for the model (afl) and the data (OHLC) to become synchronized. Imagine a model that is looking for cyclic behavior in the data. If the cycle completes in one month it takes many fewer data points to sync than if the cycle completes in one year. As for out-of-sample, the statistics can be run on any number of data points. The data points can be daily equity changes or closed trades -- whatever time granularity the trader will be making position adjustments. Providing the relationship between the mean of the metric being studied, its standard deviation, and the number of data points is reasonable, control charts can used to indicate when the system is operating well and when it is beginning to fail. Assume the metric is expectancy. If the mean expectancy is positive and the ratio of the mean to the standard deviation is high (high would be a ratio of 0.5, extremely high would be 1.0, normal would be 0.2), it takes fewer than 20 trades to have very high confidence that the system is performing well. Since systems go out of sync -- either periodically or forever -- once there are enough OOS data points to give the confidence that the developer requires, there is no benefit in waiting for further confirmation. Trade now, while the system is in sync. Thanks for listening, Howard On Fri, Feb 19, 2010 at 6:51 AM, Herman vandenBergen psy...@magma.cawrote: Hello Howard, I cannot help but wonder why the OOS periods in optimizations aren't based on the number of trades, instead of some arbitrary time period. Could it be that this is just another example of how TA methodology is based on convenience, i.e., a reluctance to redesign tools and/or a reluctance to change :-) I am no statistician, but I would guess that if one wanted some specific OOS performance the first thing to do would be to figure out how many trades would be needed to do the calculations. If 100 trades gives you the confidence why would you run a OOS period that gives you 200 trades? Best regards, herman Friday, February 19, 2010, 8:18:45 AM, you wrote: Hi SpaceBass -- The only way to determine the correct length for the in-sample period is by running experiments. The length needs to be long enough for the model to synchronize with the data and learn to recognize the signal. But not so long that the signal has changed significantly, making it hard to identify. And not so short that there is not enough signal to learn, resulting in a system that has synced to the noise. In a few words -- the length of the in-sample period should be as short as is practical and effective. Once the length of the in-sample period has been determined, the length of the out-of-sample period is easy. It is the length of time that the system remains profitable. There is no general relationship between the anything and the length of the in-sample period. There is no relationship between the length of the in-sample period and the length of the out-of-sample period. There is some controversy in the modeling and simulation field about whether the in-sample length is a legitimate variable in an optimization. While it can be dangerous to system validity to run an optimization on in-sample length, some trials using different lengths are necessary. Thanks for listening, Howard On Thu, Feb 18, 2010 at 7:23 PM, spacebass5000 spacebass5...@yahoo.com wrote: I was wondering if there was a way to optimize the In-Sample and Step time periods within AB. If not, can someone point me in the direction of a good resource on this topic?
Re: [amibroker] Re: Pyramiding / ScaleIn Questions
Hi Richard, and all -- I categorize exits in several general ways. 1. The exit from the logic of the trading system. This is usually the best exit. Exits that can be good include: 2. Exit caused by a trailing stop that follows the price movement in the direction of the trade -- the stop portion of the Parabolic Stop And Reverse or the Chandelier stop as examples. This is often an excellent exit for a trend-following system. It requires a few bars in the trade for the exit level to catch up to the price, so this is best used with trades that hold at least a few bars. It works with daily or intra-day bars. 3. Exit caused by a profit target being met. This is often an excellent exit for a system that holds only a few bars and is never looking for the big win. In order to be a valid exit, the profit target must be the exit a substantial portion of the exits -- cherry picking is not allowed. 4. Exit caused by a time limit running down. This could be a stop strictly based on time, as in holding a maximum number of bars. Or it could be an inactivity exit, as in exit when there has not been favorable price movement within some number of bars. The poorest exit: 5. Exit because a maximum loss limit has been reached. This is the exit of last resort. It is easy to test yourself. Beginning with any trading system, add a maximum loss stop using the ApplyStop function. Set the limit so far away that it is never hit and run a backtest. Gradually bring the stop closer. Note the system performance as the loss point is closer to the entry and the maximum loss stop is hit a greater percentage of the time. System performance usually degrades. Moving an exit to break even falls into this last category. It is always an attractive sounding exit -- giving you a free trade, and all -- but seldom performs as well as expected. If you plan to use it, test it for yourself. By all means --- if you have a trading system where these generalities do not hold, do not be bound by them. I am not suggesting that one solution fits all situations, or that these exits will perform in the order I have listed for your system. But do perform your own tests so that you understand how your exits work with your systems. Thanks for listening, Howard
Re: [amibroker] Re: Can Amibroker handle small decimal numbers?
Hi Zozu -- K-ratio is one of the metrics that is computed by AmiBroker and reported. If you are creating a custom objective function, you can include a term related to k-ratio. In that term, you can refer to the values that are typically reported. For example, require that k-ratio be = 0.05. All values stored in AmiBroker variables are stored as floating point numbers and are in IEEE single precision (32 bit) floating point notation. The form of the number is .xxxeyy, where xxx is about 7 decimal digits of significance and yy is an exponent. Together they allow numbers of either sign with absolute values between about 10^-38 and 10^38 to be stored. Some of the difficulty using very small numbers comes when they are added to larger numbers. Only the 7 most significant digits are stored -- all the information in digits from 8 on is lost. Thanks, Howard On Wed, Feb 17, 2010 at 3:00 PM, zozuzoza zoz...@gmail.com wrote: Hi Howard I meant kratio for example that have typical values of 0.01. If I use it as a fitness function, do I need to multiply by 100? Or if I optimise a parameter that have 0.01 step? Br, Zozu --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Howard B howardba...@... wrote: Hi Zozu -- How small are the numbers and how are you using them? Multiplying by 100 or 1000 is often useful when working with indicator values so that they scale reasonably when plotted. Multiplying by 100 or 1000 may be useful when combining a variable with a small value with a variable with a large value so that the significant digits of the smaller value are retained. Adding a constant and / or multiplying by a constant may be necessary to create a number that has a positive integer part if that value will be added to a composite and stored in the volume field. Thanks, Howard On Tue, Feb 16, 2010 at 5:23 AM, droskill drosk...@... wrote: I haven't read the book - but for me it hasn't been a problem - I routinely use small numbers as you describe them --- In amibroker@yahoogroups.com amibroker%40yahoogroups.comamibroker% 40yahoogroups.com, zozuzoza zozuka@ wrote: Hi, I am reading in Howard's book that 'Amibroker handles the negative values without and problem, but the small numbers loose all the significance beyond the decimal point.' Furthermore Howard recommend to multiply the numbers below 1 by 100 or 1000. Is it really the case?
Re: [amibroker] Re: Can Amibroker handle small decimal numbers?
Hi Zozu -- How small are the numbers and how are you using them? Multiplying by 100 or 1000 is often useful when working with indicator values so that they scale reasonably when plotted. Multiplying by 100 or 1000 may be useful when combining a variable with a small value with a variable with a large value so that the significant digits of the smaller value are retained. Adding a constant and / or multiplying by a constant may be necessary to create a number that has a positive integer part if that value will be added to a composite and stored in the volume field. Thanks, Howard On Tue, Feb 16, 2010 at 5:23 AM, droskill drosk...@yahoo.com wrote: I haven't read the book - but for me it hasn't been a problem - I routinely use small numbers as you describe them --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, zozuzoza zoz...@... wrote: Hi, I am reading in Howard's book that 'Amibroker handles the negative values without and problem, but the small numbers loose all the significance beyond the decimal point.' Furthermore Howard recommend to multiply the numbers below 1 by 100 or 1000. Is it really the case?
Re: [amibroker] Re: statistivcs definition
Industrial Strength Is that a good thing or a bad thing? Thanks, Howard On Tue, Feb 9, 2010 at 9:00 PM, reefbreak_sd reefbreak...@yahoo.com wrote: I am no expert in backtesting, you need to address those questions to Howard Bandy on this forum or buy his EXCELLENT book Quantitative Trading Systems where he creates and backtests a variety of trading sysstems along with commentary. I understand Howard is coming out with an advanced version very soon. Also he has available a recording of a lecture he gave in Australia detailing the development and backtesting of a trading system. The cost is a trivial $1.95, but beware the lecture is industrial strength. You can limit the dollar size of each position and limit the number of positions you can hold, thereby removing the total dollars in the account as a determinant of profit. Also note that there is several different levels of running the backtester. Allowing a very high level of control over what it does - This comes at a cost of complexity of programming. You can add custom written calculations to the backtest report. Reef PS I personally feel that backtesting is a hall of mirrors where you can easily fool yourself into thinking that you have a profitable system when you don't. Or conversely - needlessly discard a workable system because of poor backtest results. Be VERY skeptical of any results either good or bad. --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Ted Byers r.ted.by...@... wrote: Thanks. That helped a lot. However, I am not especially happy with the following: System test report window correctly_annualized_perc_return = 100% * ( (final_value/initial_value) ^ ( 365 / days_in_test ) - 1 ) where x^y means rising x to the power of y The problem I find lays in knowing precisely what initial_value is supposed to be. Yes, the formula is correct, and makes sense, if the initial value is fully utilized in the investment (such as the initial and final value of a house one has purchased). However, in the system I am working on, at no point does the total value of all open positions exceed $100,000, and yet I have been instructed to set, as a default for backtesting purposes, initial cash at 1,000,000 (the trader we're working with doesn't want to deal with any limits posed by the available cash). But that means I can arbitrarily improve the rate of return by a factor of ten if I use an initial value of 100,000 or arbitrarily make it worse by using an initial value of 2,000,000. Obviously, I can't use an initial value less than 100,000 or the trades the system recommends would not be possible, but apart from that constraint, that I can arbitrarily alter initial value without affecting total return seems to make this figure just so much meaningless BS. At no time, when using this code, is position size computed from the available cash. How, then, can I define things in such a way that ensures that the rate of return actually has a meaningful value? So far, it seems I can only compute a meaningful value for the rate of return for a specific trade (where the initial value is obviously the cost of buying the shares, for a long position, or the value received from the sale of shares, for a short position), but not for a collection of trades distributed over a period of several years. Is there a standard way for handling this? One that is demonstrably valid? Thanks Ted On Mon, Feb 8, 2010 at 4:11 PM, reefbreak_sd reefbreak...@... wrote: In AB, click on HELP - SEARCH type in BackTester Report in the search window Under the Select Topic that comes back, click on System Test Report Window and you will see a definition of each term. Many of these are industry standard metrics of performance. You can go to www.investopedia.com and type in for example risk adjusted return and get a more detailed explaination of most of the report items. Reef --- In amibroker@yahoogroups.com amibroker%40yahoogroups.comamibroker% 40yahoogroups.com, Ted Byers r.ted.byers@ wrote: Hi All, I am digging into how AmiBroker computes the various statistics it reports on a given back test. For example, I see the following reported: Exposure % Net Risk Adjusted Return % Annual Return % Risk Adjusted Return % Where will I find the details of exactly how AmiBroker computes these from a given suite of trades? Now, I know what a risk adjusted return is, but in my previous work, it is based on 100% of the cash being invested, and it carries a specific definition of risk. In the system I am working with now, it is rare for 100% of the available cash to be invested, and a really really long lived trade lasts only a couple weeks (though 9 out of 10 trades were profitable in my last back test using my
Re: [amibroker] Monte Carlo Analysis in AMIBROKER?
Hi Joseph -- One straightforward way to study the effect of survivorship bias is to set up a watchlist for each period. Enter the tickers of those issues that are components of that index at the beginning of the period. On the AA Settings dialog box, select a watchlist and set the Range to the dates that watchlist would have been current. Click Backtest or Explore. You can make a single run with the date range set to a longer period, but you still need some way of identifying which issues to use for which date range. You could use a watchlist for each period, then have the afl check the date being processed and verify that the ticker being processed is a member of the watchlist that goes with that period. Coding that in the afl is possible but tedious to code and hard to maintain. The first way will probably give some distortion at the date boundaries for those trades that are open across the boundary when the watchlist changes. Since you hold no position overnight, you will not be affected by this. The second way avoids the boundary problem, but at considerable added program complexity. The longer typical positions are held and the further back in time the tests are run, the more survivorship bias becomes an issue. The key to avoiding survivorship bias is to work with a list of tickers that you would have chosen if you were running the tests on the date the test date range begins. Thanks, Howard On Sun, Jan 24, 2010 at 8:27 PM, Joseph Occhipinti joseph_occhipi...@yahoo.com wrote: Thank you Howard Greatly appreciated Just a question regarding the following comment of yours: *Use the lists of stocks that were in an index at the start of each year and run tests one year at a time, with lists reconstructed at the beginning of each year.* * * Instead of back testing 'All Quatotaions', I select 'From' (selecting one year at a time), will this address the issue of survivorship bias? As an example: as at 01/01/2008 a b c d e as at 01/01/2009 a b c d as at 25/01/2010 a b c If I were to run tests one year at a time - say i chose 01/01/2008 to 01/01/2009 - does that mean that AB will only pick up stocks a, b and c given they are the only ones left in the index as at todays date? Or will AB pick the results of a,b,c,d and e for that year? And then simply omit 'e' for the following year's test? (When a stocks get delisted does that mean it is ommitted from any historical testing done?) MY SYSTEM: In short, my system is an intraday one - im in by the open and out by the close. So i hold no stocks overnight. So i am not exposed to trading halts or overnight gaps etc. (not sure if this makes a difference) Thanks again for your time Howard
Re: [amibroker] Re: Monte Carlo Analysis in AMIBROKER?
Greetings -- Norgate Premium Data, a subscription service with end-of-day and snapshot data, maintains historical data for delisted stocks on US and Australian markets. They are in the process of preparing historical lists of components of indexes, including changes and change dates. Thanks, Howard On Mon, Jan 25, 2010 at 10:53 AM, Mike sfclimb...@yahoo.com wrote: If I were to run tests one year at a time - say i chose 01/01/2008 to 01/01/2009 - does that mean that AB will only pick up stocks a, b and c given they are the only ones left in the index as at todays date? Most likely your data provider will have deleted the remaining symbols from your database such that, yes, only {a, b, c} will be used at any date. Some providers will have moved the symbol to a special 'delisted' area, but they might no longer be marked as included in the index. So, again, only {a, b, c} will be used. Mike --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Joseph Occhipinti joseph_occhipi...@... wrote: Thank you Howard Greatly appreciated Just a question regarding the following comment of yours: Use the lists of stocks that were in an index at the start of each year and run tests one year at a time, with lists reconstructed at the beginning of each year. Instead of back testing 'All Quatotaions', I select 'From' (selecting one year at a time), will this address the issue of survivorship bias? As an example: as at 01/01/2008 a b c d e as at 01/01/2009 a b c d as at 25/01/2010 a b c If I were to run tests one year at a time - say i chose 01/01/2008 to 01/01/2009 - does that mean that AB will only pick up stocks a, b and c given they are the only ones left in the index as at todays date? Or will AB pick the results of a,b,c,d and e for that year? And then simply omit 'e' for the following year's test? (When a stocks get delisted does that mean it is ommitted from any historical testing done?) MY SYSTEM: In short, my system is an intraday one - im in by the open and out by the close. So i hold no stocks overnight. So i am not exposed to trading halts or overnight gaps etc. (not sure if this makes a difference) Thanks again for your time Howard From: Howard B howardba...@... To: amibroker@yahoogroups.com amibroker%40yahoogroups.com Sent: Mon, 25 January, 2010 4:12:08 AM Subject: Re: [amibroker] Monte Carlo Analysis in AMIBROKER? Hi Joseph -- There are many uses of Monte Carlo in the fields of econometrics and financial analysis and modeling. But the three described below are the most applicable to trading systems development. Some are easy to implement in AmiBroker, others are more difficult. Some are useful, others are not useful or poor practice. 1. Use Monte Carlo techniques to study the robustness of a trading system to small changes in the data. Small, random amounts of noise can be added to the open, high, low, close, and volume to see if the trading system is sensitive to noise in the data. This is easily done and useful. There is a more detailed explanation, including code, in my book, Quantitative Trading Systems. 2. Use Monte Carlo techniques to study the robustness of a trading system to small changes in values of parameters. When an optimization is performed, the value of an objective function is calculated for every set of parameter values tested. The best set of parameters is the set that give the highest value of the objective function. If we consider a two dimensional optimization, say the lengths of two moving averages, then we can imagine and visualize the objective function as a surface above (or below) the plane defined by the two variables. If the highest value of the objective function is an isolated peak, then the system is sensitive to changes in the relationship between the model and the data being modeled, and even small changes in the characteristics of the data will cause a shift in the position of the optimal solution. That is, the system is not robust relative to changes in the values of the parameters. If, on the other hand, the highest value of the objective function is a broad plateau, then the system is relatively insensitive to changes in the relationship between the model and the data and small changes in the characteristics of the data will not result in significant changes in the profitability of the system. That is, the system is robust relative to changes in the values of the parameters. Monte Carlo techniques can be used to study the sensitivity of the system by adding random noise to the values of the parameters, testing solutions near the optimal solution. There are many subtle issues that arise when performing this type of study, making general solutions very difficult. Specific solutions are easy
Re: [amibroker] Monte Carlo Analysis in AMIBROKER?
Hi Joseph -- There are many uses of Monte Carlo in the fields of econometrics and financial analysis and modeling. But the three described below are the most applicable to trading systems development. Some are easy to implement in AmiBroker, others are more difficult. Some are useful, others are not useful or poor practice. 1. Use Monte Carlo techniques to study the robustness of a trading system to small changes in the data. Small, random amounts of noise can be added to the open, high, low, close, and volume to see if the trading system is sensitive to noise in the data. This is easily done and useful. There is a more detailed explanation, including code, in my book, Quantitative Trading Systems. 2. Use Monte Carlo techniques to study the robustness of a trading system to small changes in values of parameters. When an optimization is performed, the value of an objective function is calculated for every set of parameter values tested. The best set of parameters is the set that give the highest value of the objective function. If we consider a two dimensional optimization, say the lengths of two moving averages, then we can imagine and visualize the objective function as a surface above (or below) the plane defined by the two variables. If the highest value of the objective function is an isolated peak, then the system is sensitive to changes in the relationship between the model and the data being modeled, and even small changes in the characteristics of the data will cause a shift in the position of the optimal solution. That is, the system is not robust relative to changes in the values of the parameters. If, on the other hand, the highest value of the objective function is a broad plateau, then the system is relatively insensitive to changes in the relationship between the model and the data and small changes in the characteristics of the data will not result in significant changes in the profitability of the system. That is, the system is robust relative to changes in the values of the parameters. Monte Carlo techniques can be used to study the sensitivity of the system by adding random noise to the values of the parameters, testing solutions near the optimal solution. There are many subtle issues that arise when performing this type of study, making general solutions very difficult. Specific solutions are easy to code by running a second set of optimizations that look at the solution space near the previously selected optimum. Additionally, some of the optimization methods included with current releases of AmiBroker (such as the non-exhaustive method known as cmae -- Covariance Matrix Adaptation Evolutionary Strategy) have a robustness component that is used with no need for additional coding by the trading system developer. 3. Monte Carlo techniques can be used to study the risk profile of a sequence of trades. Your question prompts me to ask how the tests you are running are defined. If the universe of stocks being tested is comprised of the 3000 stocks that are the current members of the Russell 3000 index, and the test period is the past ten years, then there is a considerable survivorship bias in the test runs. That is, the 3000 companies that are in the index now have survived the past ten years, but those companies that disappeared during that period are not included in the tests. That bias strongly affects the test results. In some of my research, I have compared two studies: 1. Use the list of stocks currently in an index. 2. Use the lists of stocks that were in an index at the start of each year and run tests one year at a time, with lists reconstructed at the beginning of each year. The results of the first study are always significantly better than the results of the second study. Ignoring the survivorship bias will cause the trading system developer to significantly over-estimate the likelihood that the system will be profitable in the future. Norgate Premium Data (http://www.premiumdata.net/) is an excellent source of end-of-day data for the US and Australian markets, including data for issues that have been delisted. They are in the process of developing historical lists of components of major indexes which will be very valuable for study of the effects of survivorship. Your question also raises a related issue about how trades are selected. Some developers run a general test using a large universe of possible issues to trade, which results in a number of potential positions to enter that is greater than the funds available to take those positions. They then consider using Monte Carlo techniques to analyze what might happen if different combinations of issues are purchased. This is an inappropriate use of Monte Carlo analysis and is poor trading system development practice. I do not know of a single trader or trading company who runs a test or report, generates a list of signals, sees that it has more signals than he or she has money, and rolls dice to determine which of the
Re: [amibroker] Monte Carlo Analysis in AMIBROKER?
Hi Ton -- Yes, Equity Monaco is a NeoTicker product. It accepts a list of closed trades from a text file as input. You can get that by exporting results from the AA report, cleaning it up with a spreadsheet if necessary, and importing it into Equity Monaco. You definitely can use Equity Monaco with AmiBroker. My next book is Advanced AmiBroker. I am taking a short break from working on it this morning to read postings to the forum. Writing is going well, but some of my other projects have had big increases in activity and are competing heavily for time, so the book is not yet ready for the editors or the printer. No promises, and no pre-orders yet, but the availability date now looks to be April or May 2010. Thanks, Howard On Sun, Jan 24, 2010 at 10:44 AM, Ton Sieverding ton.sieverd...@scarlet.bewrote: Hi Howard, *Returning to the question of reordering trades to study the risk associated with the trading system. Use of Monte Carlo analysis in this area is very valuable. It is best done using a program that accepts a list of closed trades and performs the risk analysis. Equity Monaco, available free (**http://www.tickquest.com/product/equitymonaco.html*http://www.tickquest.com/product/equitymonaco.html *), is a good one to start with. And Market Systems Analyzer (** http://adaptrade.com/* http://adaptrade.com/*) has more capability and a trial version.* My experience with Equity Monaco stops at the first page of the manual. Isn't this a NeoTicker product ? Or at least for NeoTicker. Can I use it with AmiBroker ? oh yes, something else. And you know what ... your next book. When ? Regards, Ton.
Re: [amibroker] Monte Carlo Analysis in AMIBROKER?
Hi Markus -- I also own Tharp's books. He does use a proprietary package called Know Your System for his analysis. There are many ways to use Monte Carlo techniques. The different algorithms are more about generating random numbers and defining the distributions from which the random values are drawn and the way they are used. Tomasz has implemented the Mersenne Twister algorithm in AmiBroker. Mersenne twister is much better (higher in metrics that describe randomness, such as having a long period and not having patterns within the series) than the random number generators that come with C++, Excel, etc. If you use Excel for Monte Carlo analysis, be sure to get a Mersenne Twister Excel addin before you start. Here is one source: http://www.financial-risk-manager.com/risks/analytics/random/rand.html#mt19937. There are others. The distributions can be very problem specific, but all start out using uniform distributions and build from there to normal, and so forth. Back to Tharp. I have some criticisms of Tharp's Definitive Guide to Position Sizing. There are two in particular. 1. He arbitrarily and inappropriately sets an upper limit on the number of data points to be used in calculating his System Quality Number. (His SQN is essentially a t statistic, which he acknowledges in one sentence early in the book, but ignores from then on.) 2. He is completely unrealistic about what level of SQN trading system developers should be able to achieve. As a quick and dirty measure, a t statistic of about 2.0 suggests significance at about the 0.05 level for N of about 20 data points. A trading system that uses expectancy as its metric, computes the t statistic on actual trades or truly out-of-sample results (in-sample results have no value as estimators of future profitability), and has a t statistic of 2.5 to 3.0 will result in extraordinary profitability. Tharp talks about achieving scores of 6 or 7. Give any one of us a system that has a score of 6 and we can buy Manhattan in about a year starting from $10,000. So, read Tharp. His books do have value. But be aware that there are many aspects of trading system development, testing, and validation that he simply does not understand -- and some of his writing are seriously misleading. I have made many posts on Aussie Stock Forums ( http://www.aussiestockforums.com/) on this topic, and also on trading system development. Search using my name. I have corresponded with Van Tharp about some of these issues and he acknowledges my points. He even gives me credit in DGPS. One of the attendees of my workshops in Australia a few months ago is a personal friend of Vans and agrees with my assessment. Thanks, Howard On Sun, Jan 24, 2010 at 10:42 AM, Markus Witzler funny...@web.de wrote: Hello Howard, just stepping in here since MC analysis may be an issue keeping me busy in near future (though I haven´t yet developed much expertise in it). Are there different algorithms of MC simulators? I wonder what to look for when considerung a product, since different qualities in algorithms may turn out different levels of quality (i.e. what scenarios to expect in the future). Van Tharp for instance claimes to have Chris Anderson developed a software package called Know your system with an MC simulator in it - he uses it for studies for his book on money mangement which I own. I´m looking forward to buying your book since MC is covered there to as you said below... Thanks Markus
Re: [amibroker] Monte Carlo Analysis in AMIBROKER?
Hi Markus -- I am not the best person to ask about Intelligent Optimizer. I suggest that you address Fred Tonetti directly with those questions. Mersenne Twister is an algorithm for computing a series of pseudo-random numbers. A good source of random numbers is central to a Monte Carlo analysis program, but there is much more to it than that. Mersenne Twister would be or could be a component of a Monte Carlo analysis program, but by itself it is only a random number generator. And, yes, AmiBroker is the best trading system development platform available at any reasonable price. Thanks Tomasz. Before you begin writing your own Monte Carlo analysis program, or plug in for AmiBroker, define carefully what you want to accomplish. Reread my post to Joseph. Decide whether you are planning to be a developer of trading system development platform tools or a developer of trading systems. Evaluate the many tools already available. I just reread my post and my comments about Van Tharp. My criticisms sound harsher than I intended them to be. There is a lot to like in Tharp's work -- just keep in mind that he is an expert in Neuro Linguistic Programming, not modeling, simulation, statistics, or trading system development. Thanks, Howard On Sun, Jan 24, 2010 at 12:46 PM, Markus Witzler funny...@web.de wrote: Hello Howard, many thanks for your thorough explanation!!! Searching high and low the internet more often than not just adds to already exiting confusion... Thus, I´m really grateful for your summary! Monte Carlo has been a kind of a black box thing for me and still somewhat is. I infer from your post that Mersenne Twister is the best algorithm to date, so the AB community can be -once again!- glad to have Amibroker at its disposalG? When reading your answer to Joseph (today), I wondered what the difference between intelligent optimizer´s sensitivity analysis and a MC simulator´s test might be. Both aim at testing for robustness as far as I understand. I´m currently in the process of evaluating IO for my needs but I have never yet run a MC to test for robustness. So, I don´t now what it looks like. I don´t want to take away to much of your time and expect another detailed answer but 1./ could you just shortly elaborate on the difference between a sensitivity analysis, done by IO, and a test for robustness (i.e. sensitivity?) done thru a MC simulator? I understood there is currently no better choice than the combo of AB with Mersenne Twister at this point. 2. Incidentally, I wonder what modules one would need to have at hand or write himself (plugins for Amibroker?) to be able to run all the different tests Know your system software is able to produce (Amibroker plus Mersenne Twister, ...?). I´m asking since you said to be familiar with IITM stuff. If my questions are to far off-topic and might bore other forum members, just email me privately. And I am glad for your comments on Van Tharp´s work. Sometimes, he seems to shoot off the hip, if you know what I mean.. I certainly will look up your posts regarding this subject - thanks for mentioning. I like to verify both sides of the coin. I really appreciate your effort to help us newbies out there to broaden our horizins. Forums like this are a great place to be! Thanks again and all the best for your newest book project! Peace Markus - Original Message - *From:* Howard B howardba...@gmail.com *To:* amibroker@yahoogroups.com *Sent:* Sunday, January 24, 2010 7:33 PM *Subject:* Re: [amibroker] Monte Carlo Analysis in AMIBROKER? Hi Markus -- I also own Tharp's books. He does use a proprietary package called Know Your System for his analysis. There are many ways to use Monte Carlo techniques. The different algorithms are more about generating random numbers and defining the distributions from which the random values are drawn and the way they are used. Tomasz has implemented the Mersenne Twister algorithm in AmiBroker. Mersenne twister is much better (higher in metrics that describe randomness, such as having a long period and not having patterns within the series) than the random number generators that come with C++, Excel, etc. If you use Excel for Monte Carlo analysis, be sure to get a Mersenne Twister Excel addin before you start. Here is one source: http://www.financial-risk-manager.com/risks/analytics/random/rand.html#mt19937. There are others. The distributions can be very problem specific, but all start out using uniform distributions and build from there to normal, and so forth. Back to Tharp. I have some criticisms of Tharp's Definitive Guide to Position Sizing. There are two in particular. 1. He arbitrarily and inappropriately sets an upper limit on the number of data points to be used in calculating his System Quality Number. (His SQN is essentially a t statistic, which he acknowledges in one sentence early in the book, but ignores from
Re: [amibroker] Re: Options Pricing and Probability.
Hi rr -- Thanks for the kind words about my books. The Chicago Board Options Exchange (CBOE) calculates VIX -- the implied volatility (estimated volatility looking forward) of the SP 500 index. Their calculation uses 30 calendar days. In order to compare the historical volatility with the implied volatility, the two volatility measurements must be normalized to a common length of time. But any number of bars can be used -- whatever suits your purposes. The VIX is based on the prices of options, not the other way around. You can code Black-Scholes in afl and use it to calculate either: the implied volatility of an option when you know its price, or the behavior of the price of the option if you know its implied volatility. Using historical volatility in place of implied volatility may not be helpful. Historical volatility looks back in time at what has already happened, while implied volatility looks forward in time to what might happen in the future. If you want to use Black-Scholes within AmiBroker, you might try using VIX as a surrogate for the implied volatility in the option series you are working with. Calibrate the volatility of your underlying with the volatility of the SP 500 Index, than apply that ratio to the VIX. If you just want to know the current value of the greeks and do some what-if analysis, it might be easier to use one of the on-line, Excel, or stand-alone options calculators. Try these free sites: Crimson Mind Options Data -- www.crimsonmind.com/options IVolatility -- www.ivolatility.com Option Trading Tips -- www.optiontradingtips.com Option Price -- www.option-price.com Or these that are not free, but have trial versions: Visual Options Analyzer -- www.voptions.com Hoadley Option Tools -- www.hoadley.net/options/options.htm Excel Options Calculator -- www.kaininito.com/options/calculator Don't forget the industry sites: Chicago Board Options Exchange -- www.cboe.com Options Industry Council -- www.optionseducation.org/ Thanks, Howard On Fri, Jan 22, 2010 at 7:07 PM, rr879rr rr87...@yahoo.com wrote: Howard, Enjoyed reading your book Quantitative Trading Systems; quite useful. How do I calculate Historical Volatility? How far back would I have to look, if I am trading an expiry of 30 days? Coding a Black-Scholes model in to Amibroker could give a good intuitive feel for how the Option price and the Greeks react to the underlying and time decay. rr --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Howard B howardba...@... wrote: Greetings all -- Historical data for options is both difficult to obtain and generally not useful. Only the most active options trade regularly enough to give accurate and useful OHLCV data on their own. And options expire, which means that the active contract has a useful history of about one month. But you can do system design based on the underlying, then use an options price calculator, such as Black-Scholes, to estimate the price of an option of your choice at the time of the transaction. Options pricing depends on several major factors -- Price of the underlying, Strike Price of the option, Time to expiration, and Implied volatility. And on some minor factors (which can often be ignored) -- Risk-free interest rate, Dividend payment schedule. The first three of the four major factors are easy to determine. You can either use recent historical volatility to estimate implied volatility, or use one of the volatility indexes, such as VIX, as a surrogate for implied volatility and calibrate the relationship for the specific issue you will be trading. Thanks, Howard On Tue, Jan 19, 2010 at 5:24 AM, Anthony Faragasso ajf1...@... wrote: There is a Probability Calculator in the Library... - Original Message - *From:* rr879rr rr87...@... *To:* amibroker@yahoogroups.com amibroker%40yahoogroups.com *Sent:* Tuesday, January 19, 2010 3:07 AM *Subject:* [amibroker] Re: Options Pricing and Probability. --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, louies88 Louies88@ wrote: --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, rr879rr rr879rr@ wrote: Has anyone tried to do a Monte Carlo on the Probability value of the Underlying Stock at Option expiration (using Amibroker, of course)? Also, has any work being done in the area of Option Pricing and trading Options using Evolutionary Algorithms supported by Amibroker(CMAE or Particle-Swarm)? Maybe a little discussion on the above would be interesting. rr Hello RR I didn't know that you can trade/analyze options in Amibroker. How did you do that? Is there a link that I can find out more? thanks Amibroker provides you a programming language and the charting ability. So you can do any kind of analysis using Amibroker. If you
Re: [amibroker] Testing multiple exits
Hi Richard -- Something like this? /// //MultipleExits.afl // //Buy the first trading day of the month Buy = Month() != Ref(Month(),-1); WhichExit = Optimize(WhichExit,1,1,4,1); switch(WhichExit) { case 1: //Sell the first Wednesday Sell = DayOfWeek() == 3; break; case 2: //Sell using a 1% profit target ApplyStop(stopTypeProfit,stopModePercent,1,1); break; case 3: //Sell after a 5 day holding period ApplyStop( stopTypeNBar, stopModeBars, 5 ); break; default: //sell on the 20th Sell = Day()=20; break; } Thanks, Howard On Fri, Jan 22, 2010 at 5:14 AM, Richard richpa...@yahoo.com wrote: Hello, Is it possible or practical to test six different exit strategies in one optimization run? Could anyone point me to code example how this can be implemented? Regards Richard
Re: [amibroker] why is optimization for a large number of stocks so much slower?
Hi Steven -- The answer is in the combinatorics. If I ask for the best combination of, say, 5 stocks from among 20 choices, we are asking what is the best choice of 20, taken 5 at a time? The number of possibilities that must be evaluated is n! / (r! * (n-r)!) where n is 20, r is 5, and ! is the factorial operation. As the universe being searched increases from 20 to 300, the number of combinations searched increases at a rate much higher than exponentially. The sterling approximation of n! is sqrt(2 * pi * n) * (n ^ n) * exp(-n) Thanks, Howard On Thu, Jan 14, 2010 at 4:29 PM, stevenjhamon stevenjha...@yahoo.comwrote: I have a rotational system that takes about 30 min to optimize when I run it on a basket of 20 stocks. When I run it on a basket of 300 stocks, it takes more than 5 days, which is proportionally much greater. I use esignal datafeed, optimize with cmae and have 5 variables, 17177 optimization steps. Is there any way to speed this up? I tried changing the number of bars to load and memory used in the preferences but it didnt help.
Re: [amibroker] How to specify a different buy price than C,O,H,L, AV in Backtester AFL code?
Hi Nugget -- Try this: //BuyAtANewHigh.afl // //Buy if today's high is at least 1% higher than yesterday's high TargetPrice = 1.01 * Ref( H, -1 ); Buy = H TargetPrice; BuyPrice = TargetPrice; Sell = BarsSince( Buy ) = 2; /// Thanks, Howard On Thu, Jan 14, 2010 at 6:10 PM, nuggettrader matti.vat...@yahoo.comwrote: I need to know how to specify a different buy price than C,O,H,L,AV in Backtester AFL code. I use TeleChart end of day data. For example I want to buy if and when a stock tops yesterday's High by 1%. In other words if today's High is at least 1% higher than yesterday's High then I would get a buy signal at some time during the trading day regardless if the stock closes 1% or more higher or not. How do I code this in AFL?
Re: [amibroker] Re: Options Pricing and Probability.
Greetings all -- Historical data for options is both difficult to obtain and generally not useful. Only the most active options trade regularly enough to give accurate and useful OHLCV data on their own. And options expire, which means that the active contract has a useful history of about one month. But you can do system design based on the underlying, then use an options price calculator, such as Black-Scholes, to estimate the price of an option of your choice at the time of the transaction. Options pricing depends on several major factors -- Price of the underlying, Strike Price of the option, Time to expiration, and Implied volatility. And on some minor factors (which can often be ignored) -- Risk-free interest rate, Dividend payment schedule. The first three of the four major factors are easy to determine. You can either use recent historical volatility to estimate implied volatility, or use one of the volatility indexes, such as VIX, as a surrogate for implied volatility and calibrate the relationship for the specific issue you will be trading. Thanks, Howard On Tue, Jan 19, 2010 at 5:24 AM, Anthony Faragasso ajf1...@epix.net wrote: There is a Probability Calculator in the Library... - Original Message - *From:* rr879rr rr87...@yahoo.com *To:* amibroker@yahoogroups.com *Sent:* Tuesday, January 19, 2010 3:07 AM *Subject:* [amibroker] Re: Options Pricing and Probability. --- In amibroker@yahoogroups.com, louies88 louie...@... wrote: --- In amibroker@yahoogroups.com, rr879rr rr879rr@ wrote: Has anyone tried to do a Monte Carlo on the Probability value of the Underlying Stock at Option expiration (using Amibroker, of course)? Also, has any work being done in the area of Option Pricing and trading Options using Evolutionary Algorithms supported by Amibroker(CMAE or Particle-Swarm)? Maybe a little discussion on the above would be interesting. rr Hello RR I didn't know that you can trade/analyze options in Amibroker. How did you do that? Is there a link that I can find out more? thanks Amibroker provides you a programming language and the charting ability. So you can do any kind of analysis using Amibroker. If you study the underlying math that relates to Options, you can program Amibroker to analyze Options. I would like to discuss here the experience that Amibroker users have had developing/coding Option-related tools and techniques. rr
Re: [amibroker] Optimizing
Hi Markus -- All trades are trend following for the time they are held -- but the conditions that describe the entry are either mean-reverting or trend-following depending on whether the system buys weakness or buys strength, respectively. Under some conditions, mean reversion systems are preferable to trend following systems. You will need to test your system on the data you plan to trade. And you will need to evaluate the performance as measured by the metrics that are important to you. Psychologically, some people prefer trend-following, just a some people always buy and never short. Thanks, Howard
Re: [amibroker] Optimizing
Hi Markus -- The characteristics of a desirable trading system are yours to decide. Whether you want to focus on trend following systems, on mean reversion systems, on pattern systems, statistical systems, or whatever else is completely up to you. I meant no criticism. My suggestion about allowing the relationship between the two moving average lengths was simply to point out that what was originally thought of as a trend following system might transform itself into a mean reversion system under some circumstances. As always -- do your own research, including in-sample testing and out-of-sample validation. Walk forward testing is extremely valuable. In-sample results are always good and have no value in estimating future performance of a system. Thanks, Howard
Re: [amibroker] Re: Against All Odds
Greetings -- Beware of high sums resulting from signals coming from indicators that are positively correlated. For example, RSI, CCI, Stochastic will all trigger at about the same time / price. Thanks, Howard On Fri, Dec 25, 2009 at 6:35 PM, Neil Wrightson ne...@nwe.net.au wrote: Hi, This is a recent feature. Perhaps you need to update? Regards, *Neil Wrightson.* -- *From:* amibroker@yahoogroups.com [mailto:amibro...@yahoogroups.com] *On Behalf Of *Bob Waits *Sent:* Saturday, 26 December 2009 9:23 AM *To:* amibroker@yahoogroups.com *Subject:* Re: [amibroker] Re: Against All Odds Getting error in this line: SetOption(ExtraColumnsLocation, 1 );// put parameter columns up-front after optimization -- *From:* progster01 progs...@codefortraders.com *To:* amibroker@yahoogroups.com *Sent:* Fri, December 25, 2009 10:49:32 AM *Subject:* [amibroker] Re: Against All Odds Nice bit of code there, implementing the classic signal-counting approach. Below is my riff on it to add: * Parameterized filter requirements. Added ParamOptimize( ). * Put in LongShortBoth logic and N-bar stop for analysis purposes. * Replaced obsolete (per the docs) ColumnX = statements with AddColumn() statements. * Colored the long signals green, short signals red in the Exploration. * Added SummaryOrAll switch for Exploration column output. * Put parameters in front of output. Pictures of the output, a sample equity curve, and code that can be cut/pasted cleanly have been posted in the CFT Forum at: http://www.codefortraders.com/phpBB3/viewtopic.php?f=60t=616 Merry Christmas and Happy Holidays to all! - /* SignalSums_02. afl Versions _01 From http://www.amibroke r.com/members/ library/formula. php?id=29http://www.amibroker.com/members/library/formula.php?id=29 _02 (Progster) Parameterized filter requirements. Added ParamOptimize( ). Put in LongShortBoth logic and N-bar stop for analysis purposes. Replaced obsolete (per the docs) ColumnX = statements with AddColumn() statements. Colored the long signals green, short signals red in the Exploration. Added SummaryOrAll switch. Put parameters in front of output. */ /* Against all odds (draft). Written by Thierry HUITEL o-l---} based on Jim Varney's work-- CANDLESTOCHASTICS- - and all the amibroker group :-) This Exploration is a scan for 24 different buy or sell signals. The odds are 1 of 6 to get a TWO with a dice. If you try 1000 times, the odds are more than 99%. The aim of the exploration is to find days when many bullish or bearish signs are triggered at the same time. If 5 indicators give a buy advice, it is more reliable than one. I invite everybody to add your own systems to these ones, to improve the reliability. And experimented technical analysts could give advices to avoid the trap of using several different indicators all working off the same input data. Vol Index: this column is the ratio of today's volume to the 14-day average volume. This column should be sorted Descending. The best signals are occur when VolIndex is at least 2 or higher. PCL[up]: Piercing Line, up signifies Bullish. MDS[up]: Morning Doji Star BLE[up]: Bullish Engulfing HAM[up]: Hammer BRE[dn]: Bearish Engulfing, dn signifies Bearish. DCC[dn]: Dark Cloud Cover EDS[dn]: Evening Doji Star TDREI[up] [dn]: Tom DeMark's Range Expansion Index KUP[up] [dn]: Keltner Bands -DIMITRIS TSOKAKIS RSI[up] [dn]: Relative Strength Index 14 periods MFI[up] [dn]: Money Flow Index ST2[up] [dn]: Stochastic Slow - Donald Dalley DIV[up] [dn]: % R divergence -DIMITRIS TSOKAKIS KST[up] [dn]: MARTIN PRING'S KST MOMENTUM SYSTEM -TJ COP[up]: Coppock Curve TJ SMH[up] [dn]: smash day pattern. DIMA CHK[up] [dn]: Chaikin Money Flow. Thierry Huitel A 1 in the column signifies TRUE, a 0 indicates no signal. - - - - - -*/ function ParamOptimize( ParamTitle, defaultVal, minv, maxv, step ) { return Optimize( ParamTitle, Param( ParamTitle, defaultVal, minv, maxv, step ), minv, maxv, step ); } Commentaires sur + name() + pour le +date(); /* Minimum Price and 14 day Avg Volume Values for Filter */ minPrice = 3; //change as needed minVol = 5; //change as needed VolAvg = ma( v, 14 ); VolumeIdx = v / VolAvg; AvgRange = sum( abs(O-C),15 )/15; /* Candle Codes */ White = iif((CO) AND ((C-O)=0.8* (H-L)),1, 0) AND (C-O)AvgRange; Black = iif((CO) AND ((O-C)=0.8* (H-L)),1, 0) AND (O-C)AvgRange; Doji = iif(abs(O-C) =0.1*(H- L),1,0); /* Dark Cloud Cover [Bear] */ DCC = iif(ref(White, -1) AND Black AND C=ref(((H+L) /2),-1) AND Oref(C,-1), 1,0); /* Piercing Line [Bull] */ PL = iif(ref(Black, -1) AND White AND C=ref(((H+L) /2),-1) AND Oref(C,-1), 1,0); /* Evening Doji Star [Bear] */ EDS = iif(ref(White, -2) AND ref(Doji, -1) AND Black AND C=ref(((H+L) /2),-2), 1,0); /* Morning
Re: [amibroker] Re: Back test questions
Hi Peter -- In this code, Buy is True on every bar where the condition RSI(4) is less than 30. As long as RSI(4) stays below 30, Buy stays True. The statement Sell = Close sets the Sell to the value of the Closing price. Since any non-zero value is interpreted as True, and only exactly zero is interpreted as False, Sell is True on every bar. Thanks, Howard On Mon, Dec 21, 2009 at 8:52 AM, peter843 yahoogro...@snugmail.com wrote: Hi Howard, Here is some sample code that has the issues I discussed. --- RSISignal = RSI(4) 30 ; PositionSize = -10; // invest 10% of portfolio equity in single trade Buy = RSISignal ; Sell = Close ; --- --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Howard B howardba...@... wrote: Hi Peter -- To be sure we are all looking at the same situation, post the code you have a question about. A common reason trades last longer than might be expected is that the Buy condition reoccurs during the trade. Thanks, Howard On Sat, Dec 19, 2009 at 1:31 PM, peter843 yahoogro...@... wrote: 1. My intention is to buy on the close when I get a signal and exit on the close of the next day. I'm using EOD data. In AA Trades settings I have prices set to close and delays set to 0. In my code I have Sell = Close ; When looking at the trade list the majority of trades last 2 bars as expected. But some last much longer. How do I get them all to last 2 days? 2. When looking at the Trade column of the trades list I see descriptions I don't understand like Long (trail), Long (profit), Long (n-bar), Long(max loss), Long(nn). In the Stops tab of settings everything is disabled so I don't understand where all these are coming from.
Re: [amibroker] Back test questions
Hi Peter -- To be sure we are all looking at the same situation, post the code you have a question about. A common reason trades last longer than might be expected is that the Buy condition reoccurs during the trade. Thanks, Howard On Sat, Dec 19, 2009 at 1:31 PM, peter843 yahoogro...@snugmail.com wrote: 1. My intention is to buy on the close when I get a signal and exit on the close of the next day. I'm using EOD data. In AA Trades settings I have prices set to close and delays set to 0. In my code I have Sell = Close ; When looking at the trade list the majority of trades last 2 bars as expected. But some last much longer. How do I get them all to last 2 days? 2. When looking at the Trade column of the trades list I see descriptions I don't understand like Long (trail), Long (profit), Long (n-bar), Long(max loss), Long(nn). In the Stops tab of settings everything is disabled so I don't understand where all these are coming from.
Re: [amibroker] Re: smart trail stop
Greetings -- As a way of testing whether scaling-in works for your trading system, you might code up two separate trading systems. The first takes a position at your first signal. The second takes a position when you already have your first signal and then receive your scale-in signal. Comparing the results of the two will give an indication of whether your system should take its full position immediately, or takes its full position at the scale-in signal, or use the scale-in method. For most systems, the best results come from taking a full position at one of the two signals, rather than scale-in using both signals. The same thing applies to scaling-out. For most systems, the best results come from a complete exit at a sell signal. But test to learn how your system acts. Thanks, Howard On Tue, Dec 1, 2009 at 9:11 PM, asitasu asit...@hotmail.com wrote: hi mark, exellent job by throwing light on risk/trade management. i have few sugessions to make about different way of putting smart stop. and different way to manage trade to lock increase profit potential. i am not good at writting afl so if you can incorporate following strategy in the afl give your opinion i would be highly oblige. it would be great for rest of our trader community to understang different way of managing trade. my system(for one position only) : buy as per your or any rule. hear initial position = 1/4 th of max permissable position as per money management rule(whichever we follow) say for simplysity 100 shares(ie fix position sizeing method) initial position = 25, scale-in 1/4 position as soon as traling stop initiated. scale-in remaining position at buyprice + 4*ATR sell trade management as follow 1) put initial stop loss at time of entry to low of privious 3 bar lowest low minus filter(this is fix stop). 2) as soon as trade moves to 2*ATR in favour of trade( current price buyprice+2*ATR. cancell above stop follow trailing stop. trailing stop = low ideal bar low. ideal bar = bar which close at lower than priviou 3 bar low. 3) after current price buyprice + 6*ATR. change trailing stop = low privious bar low - filter in my opinion this system will produce optimum return on risk. kindly favour me in coading above mehod. asit. --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, de_techneut twistedcha...@... wrote: Hi Mark, thanks for sharing this code. this will definitely help me in my further study of the market. I am just starting in Amibroker so i'm not yet an accomplished programmer. (i doubt i ever will be) I know it's probably an open door but here it is anyway: a good stoploss is indeed essential to all trading systems. what is equally important, imo, is a good profit target mechanism as a way to get out of a trade. I find the classic pivots to do a marvelous job at that. I usually calculate pivots depending on the time frame i'm trading, (around 30 to 60 bars) i.e. 1 hour pivots for a minute chart or weekly pivots for a hourly chart. hope this helps you in some way. Thanks for sharing, Marc. --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, r22mark mtf_79@ wrote: Hi. Money / risk management is an area of interest to me. I have tried to create a smart trailing stop, one that adjusts itself. There is also some stuff that people may not have encountered - Fixed Fractional Position Sizing with margin (to mimic CFD's) , various buy filters, PositionScore, and the Graph / indicator plot code is handy for displaying trade arrows, and trade prices. Hope there is something of use for you. This is NOT a ready to trade system - you will likely find results are poor. It IS an example of what can be done other than a basic trail stop. This is an ongoing project. Plot it or drag it onto a chart to view / adjust the parameters. The risk management side has: - initial stop set at 20%. - after 5 days stop raised /risk reduced by 50% - stop moved to break even after 10 days - after 15 days stop raised / risk reduced by 50% - at any time you have 3 lower lows, risk is reduced by 25%, every time. - these can all adjusted via parameters. Again this is a code in progress, I use Plot() to verify what is happening at each bar. If you want to check my work, uncomment them. Let me know if you find any errors. So people. Comments? Ideas? Feedback? I haven't heard of anyone doing smart trail stops. Or am I am just wasting my time? Mark SetTradeDelays (0,0,0,0); SetOption(InitialEquity, 10); SetOption(AccountMargin, 10); // only put up 10% funds, buying power x 10 SetOption(CommissionMode, 1); SetOption(CommissionAmount, 0.10); // .1% commission per entry / exit SetOption(MaxOpenPositions, 12); SetOption(AllowSameBarExit, True); // FIXED FRACTIONAL POSITION SIZING CapRisk = Param(CapitalRisk, 2, 1,5,0.5); // capital risk
Re: [amibroker] What's a good k ratio, and thoughts on when k ratio clashes with MDD and Sharpe?
Hi PS -- One way to get a feeling for values for metrics and objective functions is run an optimization, giving you a range of results. If necessary, peek into the future so you are certain to get some really good results. Look through the list of results, pick some individual results with a variety of values for the metrics you want to learn about. Set the default value of the optimized variables to the specific values you chose. Run a single backtest. Plot the equity curve. When you have done a few of these and have a feeling for the characteristics of the systems you would like to trade, print out the plot of the equity curves and write the values of the metrics and objective functions on the printout. --- Your question about interpretation. My preference is for objective functions that reward equity growth and penalize drawdown. CAR/MDD, RAR/MDD, RRR, Recovery Factor, K-Ratio, Ulcer Performance Index, and Sharpe Ratio all do that. In all of these cases, larger values are better. The important results are the out-of-sample results. We are looking for logic and parameter values that not only perform well in-sample, but that also perform well out-of-sample. When you run walk forward tests, you will find that some objective functions give high rank to alternatives that do tend to perform well out-of-sample, while other objective functions select alternatives that often do not perform well out-of-sample. You will need to run some of your own tests to get a feeling for how these work on your trading systems. My experience is that using net profit is usually a poor objective function, although it is the default (and often the only) selection for some trading systems development platforms other than AmiBroker. Fund managers are evaluated on the Sharpe Ratio of their performance. My experience is that systems selected using Sharpe Ratio tend to perform poorly out-of-sample. Standard Error is a measurement of the smoothness of the equity line -- smaller values are better. But optimizing to minimize standard error alone may give high ranks to systems that have trading characteristics that you do not want. For example, if you have the options set so that the equity earns interest when ever it is not in a position, then using standard error will reward alternatives that stay in cash and trade infrequently. One of the very valuable features of AmiBroker is the capability for the system developer to create whatever objective function he or she wants to use. It does not have to be limited to those that are distributed with AmiBroker and appear in the list of metrics. You might want to combine metrics -- for example to reward alternatives whose trading frequency suits your preferences, while also rewarding equity growth and penalizing drawdown. Thanks, Howard On Sat, Nov 28, 2009 at 11:33 PM, potatosoupz potatoso...@yahoo.com wrote: I don't see any good definitions for the metrics below. I am familiar of course with Sharpe, and Ulcer Index. I'm finding it a bit hard to reconcile the differences. How would you reconcile a backtest that has a max draw down % that is smaller than it's profit %, a low ulcer index, a high Sharpe, but a very low k ratio ( .05)? Ulcer Index in my mind is one of the best metrics outside of a much deeper quantitative treatment of things. Thoughts? CAR/MDD ? RAR/MDD ? Payoff Ratio ? Standard Error ? RRR ? Recovery Factor ?
Re: [amibroker] Re: Tick data, how important is bids/asks?
Greetings all -- In a conversation I had recently with a practitioner of high frequency trading, including flash trading, he pointed out that it is not unusual for bids and offers to be modified many times for every trade that is eventually executed. Many means somewhere between two or three times and several hundred times -- much of that activity taking place in millisecond and microsecond time frames. In other conversations and in my own experience, traders often place an order with a bid or ask price designed to learn something about the market, but have no intention of being filled. One fellow described these orders as cancel if close. In my opinion, bid and ask prices do not add information that is helpful to individuals and small trading organizations. Thanks, Howard On Mon, Nov 23, 2009 at 9:57 AM, Tomasz Janeczko gro...@amibroker.comwrote: Hello, Bid and asks are sent by IQFeed and eSignal and IB, and they are shown in TimeSales window in AmiBroker. http://www.amibroker.com/guide/w_timesales.html Historical data is different story. Various feeds supply various information. IB does not deliver tick historical data at all (best resolution is 1 second). IQFeed as written below delivers historical tick data in form of TRADES only. eSignal depending on request you send can deliver trades only, bid/ask only or both (including all bid/ask changes that happen *between* trades). Access to historical bid/ask was not given in form of arrays in AB because of differences outlined above (only some sources deliver necessary info), and because there was no room in quotation structure. With recently introduced changes (added aux1/aux2 fields) now it is technically possible to deliver historical bid/ask matching trade records (the way IQfeed does) but that requires extra code in the plugin(s) and it is under development. Note also that in the past I have been doing research on bid/ask relationship vs trade prices and found that there is really lots of manipulation occuring on bid/ask and level2 books and hypothesis that relationship between bid/ask/trade is market driving force was found to be false. People often forget that nowadays lots of trades come from dark liquidity pools as they are required to report trades made but they are not required to report quotes (bid/ask) so they don't appear in order books *at all*. You won't see any quote from dark pools. You will see the trades, but they are reported with delay as large as possible. So called alternative trading systems (dark pools among others) are required to report trades to the Consolidated Tape on a 90-second delay. This leads to very distorted picture and makes bid/ask analysis very questionable. Best regards, Tomasz Janeczko amibroker.com - Original Message - From: iqfeed iqf...@dtn.com iqfeed%40dtn.com To: amibroker@yahoogroups.com amibroker%40yahoogroups.com Sent: Monday, November 23, 2009 4:18 PM Subject: [amibroker] Re: Tick data, how important is bids/asks? Just to clarify, IQFeed does provide bid/ask quotes in the stream. We send every trade, as well as every bid/ask price and volume update. We don't store each bid/ask update in history however. Instead, we only store trades, and the bid/ask price at the time of the trade which allows 3rd party software to determine if a trade occured at the bid or the ask. Trades are often interpreted as a buy or a sell based on if the trade hit the bid or ask and we provide the information needed to determine this. --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Potato Soup potatoso...@... wrote: I'm working with IQFeed tick data. They don't seem to provide bid/ask quotes, just trades. What's the consensus on whether this matters? I've seen it argued that a lot of games go on with quotes, fakeouts, etc. And that trade ticks are all that matter. Seems though for less liquid instruments you'd really want updated quotes, or the true price could be quite far from the last trade. I realize most AmiBroker users don't trade on ticks, but thought I'd ask here for comment anyway. IMPORTANT PLEASE READ This group is for the discussion between users only. This is *NOT* technical support channel. TO GET TECHNICAL SUPPORT send an e-mail directly to SUPPORT {at} amibroker.com TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at http://www.amibroker.com/feedback/ (submissions sent via other channels won't be considered) For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG: http://www.amibroker.com/devlog/ Yahoo! Groups Links
Re: [amibroker] HOW TO CREATE CSV FILE WITHIN AFL OF EXPLORATION
Hi Bis -- The documentation explains how to write data to disk files from within AFL. You will need a sequence of: fopen -- one time to establish the file a loop that formats the data the way you want it, then calls fputs for each bar fclose -- one time to close the file and finalize the write. Thanks, Howard On Wed, Nov 18, 2009 at 9:17 AM, bistrader bistra...@yahoo.com wrote: I would like to create a csv file of an afls' exploration. Does anyone have an example?
Re: [amibroker] Walk Forward Test - How would you...
Hi Dubi -- What is SPSO? Thanks, Howard On Wed, Nov 11, 2009 at 9:07 AM, dubi1974 gonzale...@chello.at wrote: Hi! Is it possible to optimize a system (for e.g. best net performance %) with SPSO but then use the highest Ulcer Performance Index or CAR/MDD and use then this parameters for the out of sample test for the next period in the Walk Forward Test of Amibroker? I know I could do this in separate steps, but I would like to automize that. Or does someone know an other solution for this? Many thanks and kind regards, dubi
Re: [amibroker] Re: Walk Forward Test - How would you...
Hi Bisto -- Thanks. From the original posting, I was thinking that SPSO was a metric. Dubi -- The choice of optimization method (exhaustive, cmae, ...) and metric (Ulcer Index, CAR/MDD, k-ratio, ...) are independent. The optimization portion of the walk forward will be carried out using the optimization method you request in you afl code with the OptimizerSetEngine statement. The selection of which of the alternatives tested to use for the out-of-sample run will be determined by the metric you set in the Optimization Target box on the Walk Forward tab of the AA Settings. Or did I misinterpret your question? Thanks, Howard On Fri, Nov 13, 2009 at 3:39 AM, Bisto bistoma...@yahoo.com wrote: I suppose: Standard Particle Swarm Optimization Bisto --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Howard B howardba...@... wrote: Hi Dubi -- What is SPSO? Thanks, Howard On Wed, Nov 11, 2009 at 9:07 AM, dubi1974 gonzale...@... wrote: Hi! Is it possible to optimize a system (for e.g. best net performance %) with SPSO but then use the highest Ulcer Performance Index or CAR/MDD and use then this parameters for the out of sample test for the next period in the Walk Forward Test of Amibroker? I know I could do this in separate steps, but I would like to automize that. Or does someone know an other solution for this? Many thanks and kind regards, dubi
Re: [amibroker] Re: Optimization targeting equity curve smoothness?
Greetings Ramon, Graham, and all -- You are probably already aware, but many will not be. There is danger in multistep optimization when the second step is applied to the results of the first step, all of the out-of-sampleness has probably been used up. Be certain to reserve some additional data for a truly out-of-sample test. Thanks, Howard On Mon, Oct 19, 2009 at 9:23 AM, ramoncummins ramoncumm...@hotmail.comwrote: I asked the same question recently, custom backtester code for r-squared of the equity curve can be found here: http://finance.dir.groups.yahoo.com/group/amibroker/message/141718 cheers Ramon --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, grahamj42 graham.john...@... wrote: Not sure if this is what you are after, but this one of my current projects. 1. define variable PassNum - normally set to 1 2. using CBT, define/create system specific equity curve 3. run backtest 4. set PassNum = 2 5. using PassNum Foreign, apply an indicator to the equity curve and use this as en entry filter. As a simple approach I have been playing with ROC. 6. run backtest It is a bit klunky, but it works. Graham --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, DIANE TONETTI ftonetti@ wrote: KRatio is measurment of the smoothness of the Equity curve which works fine for systems that dont compound ... For systems that do you could calculate your own KRatio based on the log of equity On Wed, Oct 14, 2009 at 8:36 AM, droskill wrote: I agree it would be an interesting choice - only issue is that, as far as I can see, the backtester does not allow that kind of targeting. --- In amibro...@yahoogrou ps.com mailto:amibroker@yahoogroups.comamibroker%40yahoogroups.com , woodshedder_ blogspot woodshedder_ blogspot@ ... wrote: Droskill, What about R squared? --- In amibro...@yahoogrou ps.com mailto:amibroker@yahoogroups.comamibroker%40yahoogroups.com , droskill droskill@ wrote: Hey all - One of the things I would love to optimize around is equity curve smoothness - but I don't see any parameter that really matches with that. Drawdown is an obvious one as a smooth equity curve generally doesn't have huge drawdowns - but I'm wondering if people have other ideas. Thanks in advance! mailto:amibroker@yahoogroups.com amibroker%40yahoogroups.com http://groups.yahoo.com/start;_ylc=X3oDMTJvNm8wcWYyBF9TAzk3MzU5NzE0BF9wAzMEZ3JwSWQDMTAxMDY5MgRncnBzcElkAzE3MDU2MzIxOTgEc2VjA25jbW9kBHNsawNncm91cHMyBHN0aW1lAzEyNTU1MjM4MDQ-
Re: [amibroker] Re: Money management AFL
Greetings all -- Be certain that scaling in actually helps your trading system. It hurts most. You might be able to isolate the scaling in effect by running the system as two separate systems -- one with the original buy and the second with the scale in buy. Thanks, Howard On Wed, Oct 21, 2009 at 1:35 AM, mkecera mkec...@gmail.com wrote: Remember that if you do use scaling out you are just adding another system to your basic system. The same applies for scaling in. MK --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, kevinkee20 kevinke...@... wrote: I'm trying to write a money management AFL. I start off with the scaling-out example in the user guide, and add just one more condition - after openinig a position, if it is initially profitable but before it hits the profit target of say 20% it appears to be turning into a loss. In this case I want to set the stop to be the BuyPrice. Unfortunately it doesn't work - it just doesn't exit when the price drops below the BuyPrice. Below please find the full AFL, would anyone be able to help ? Buy = Cross( MA( C, 10 ), MA( C, 30 ) ); Sell = 0;//Cross(MA(C,30), MA(C,10)); // the system will exit // 50% of position if FIRST PROFIT TARGET stop is hit // 50% of position is SECOND PROFIT TARGET stop is hit // 100% of position if TRAILING STOP is hit SetTradeDelays( 0, 0, 0, 0 ); /* delay entry/exit by one bar */ FirstProfitTarget = 20; // profit SecondProfitTarget = 40; // in percent TrailingStop = 25; // also in percent priceatbuy=0; highsincebuy = 0; exitoriginal = 0; exitriskfree = 0; exit = 0; for( i = 0; i BarCount; i++ ) { if( priceatbuy == 0 AND Buy[ i ] ) { priceatbuy = BuyPrice[ i ]; exitoriginal = 1; exitriskfree = 0; } if( priceatbuy 0 ) { highsincebuy = Max( High[ i ], highsincebuy ); if (exitoriginal == 1 AND Close[i] priceatbuy) { exitoriginal = 0; exitriskfree = 1; } if (exitriskfree == 1 AND Low[i] = priceatbuy) { exit = 3; SellPrice[i] = priceatbuy; exitoriginal = 0; exitriskfree = 0; } if( exit == 0 AND High[ i ] = ( 1 + FirstProfitTarget * 0.01 ) * priceatbuy ) { // first profit target hit - scale-out exit = 1; Buy[ i ] = sigScaleOut; } if( exit == 1 AND High[ i ] = ( 1 + SecondProfitTarget * 0.01 ) * priceatbuy AND exitriskfree ==1) { // second profit target hit - exit exit = 2; SellPrice[ i ] = Max( Open[ i ], ( 1 + SecondProfitTarget * 0.01 ) * priceatbuy ); } if(( Low[ i ] = ( 1 - TrailingStop * 0.01 ) * highsincebuy ) AND exitriskfree==1) { // trailing stop hit - exit exit = 3; SellPrice[ i ] = Min( Open[ i ], ( 1 - TrailingStop * 0.01 ) * highsincebuy ); } if( exit = 2 ) { Buy[ i ] = 0; Sell[ i ] = exit + 1; // mark appropriate exit code exit = 0; priceatbuy = 0; // reset price highsincebuy = 0; } } } SetPositionSize( 20, spsPercentOfEquity ); SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) ); // scale out 50% of position // scale out 50% of position PlotShapes( (Buy) * shapeUpArrow , IIf( (Buy), colorGreen,colorBlue ), 0,IIf( (Buy), L,H ),-20 ); Plot( Close, Price, IIf( Close Open, colorGreen, colorRed ),styleCandle | styleThick ); PlotShapes( (ExRem(Sell,Buy)) * shapeSmallDownTriangle , colorLightOrange, 0,H ,-15 ); Plot( MA(C, 10), _DEFAULT_NAME(), colorGreen, styleLine); Plot( MA(C, 30), _DEFAULT_NAME(), colorRed, styleLine);
Re: [amibroker] Re: Is the Walk forward study useful?
), sqrt(5000) alone would yield in excess of 70 for the multiplier. This would leave expectancy/StdDev of R with just a target of 0.1, to reach the 7 t-tests score. Now, if you had 1,000,000 tranasctions in your OOS test The concept of limiting the trade count does make sense to me. Maybe 100 is too low, and should be set higher. There does come a point whereby the sqrt(N) part of the equation will render the rest of the equation irrelevant once N gets too large. $0.02 Bing --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Howard B howardbandy@ wrote: Hi Zozu -- I must disagree with Van Tharp on this. If the runs are truly out-of-sample, then each and every one contributes to the computation. It makes no sense to limit the count to 100. It is poor procedure to limit the count. It is bad science to limit the count. Do not limit the count. If the runs are in-sample, then the test has no meaning anyway. Computing the t-test statistic using any N will be misleading. Do not even do the computation. If a decision to trade a system is made after computing the t-test statistic on trades that came solely from in-sample results, there is an extremely high probability that a Type I error will be committed. That is, the trader will believe that his system is better than random, when it is in fact not better than random. Type I errors result in loss of money. Thanks, Howard On Tue, Oct 13, 2009 at 10:54 AM, zozuzoza zozuka@ wrote: Hi Howard, Limiting the number of N doesn't mean that you are not using all trades for the calculation of SQN. Only the sqrt(N) part of the formula is limited in order not to distort the results if there are many trades. It makes sense. The other part of the formula does count on all the trades. Zozu
Re: [amibroker] Import thousands acsii files
Greetings -- I do not offer a solution, rather a question. What is in those files, and how will they be used? Will they be used as components of trading systems that will someday be traded? If the data in the ASCII files is available from a vendor for which there is already an AmiBroker data plug-in, then using that vendor's data rather than the ASCII gives several advantages: 1. The research data and the trading data come from the same source. Consistency is very important in trading system design. Maybe more important than accuracy. 2. You let the vendor be in the data management business, while you spend your time developing trading systems. 3. You bypass the task of importing the ASCII files for the research project. 4. Think ahead to how the data will be gathered and imported into AmiBroker while trading. If you import the ASCII files for research, where will the data come from for trading? Will you be able to gather the data, edit it, import it, and still have a timely signal? My use of ASCII files is for one-time projects. If the data turns out to be useful, I look for a data vendor who can provide it in the form I need it and on the time schedule I need it. Thanks, Howard On Thu, Oct 15, 2009 at 10:39 PM, Keith McCombs kmcco...@engineer.comwrote: Brad -- I don't have an answer for you, but I do have a couple of questions, because I too have over a thousand ascii files that I would like to import into AB. Have you completely automated the task, using not only the suggested jscript but also set up a list of all the equities to load, so that you can just let AB take it from there? Or is much the time your 'hands on' time, for example manually typing in symbols or clicking mouse buttons for every symbol? Thank you for bring up this issue. I sure hope others with applicable experience chime in. -- Keith bradjeng wrote: I try to import thounds of ascii files to Amibroker by JScript. (http://www.amibroker.com/docs/ab302.html) It works but very slow. Is there any quicker way to batch import ascii files ? Or can I write data directly to the Amibroker's data file ? (what's the data format ?) Thanks !!
Re: [amibroker] Re: Is the Walk forward study useful?
Hi Bing -- Yes, I recommend penalizing a trading system only when it loses. The standard deviation of a number of trade results is computed using all trades, winners and losers. Replacing a trade from the middle of the list with a large winner changes the standard deviation just as much as replacing that trade with a large loser. If the standard deviation is used in the denominator of a metric, and it usually is, using the standard deviation penalizes winners. The semi-deviation uses only those trades that are losers. Losers can be defined however you want it to be. Trades that lose money is usually my definition. You might try trades below the mean. If you are successful, then all of your trades will be above average. Grin. Thanks, Howard On Fri, Oct 16, 2009 at 3:12 AM, bingk66 bing.k...@optusnet.com.au wrote: Hi Howard, Many thanks for your detailed response. You'll be pleased to know that I am still repeating keep a positive expectancy, limit losing trades, trade frequently. lol Given your point that risk of bankruptcy increases dramatically as the standard deviation of losing trades increases, would it be fair to say that you prefer to use standard deviation of losing trades as the denominator for the t-test calculation, as opposed to the normal standard deviation ? Also would appreciate your opinion about using the standard deviation of trades that are below the mean, as opposed to just the losing trades ? Bing --- In amibroker@yahoogroups.com amibroker%40yahoogroups.com, Howard B howardba...@... wrote: Hi Bing, and all -- I think we need a reality check. First -- computing the t-test, or any other metric using the results from in-sample runs has no value. Almost any trading system can have the parameters, logic, time frame, and reporting period adjusted so that the in-sample results are very profitable. In my speeches, I show a series of slides, each slide displayed in two steps. Step 1 is the in-sample equity after optimizing over an in-sample period. The chart ends at the end of the in-sample period. It always looks good. When the results of testing a system do not look good, we do not spend any more time on that system, but go on to others where it does look good. Step 2 adds an out-of-sample data period, applies the same system, and shows the out-of-sample equity. For some systems the equity continues to rise, for some it goes flat, for others it drops sharply. There is no way to tell what will happen in the out-of-sample period without testing the out-of-sample period. That is -- there is no information in the in-sample results that predict the out-of-sample results. There is no way to know whether the model has fit itself to the signal component of the data that contains the pattern leading to profitable trades or to some noise component of the data that does not exist in the out-of-sample data. Second -- if someone has a trading system that has produced a truly out-of-sample set of closed trades where the t-test, or any other fitness metric, would be embarrassingly high without limiting the value used as the number of data points, he or she should call me. I can help them find a semitrailer large enough to carry all the money they will make trading that system. Limiting the number used as N is a non-issue, in addition to being bad procedure. Tharp admits that he is not a statistician, and that he finds some of the mathematics involved in position sizing and fitness function analysis to be at his comfort limit. It is apparent to me that the systems he shows as standards for SQNs of 2, 3, 4, 5, and so forth are not the result of trading system runs -- either in-sample or out-of-sample -- to which he has applied his metric; they are artificial examples constructed so the results turn out as he wants them to. That is not a bad thing in itself, but when he suggests that we should go on searching for systems with SQNs of 10 or more (page 279 of Definitive Guide to Position Sizing), that is completely unrealistic and will send naive systems developers off on windmill-tilting quests that will never be successful. One of the difficulties using Tharp's data sets is that the standard deviation of losing trades is zero for some of them. That is not only unrealistic, but it makes computation of metrics that include standard deviation of losing trades, such as Sortino ratio, difficult. Do the following experiment. Put together a data set that represents potentially realistic trading results that you hope to achieve -- be optimistic, but realistic. If you would expect one trade a week, a set of 52 data points represents a year. 252 data points if you would have a trading result every day. Each data point is the number of dollars gained or lost from that closed trade, based on trading a single unit -- one futures contract, one hundred shares