Creating a trading system from scratch

How many lines of code you are comfortable with


  • Total voters
    61
master
Code:
from scipy import log,exp,sqrt,stats
from scipy import log,exp,sqrt,stats
S=10907;X=10900;T=0.0821918;r=0.0655;c=208.1
def bsCall(S,X,T,r,sigma):
    d1=(log(S/X)+(r+sigma*sigma/2.)*T)/(sigma*sqrt(T))
    d2 = d1-sigma*sqrt(T)
    return S*stats.norm.cdf(d1)-X*exp(-r*T)*stats.norm.cdf(d2)


def impliedVolBinary(S,X,T,r,c):
    k=1
    volLow=0.001
    volHigh=1.0
    cLow=bsCall(S,X,T,r,volLow)
    cHigh=bsCall(S,X,T,r,volHigh)
    if cLow>c or cHigh<c: 
        raise ValueError
    while k ==1: 
      

        cLow=bsCall(S,X,T,r,volLow)
        cHigh=bsCall(S,X,T,r,volHigh)  
        volMid=(volLow+volHigh)/2.0  
        cMid=bsCall(S,X,T,r,volMid)
        if abs(cHigh-cLow)<0.01: 
            k=2 
        elif cMid>c:
            volHigh=volMid 
        else:
             volLow=volMid
    return volMid, cLow, cHigh
print("Vol,     cLow,      cHigh")
print(impliedVolBinary(S,X,T,r,c))
from python for finance looks pretty close on call side
well there is quantinsti.com as well
quantinsti.com
you should espcially see there blogs..
great site for algotraders
 

UberMachine

Well-Known Member
well there is quantinsti.com as well
quantinsti.com
you should espcially see there blogs..
great site for algotraders
I do see them (but not the article mentioned by you)
For capital/cash markets, security selection and capital management is good enough to cross the line but for options trading position sizing is also must. Most strategies work out only if you have sufficient capital and has a good buy/write strategy (@amrutham posts has a lot of input).

I am planning to do options testing based on historical data and a ML model (just forgot all the relationships between the underlying and treat each of them as unique). This is outlandish but I got to hold this as the baseline and then tweak and improve it. One of the simplest things we could do is to take something that's worked in the capital market and backtest it on derivatives.
 
Last edited:

UberMachine

Well-Known Member
I do see them (but not the articel mentioned by you)
For capital/cash markets, security selection and capital management is good enough to cross the line but for options trading position sizing is also must. Most strategies work out only if you have sufficient capital and has a good buy/write strategy (@amrutham posts has a lot of input).

I am planning to do options testing based on historical data and a ML model (just forgot all the relationships between the underlying and treat each of them as unique). This is outlandish but I got to hold this as the baseline and then tweak and improve it. One of the simplest things we could do is to take something that's worked in the capital market and backtest it on derivatives.
If how this is done in realtime, you can check out pyvideo.org videos on algorithmic trading.
 
You can automate options the same way you do scrips. But if you need fine grained control, you could subscribe for sensibulll, get the data and use kite connect API to fire your orders.
Got to know the specifics before further suggestions
I need is scalping script for amibroker for trading options exclusively.
 
UB sir,

I used to trade intraday in crude oil with sma5 and sma8 crossover strategy sir.Could you please give me sample code to zerodha kite in python to automate my strategy sir.
Thanks in Advance,
Radha
 

Similar threads