Working out Margin Requirements Thread

I hope you find it useful. As you may have seen, @obrienciaran is hoping to add a couple of extra features soon.

1 Like

Watch this space tomorrow. Hangover depending.

It is a good template though for anything which may be needed in future similarly.

Code is available here if anybody would like to add to it. @Finki @pipo @nickspacemonkey

2 Likes

@obrienciaran, I just noticed that you’re not allowing the “Result” to go below 0. A negative figure would indicate that people can actually remove funds from their account in order to achieve a specific percentage, which might be quite useful.

Also, how would you feel about changing the wording to:

  • Input your ACCOUNT VALUE
  • Input your BLOCKED FUNDS

I think it would be clearer if the text exactly matched what appears in the app, including the case of the letters.

Having said that, I haven’t yet checked how these values are represented on the website.

1 Like

@Richard.W and @obrienciaran, what do you make of this?:

How to calculate how much will you need to keep your position open after the margin requirements increase? – Trading 212

Yes another good point. Fair play. Is a negative value of concern would be my first question? Given the panic of the situation do people want to remove money? Maybe however! This could be implemented easily.

Right now we are saying that if the person has enough money in the account to meet their target requirement, take no action; I.e. 0 deposit pound needed. It could be worthwhile to show users they can take out money however and still be afloat. This should be an easy fix to the calculations. Just allow the calculations to go into the minus rather than defaulting to 0.

I’m 6 beers in so this is one for the morning!

Agreed also on the ACCOUNT VALUE and BLOCKED FUNDS. Will implement in the morning.

2 Likes

I’ve just looked at the web site. It uses the terms (in order, from left to right across the bottom of the screen):

  • LIVE RESULT - seems to match “Total” at the bottom of the OPEN POSITIONS screen in the app
  • FREE FUNDS - seems to match FREE FUNDS in the app
  • BLOCKED FUNDS - seems to match BLOCKED FUNDS in the app
  • USED MARGIN - for me, this shows the same figure as BLOCKED FUNDS
  • ACCOUNT VALUE - seems to match ACCOUNT VALUE in the app
  • STATUS - seems to match the 25%/45% progress bar in the app, which isn’t labelled but I’ve seen referred to as the “Margin Indicator”.

Does anybody have any idea what the difference between BLOCKED FUNDS and USED MARGIN is?

Just double checking so I’m getting this right:

Is it correct to say:

  • Cash Required to Maintain Current Margin Percentage = Blocked Funds * 2.5 - Blocked Funds
  • Margin Percentage if No Action Taken = Account Value/(Account Value + Blocked Funds*2.5)*100

@Richard.W

1 Like

I’m out walking just now, but both those calculations seem correct. I think that’s how I did it on the spreadsheet I knocked up yesterday.

By the way, the first one can just be expressed as 1.5 * BLOCKED FUNDS!

True! That’s much neater with 1.5 x BLOCKED FUNDS.

Great. I uploaded the new version with these elements in now. I’ll tidy up the appearance a bit. Enjoy the walk.

1 Like

Oh, my mistake. You need to handle the <50% case separately. Do you know what I mean by that?

I do indeed. Do I know how to do the calculation for that however is another question :smiley:

2 Likes

I think @Richard.W listed the formula yesterday, perhaps on the original topic.

1 Like

Check out this post.

2 Likes

By the way, which of the two formula are you using if BLOCKED FUNDS = ACCOUNT VALUE? They should both yield 50%, so it doesn’t matter, but I want to make sure it hasn’t fallen through the gap!

This might be a bit of overkill…

Now that you’ve written some code to calculate the margin percentage, you could run that code against the result of your calculation to check that it matches the user-specified value on the slider.

I’m worried about people losing money as a result of some mistake in our logic. If the two values don’t match (perhaps with a small tolerance to account for rounding issues) then you could display something like "There is an error in the calculation. Please post your ACCOUNT VALUE and BLOCKED FUNDS to the Calculator forum topic. If they do match, you could (optionally) put “VERIFIED” in brackets after the result!

I’m not sure what sort of tolerance to set. You could just show both figures, plus a difference, and put a label that prompts the user to compare the two values.

I’m gold-plating now…

Could you add FREE FUNDS underneath ACCOUNT VALUE and BLOCKED FUNDS and calculate it by subtracting the latter from the former? Then put a label next to it that says “If this doesn’t match the FREE FUNDS figure shown by Trading 212, please check your figures”.

With the default values of 200 and 100, shouldn’t the new values be 300 and 40% respectively?

Get yourself a little donate button on too, you deserve a drink for all this work regardless :+1:

2 Likes

So one formula is taking a condition for greater than or equal to 50%
2.5 * blocked_funds) / ((1 / (target_margin / 100)) - 1)) - account_value

The other then is for over 50%
(target_margin*.05*blocked_funds) - account_value

Yes I like this idea. There could be a rounding error but a tolerance of .1 could suffice here.

Just implementing the formula for cash required to maintain current margin percent if under 50%. Currently it is still as per my formula above.

Another good idea and a simple win.

1 Like

Now I can’t even edit these messages!

Did you see this edit? I now know you’re still working on the percentage, so it’s just the 150 instead of 300 that we need to look at.