It looks like you're new here. If you want to get involved, click one of these buttons!
# Bracket and cover order Margins calculation:-
# Equity:-
co_lower = co_lower/100
co_upper = co_upper/100
trigger = price - (co_upper * price)
if stoploss < trigger:
stoploss = trigger
else:
trigger = stoploss
x = 0
if transaction_type == 'buy':
x = (price - trigger) * quantity
else:
x = (trigger - price) * quantity
y = co_lower * price * quantity
margin = x > y ? x : y
margin = margin + (margin * 0.2)
#NFO
if options:
# For NIFTY and BANKNIFTY
if 'NIFTY' in tradingsymbol and transaction_type == 'buy':
margin = price * quantity * 0.70
else:
margin = (strike_price + price) * quantity * 0.025
#Futures
else:
co_lower = co_lower/100
co_upper = co_upper/100
trigger = price - (co_upper * price)
if stoploss < trigger:
stoploss = trigger
else:
trigger = stoploss
x = 0
if transaction_type == 'buy':
x = (price - trigger) * quantity
else:
x = (trigger - price) * quantity
y = co_lower * price * quantity
margin = x > y ? x : y
margin = (margin * 0.20) + margin
#MCX
co_lower = 0.01
co_upper = 0.019
trigger = price - (co_upper * price)
if stoploss < trigger:
stoploss = trigger
else:
trigger = stoploss
x = 0
if transaction_type == 'buy':
x = (price - trigger) * quantity
else:
x = (trigger - price) * quantity
y = co_lower * price * quantity
margin = x > y ? x : y
margin = margin + (margin * 0.4)
#CDS
co_lower = co_lower/100
co_upper = co_upper/100
trigger = price - (co_upper * price)
if stoploss < trigger:
stoploss = trigger
else:
trigger = stoploss
x = 0
if transaction_type == 'buy':
x = (price - trigger) * quantity
else:
x = (trigger - price) * quantity
y = co_lower * price * quantity
margin = x > y ? x : y
margin = margin + (margin * 0.2)
if stoploss < trigger:
stoploss = trigger
else:
trigger = stoploss
margin = x > y ? x : y
try this:
margin=max(x,y)
You can check out this thread for margins API.
Am I missing something here? How have you initialized the stoploss value?
margin = (strike_price + price) * quantity * 0.25
For Strike_price = 12000, price=1000, quantity=75 from the above formula one gets a value of Rs. 2,43,750
The same values entered in your formula calculator on your site gives Rs. 24,375
i.e. exactly one tenth the value. What am I missing here?
margin = (margin * 0.20) + margin;
when I compare this to the actual margin you are blocking, it seems that there is an error. By the above calculation one NFO Nifty contract should block a margin of Rs. 50K, but you actually block only 42K right now.
It seems there is an error and that this line should be more like what is given below because when I use this then the margin calculated and the actual margin you block matches closely.
margin = (margin * 0.002) + margin;
Am I getting something wrong here, or is there an error in the calculation formula given to us?
The margin requirement has been updated recently.
You can know more here,
I am aware of the margin requirement changes. I read the bulletin every day morning. This has got nothing to do with the margin requirement change, I am just pointing out an error in the basic formula for calculating the margin as given by you above in this post itself.
To verify the same, just enter the current co_upper and co_lower in the formula and check for yourself.
Is there any code or api to calculate the normal margins required when we short options?
No, we don't have any API to calculate margins required for option shorting, you will have to manually use margin calculator.
Margin calculation for all F&O contracts is based on intra-day and eod/bod span files from the respective exchange and there are lot of other values considered too while calculating the same. Overall, it's complex calculation.
We are working on margin computation APIs at our end for API clients as well. The same, we recently offered on the Kite web.
Update: Margin APIs is added. Go through the documentation here.
You can refer to this thread.
Thanks for your response. I will try that.
why have you added this line margin = margin + (margin * 0.2) ?
and from where will we get this value of 0.2? Is it a constant?
In equity segment.
trigger = stoploss
I have one doubt. I was going through @sujith's explaination at the top of this thread. After looking at the response of https://api.kite.trade/margins/equity , i observed that co_upper is always lower than co_lower. So if co_upper < co_lower, then the leverage would always be 1/co_lower regardless of my stoploss. ( i am representing stoploss as percentage )
There are three cases :-
1. stoploss < co_upper < co_lower :-- in this case trigger will be same as stoploss. and since stoploss < co_lower, my leverage would be 1/max(stoploss,co_lower) which is 1/co_lower
2. co_upper < stoploss < co_lower :-- In this case trigger will be co_upper and since co_upper < co_lower, my leverage would again be 1/co_lower.
3. co_upper < co_lower < stoploss . This would be same as case 2.
So, in short if co_upper < co_lower, i can safely assume that leverage i would get is 1/co_lower regardless of my stoploss. Am I missing something here?
{"margin": 0, "co_lower": 5.95, "mis_multiplier": 10.0,
"tradingsymbol": "BOSCHLTD",
"co_upper": 10.0, "nrml_margin": 0, "mis_margin": 9.91}
sujith used margin + 0.2 * margin. Where does this 0.2 come? is it a constant?