Creating a trading system from scratch

How many lines of code you are comfortable with


  • Total voters
    61

UberMachine

Well-Known Member
Hi UB,

I am having EOD database in mysql so instead of loading files through pandas can i use Rapid API to load data from mysqldatabase.If 'Yes',kindly can you tell me which class or function i should be using to achieve this.
You could do it. You need to pass a connection string as shown in the home page
Python:
from sqlalchemy import create_engine
engine = create_engine('sqlite:///data.db')
backtest(connection=engine, tablename='data')
Since you use MSSQL, your connection string should be in one of the following two variants
Python:
# pyodbc
engine = create_engine('mssql+pyodbc://scott:tiger@mydsn')

# pymssql
engine = create_engine('mssql+pymssql://scott:tiger@hostname:port/dbname')
Connection from MYSQL
Python:
engine = create_engine('mysql://scott:tiger@localhost/foo')
More info on connection string here

Doing this would load the entire table into memory and it expects timestamp and symbol columns in the database.
A better way would be to use the pd.read_sql_query function.
 
Last edited:

UberMachine

Well-Known Member
master the easiest way atm only https://www.nseindia.com/live_marke...trument=OPTSTK&symbol=RELIANCE&date=27DEC2018:DThis is just a empty concept no setup ,it will be even better using open price and open iv of today ,we enter at these levels or we exit at these:cool:,we can use open price +sd*0.236 or0.382 to take entry and exit at extreme
But, what price to enter? Maybe the ATM option.
But in any case, calculating the IV would help us backtest and see the patterns in a better manner.
Could you try it out the same strategy on cash markets and options using historical volatility?
As far as I know, there is no easy framework for options constructions out of the box.
Are you a full time trader?
 

prabhsingh

Well-Known Member
You could do it. You need to pass a connection string as shown in the home page
Python:
from sqlalchemy import create_engine
engine = create_engine('sqlite:///data.db')
backtest(connection=engine, tablename='data')
Since you use MSSQL, your connection string should be in one of the following two variants
Python:
# pyodbc
engine = create_engine('mssql+pyodbc://scott:tiger@mydsn')

# pymssql
engine = create_engine('mssql+pymssql://scott:tiger@hostname:port/dbname')
More info on connection string here

Doing this would load the entire table into memory and it expects timestamp and symbol columns in the database.
A better way would be to use the pd.read_sql_query function.
Thanks.

I am just downloading Bhavcopy from NSe and loading that into DB.So above would work?
 

prabhsingh

Well-Known Member
But, what price to enter? Maybe the ATM option.
But in any case, calculating the IV would help us backtest and see the patterns in a better manner.
Could you try it out the same strategy on cash markets and options using historical volatility?
As far as I know, there is no easy framework for options constructions out of the box.
Are you a full time trader?
Historic Volatility is different then Implied because it HV only considers cash part where as IV as name suggest needs to consider options as well so not sure how back testing would work over here.
 

pannet1

Well-Known Member
Thanks.

I am just downloading Bhavcopy from NSe and loading that into DB.So above would work?
try it and see.

if you want to store the Bhavcopy for later use then you will need a local db. even if that is the case BHAVCOPY is always there at NSE. A rare scenario would be if you need to test the strategy offline.

also you asked for mysql and UB gave Ms sql. whatever you need please apply the correct connection string for it to work.
 

UberMachine

Well-Known Member
Historic Volatility is different then Implied because it HV only considers cash part where as IV as name suggest needs to consider options as well so not sure how back testing would work over here.
You are right. Its just to get started to see whether the historical volatility has any sort of correlation (nothing sort of it in capital markets).
If possible, we could try to infer IV from collecting data, comparing with HV and then removing volatility for cash/time part; you could be thinking its much better to calculate the IV in first place :) as already mentioned but we could try it as a proxy to see we can infer something since we have no out of box tool to do this type of backtesting.
 

prabhsingh

Well-Known Member
try it and see.

if you want to store the Bhavcopy for later use then you will need a local db. even if that is the case BHAVCOPY is always there at NSE. A rare scenario would be if you need to test the strategy offline.

also you asked for mysql and UB gave Ms sql. whatever you need please apply the correct connection string for it to work.
You need to read my message correctly.I am already having local MySQL dB where I am downloading Bhavcopy and F&o files and storing to database.This is all automated with task manager and code written in Python.Now I want code to read data from MySQL and calculate other required trading values like percent change,NR7 etc.
 

UberMachine

Well-Known Member
try it and see.

if you want to store the Bhavcopy for later use then you will need a local db. even if that is the case BHAVCOPY is always there at NSE. A rare scenario would be if you need to test the strategy offline.

also you asked for mysql and UB gave Ms sql. whatever you need please apply the correct connection string for it to work.
Great catch. Missed it. Now added
 

Similar threads