Tip, Sorry, I used AmiBroker terms in the context of a broker in my last reply, which may have confused things. I'll try again keeping the terms straight.
Your broker may have different names for it. But, when trading on margin we have; cash, stock, equity, maintenance margin, available funds and buying power. I believe that it goes along the lines of; maintenance margin equals 1/2 x stock, equity equals cash + stock, available funds equals cash + stock - maintenance margin. And, overnight buying power equals 2 x available funds. So, given our 100k brokerage account, after taking a 10k trade, we have: cash = 100k - 10k = 90k stock = 0 + 10k = 10k maint. margin = 0 + (1/2 x 10k) = 5k equity = 90k + 10k = 100k avail. funds = 90k + 10k - 5k = 95k buying power = 2 x 95k = 190k Taking a second 10k trade we have: cash = 90k - 10k = 80k stock = 10k + 10k = 20k maint. margin = 5k + (1/2 x 10k) = 10k equity = 80k + 20k = 100k avail. funds = 80k + 20k - 10k = 90k buying power = 2 x 90k = 180k Continuing to the end we get: cash = -90k - 10k = -100k stock = 190k + 10k = 200k maint. margin = 95k + (1/2 x 10k) = 100k equity = -100k + 200k = 100k avail. funds = -100k + 200k - 100k = 0k buying power = 2 x 0k = 0k We only actually start paying margin interest once our cash falls below zero. Now let's compare that to AmiBroker. AmiBroker does not have a separate variable for available funds. So, instead it just re-uses the cash variable to hold available funds. When taking a new position with 50% margin, AmiBroker takes half from its cash (avail funds) and charges the other half to margin (maintenance margin). Equity is calculated as cash + stock - margin. After the first 10k trade from starting equity of 100k: cash = 100k - (1/2 x 10k) = 95k stock = 0 + 10k = 10k margin = 0 + (1/2 x 10k) = 5k equity = 95k + 10k - 5k = 100k avail. funds = cash = 95k buying power = 2 x 95k = 190k Taking a second 10k trade we have: cash = 95k - (1/2 x 10k) = 90k stock = 10k + 10k = 20k margin = 5k + (1/2 x 10k) = 10k equity = 90k + 20k - 10k = 100k avail. funds = cash = 90k buying power = 2 x 90k = 180k Continuing to the end we get: cash = 5k - (1/2 x 10k) = 0k stock = 190k + 10k = 200k margin = 95k + (1/2 x 10k) = 100k equity = 0k + 200k - 100k = 100k avail. funds = cash = 0k buying power = 2 x 0k = 0k Assuming that all of the above is correct, you can see that AmiBroker does in fact give the correct results for a margin backtest. We just have to understand that AmiBroker's "cash" is our broker's "available funds". Note that some brokers show buying power based on intra day trading (i.e. 4x available funds) rather than overnight holding (i.e. 2x available funds). In such cases, you need to adjust the broker's buying power to match your EOD trading. Mike --- In [email protected], "tipequity" <[EMAIL PROTECTED]> wrote: > > Mike > > I had done what you suggested a while back. I sort of hijacked this > thread to warn portfolio stock traders that the results that they may > get in their backtest is NOT correct if they use margin. I am certain > that in the US, brokers will not charge you margin expense if you > have cash in your account. > > --- In [email protected], "Mike" <sfclimbers@> wrote: > > > > Admittedly, it has been a while since I last looked at this. > > > > But, my recollection is that AmiBroker will use the ratio accross > all > > trades, regardless of whether or not you have actually expended all > > your cash. In other words, in the example given, the distribution > > would in fact be $5000 from cash and the other $5000 on margin, > > leaving $95000 in cash. > > > > This is consistent with what your broker might show in that trades > > made from a marginable account will only deduct part of the cost > from > > your cash, and the remainder will show up as being on margin. > > > > To see exactly what is going on, go to the Report tab of the AA > > Settings window and select the "Detailed Log" option, then run your > > backtest. The ouput will show changes to cash, margin, equity, at > > each buy/sell. > > > > Mike > > > > --- In [email protected], "tipequity" <l3456@> wrote: > > > > > > Mike > > > > > > Wouldn't this approach create a incorrect results if: > > > 1. you are a EOD stock trader > > > 2. want to use 50% margin > > > 3. no more than 10% in one stock > > > 4. initial cash $100,000 > > > on the first buy you should be using $10,000 from cash not from > > $5000 > > > and $5000 on margin. It seems to me the correct approach is once > > your > > > cash is exhausted then AB should take on margin loan. > > > > > > --- In [email protected], "Mike" <sfclimbers@> wrote: > > > > > > > > Hi, > > > > > > > > The feature dictates what percentage of the purchase price is > to > > be > > > > paid from your own funds vs. a margin loan. When set to 100, > you > > > pay > > > > the entire amount (i.e. 100%). When set to 75, you pay 75% of > the > > > > purchase and take a margin loan for the remaining 25%. When set > > to > > > > 50, you pay half and take a margin loan for the other half, etc. > > > > > > > > The amount in absolute dollars will vary based on the price and > > > > number of shares bought. However, the ratio will remain the > same > > > for > > > > all trades. You can do the math to figure out what the actual > > > amount > > > > is by multiplying the number of shares by the purchase price > and > > > then > > > > multiplying that by the percentage covered by margin. > > > > > > > > Mike > > > > > > > > --- In [email protected], "guhu0434" <g.h.h@> wrote: > > > > > > > > > > Hello, > > > > > > > > > > thank you for the answer. The setting you mention gives the > > > > > backtester the possibility to make a margin loan. I am > > interested > > > > in > > > > > the actual amount of the loan. I hope I explained it in such > a > > > > manner > > > > > you get my point. > > > > > > > > > > I got the stuff with cash and equity simply by looking at the > > > > equity > > > > > chart in amibroker, right mouse button and click on "Formula". > > > > > > > > > > To my knowledge, this feature isn't documented. > > > > > > > > > > WIth regards, Guido > > > > > > > > > > --- In [email protected], "Mike" <sfclimbers@> wrote: > > > > > > > > > > > > Hi, > > > > > > > > > > > > The easiest approach is to set the margin from the AA > > Settings > > > > > window > > > > > > (e.g. 100 means no margin, 50 means max overnight margin > > > allowed > > > > by > > > > > > U.S. markets, 50% paid by you, 50% by your broker). > > > > > > > > > > > > If you want to do it using code, try SetOption > > ("AccountMargin", > > > > > 50), > > > > > > for example. > > > > > > > > > > > > Mike > > > > > > > > > > > > P.S. Where did you read that Foreign("~~~Equity", "L") was > > > equal > > > > to > > > > > > cash? Or are you making an assumption? > > > > > > > > > > > > --- In [email protected], "guhu0434" <guhu0434@> > > wrote: > > > > > > > > > > > > > > Hello, > > > > > > > > > > > > > > I hope somebody can help me with this question. How can I > > > > control > > > > > > the > > > > > > > MarginLoan during backtest? > > > > > > > > > > > > > > As I see, Equity and Cash can be controlled via the > > ~~~EQUITY > > > > > > > eq = Foreign("~~~EQUITY", "C"); > > > > > > > cash = Foreign("~~~EQUITY", "L"); > > > > > > > > > > > > > > I tested the other values "H","O","V" as well, but can't > > find > > > a > > > > > > hint > > > > > > > for the marginloan. > > > > > > > > > > > > > > I would like to improve my moneymanagement... > > > > > > > > > > > > > > With thanks in advance... > > > > > > > > > > > > > > Guido > > > > > > > > > > > > > > > > > > > > > > > > > > > >
