Interest on leverage for Z8 and Z9

Posted By: kujo

Interest on leverage for Z8 and Z9 - 12/04/17 14:49

Hello,
Z8 and Z9 systems use leverage 2:1. I am trying to understand whether a backtest takes into account interest on leverage that should be paid to a broker. As I understand, it should decrease the returns.
Thanks!
Posted By: jcl

Re: Interest on leverage for Z8 and Z9 - 12/05/17 14:34

Yes, when you know the interest per day and contract. Enter it in the RollLong column of the AssetsZ8/Z9 asset list. F.i. for a $50 stock with 1% annual interest and a USD account, enter -0.0009 in that column.
Posted By: Hredot

Re: Interest on leverage for Z8 and Z9 - 12/05/17 16:38

How do you arrive at -0.0009?

My calculation gives:
-$50/100/240=-$0.0021
rollover per business day.
Posted By: jcl

Re: Interest on leverage for Z8 and Z9 - 12/06/17 10:26

In fact it's -0.0007, since calendar days are counted, not business days. -$50 / leverage 2 / 365 days * 0.01 interest = -0.0007.
Posted By: Hredot

Re: Interest on leverage for Z8 and Z9 - 12/06/17 14:46

Thanks for your reply!

Does this mean Zorro continuously executes the run() routine on weekends as well?
Posted By: jcl

Re: Interest on leverage for Z8 and Z9 - 12/06/17 16:14

No, rollover is unrelated to the run() function.
Posted By: kujo

Re: Interest on leverage for Z8 and Z9 - 12/06/17 16:45

Originally Posted By: jcl
In fact it's -0.0007, since calendar days are counted, not business days. -$50 / leverage 2 / 365 days * 0.01 interest = -0.0007.

thanks for clarification! As I understand, it's initial RollLong value. When I test a system will this value be recalculated every day based on a current stock price?
Posted By: kujo

Re: Interest on leverage for Z8 and Z9 - 12/06/17 19:21

Also, I have a question about MarginCost and Leverage in AssetsZ9.csv
1st test: MarginCost=0 and Leverage=2.
According to the manual MarginCost can be left at 0 when Leverage is used for determining the margin. Ok

2nd test: MarginCost=25 and Leverage=0.
Again, according to the manual when MarginCost is nonzero, Leverage is ignored and the Leverage variable is calculated from MarginCost and the initial price.

Initial price = 50, PIP = PIPCost = 0.01
As I understands, these tests are equal and should produce the same results. However, they are different. Is it a bug or I miss something?
Posted By: jcl

Re: Interest on leverage for Z8 and Z9 - 12/07/17 15:55

Rollover will not be recalculated, since it changes anyway all the time unrelated to the asset price. MarginCost is calculated from the current price when Leverage is set, otherwise it is taken from the asset list. So your 2 settings are in fact different.
Posted By: kujo

Re: Interest on leverage for Z8 and Z9 - 12/10/17 03:38

Originally Posted By: jcl
Yes, when you know the interest per day and contract. Enter it in the RollLong column of the AssetsZ8/Z9 asset list. F.i. for a $50 stock with 1% annual interest and a USD account, enter -0.0009 in that column.


Maybe I'm missing something, but, as I understand, the RollOver cost model came from Forex. It's not really applicable to stock market. In stock market there is no overnight fee. However, there is an interest that should be paid to a broker for borrowing money (in case of leverage) or securities (in case of short selling).

So for the Z9 strategy that trades ETFs, if I enter interest in the RollLong column and leverage = 2, Zorro calculates interest fee for every security that I hold overnight. But the interest is only applicable for the borrowed money/securities.

Could you please comment on this? How to tailor Z9 strategy's cost model for real stocks/ETFs?
Thank you!

Posted By: jcl

Re: Interest on leverage for Z8 and Z9 - 12/11/17 07:58

Just calculate the rollover as in the example. What exactly is the problem?
Posted By: kujo

Re: Interest on leverage for Z8 and Z9 - 12/11/17 12:31

Originally Posted By: jcl
Just calculate the rollover as in the example. What exactly is the problem?


Jcl, thanks for helping out.
The problem is that I want to calculate the cost of borrowing for leverage in the stock market with Zorro (Z9 system to be exact).

Example: I have 5k in my account. I use leverage 2 and borrow another 5k from the broker. Then I buy 10k worth of ETFs. I remain open in this position for a year. Interest on borrowing money from the broker is 3%. By the end of the year I owe broker ~150 (5k * 3%) as an interest for borrowing. So, I want Zorro to calculate this amount.

I understand what is rollover for forex, but it's not clear for me what is rollover for the stock market in Zorro. As I understand, I can use RollLong to calculate the interest for borrowing. However, rolllong costs calculated by Zorro in the above case would be ~300, because Zorro will use 10k for calculation. So, rolllong isn't exactly the cost of borrowing.

I wonder if I can calculate the cost of borrowing (150 in the above case) for the stock market. If yes, could you please point out how to do this using Z9 system?

Thank you!
Posted By: Hredot

Re: Interest on leverage for Z8 and Z9 - 12/11/17 13:35

Just my two cents:

Certainly you do not intend to use up all available funds in your account to buy assets? It is essential to leave a buffer to allow for price fluctuations and avoid a margin call.

You can manually adjust the rolllong parameter until it accumulates to the figure you expect over a year. In your leverage 2 example, just divide rollong by two.
Posted By: kujo

Re: Interest on leverage for Z8 and Z9 - 12/11/17 16:48

Thanks for the comments!

So, as I understand so far, there is no dedicated function in Zorro to calculate a margin interest for borrowed money (cost of borrowing) in case of leverage in the stock market. RollLong calculates rollover costs and it's not really a margin interest. It calculates costs for holding all positions overnight, not a cost of interest for borrowed money. As a workaround, it's possible to use RollLong and multiply it by (1 - 1 / leverage) , as Hredot suggested (0.5 in case of leverage 2, thanks for idea!). But it seems that this method will give only approximate results because there are some assumptions.

So, I have 3 questions:
1. jcl, could you confirm or deny that the best way to calculate margin interest (or cost of borrowing) for the stock market is: "RollLong * (1 - 1 / leverage)"? RollLong comes from broker's interest for borrowing, i.e. 3%. (1 - 1 / leverage) takes into account only borrowed amount, not all (i.e. 1/2 for lev 2; 2/3 for lev 3, etc ).
2. Are there any plans to implement a dedicated function for margin interest (cost of borrowing) calculation? if not, why?
3. I assume I can manually calculate margin interest (cost of borrowing) in my own written scripts. If so, could you please give me a hint how to do this?

Thanks for the help!
Posted By: jcl

Re: Interest on leverage for Z8 and Z9 - 12/12/17 08:56

I'm afraid I do not really understand your problem. When you have open positions, you borrow margin and pay interest. That is the rollover. It has nothing to do with stock or forex. Forex is only a special case as you trade pairs, so rollover is here the interest difference.

Just enter the Rollover in the asset list as in the example that I gave. It is daily interest*price*(1-1/leverage). If you want it to be very precise, you can really calculate rollover in the script once per day, but then you need to know the broker's current interest.
Posted By: kujo

Re: Interest on leverage for Z8 and Z9 - 12/12/17 15:01

Originally Posted By: jcl
I'm afraid I do not really understand your problem. When you have open positions, you borrow margin and pay interest. That is the rollover. It has nothing to do with stock or forex. Forex is only a special case as you trade pairs, so rollover is here the interest difference.

Just enter the Rollover in the asset list as in the example that I gave. It is daily interest*price*(1-1/leverage). If you want it to be very precise, you can really calculate rollover in the script once per day, but then you need to know the broker's current interest.


Oh, it seems that finally comprehension arrived to me... :-)
Because of this part (1-1/leverage) the interest will be calculated only for borrowed amount, not for all. Well, thanks for your help and patience!

I also found this phrase in the manual:
If the Rollover is unknown, it can be estimated from the current annual interest divided by 365 and multiplied with asset price/leverage.

I believe instead of price / leverage it should be price * (1 - 1/leverage). Correct me please if I am wrong.
Posted By: kujo

Re: Interest on leverage for Z8 and Z9 - 12/12/17 15:29

Also, as I understand, RollLong is a fixed value.
Example:
Let's assume that we are trading a stock which price starts with an initial price = 50 (leverage=3, cost of borrowing 5%). However, at the end of the testing period the stock's price is 100.
In an asset list we enter RollLong = 50 * 0.05 * (1 - 1/3) / 365 = 0.0046.

So, the same rolllong 0.0046 will be applied when I open a trade in the beginning of the testing period (price=50) and in the end of the period (price=100). And to adjust the rollong (i.e. 0.0092 when the price=100) I need to calculate rolllong once per day manually.

Do I understand it correctly?
Posted By: jcl

Re: Interest on leverage for Z8 and Z9 - 12/12/17 16:14

Yes, it is price*(1-1/leverage). When the price changes, rollover also changes. If you want to catch the price change, update the RollLong variable any day, using the same formula. The entry in the asset list is fixed.
Posted By: kujo

Re: Interest on leverage for Z8 and Z9 - 12/12/17 16:26

I see, I wonder if you have a code snippet for this calculation. If not, could you give me a hint how to do this?
Posted By: jcl

Re: Interest on leverage for Z8 and Z9 - 12/12/17 16:30

RollLong = priceClose()*(1-1/Leverage)*0.03/365;

but check if your broker really calculates rollover this way. Some brokers have different methods to determine rollover, such as a fixed fee per asset.
Posted By: kujo

Re: Interest on leverage for Z8 and Z9 - 12/12/17 16:38

Thank you!
Posted By: mhdus

Re: Interest on leverage for Z8 and Z9 - 01/09/18 17:09

As Zorro can now trade options: why not completely avoiding the interest cost by trading synthetics (long calls + short puts) instead of the underlyings? Margin requirements are quite similar (somewhat depending on account types) but there is no interest to be paid (ok, no dividends earned either).
Would that be something for the Zorro developers to consider for Z8 and Z9, eventually as a configurable alternative? Anyone else interested?
© 2024 lite-C Forums