Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 672 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: Interest on leverage for Z8 and Z9 [Re: kujo] #469840
12/11/17 07:58
12/11/17 07:58
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
Just calculate the rollover as in the example. What exactly is the problem?

Re: Interest on leverage for Z8 and Z9 [Re: jcl] #469845
12/11/17 12:31
12/11/17 12:31
Joined: Dec 2017
Posts: 129
Halifax, NS
K
kujo Offline OP
Member
kujo  Offline OP
Member
K

Joined: Dec 2017
Posts: 129
Halifax, NS
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!

Re: Interest on leverage for Z8 and Z9 [Re: kujo] #469849
12/11/17 13:35
12/11/17 13:35
Joined: Sep 2017
Posts: 235
H
Hredot Offline
Member
Hredot  Offline
Member
H

Joined: Sep 2017
Posts: 235
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.

Last edited by Hredot; 12/11/17 13:37.
Re: Interest on leverage for Z8 and Z9 [Re: Hredot] #469855
12/11/17 16:48
12/11/17 16:48
Joined: Dec 2017
Posts: 129
Halifax, NS
K
kujo Offline OP
Member
kujo  Offline OP
Member
K

Joined: Dec 2017
Posts: 129
Halifax, NS
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!

Last edited by kujo; 12/12/17 01:51.
Re: Interest on leverage for Z8 and Z9 [Re: kujo] #469869
12/12/17 08:56
12/12/17 08:56
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
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.

Re: Interest on leverage for Z8 and Z9 [Re: jcl] #469880
12/12/17 15:01
12/12/17 15:01
Joined: Dec 2017
Posts: 129
Halifax, NS
K
kujo Offline OP
Member
kujo  Offline OP
Member
K

Joined: Dec 2017
Posts: 129
Halifax, NS
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.

Re: Interest on leverage for Z8 and Z9 [Re: kujo] #469883
12/12/17 15:29
12/12/17 15:29
Joined: Dec 2017
Posts: 129
Halifax, NS
K
kujo Offline OP
Member
kujo  Offline OP
Member
K

Joined: Dec 2017
Posts: 129
Halifax, NS
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?

Re: Interest on leverage for Z8 and Z9 [Re: kujo] #469885
12/12/17 16:14
12/12/17 16:14
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
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.

Re: Interest on leverage for Z8 and Z9 [Re: jcl] #469886
12/12/17 16:26
12/12/17 16:26
Joined: Dec 2017
Posts: 129
Halifax, NS
K
kujo Offline OP
Member
kujo  Offline OP
Member
K

Joined: Dec 2017
Posts: 129
Halifax, NS
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?

Re: Interest on leverage for Z8 and Z9 [Re: kujo] #469887
12/12/17 16:30
12/12/17 16:30
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
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.

Page 2 of 3 1 2 3

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1