Creating a trading system from scratch

How many lines of code you are comfortable with


  • Total voters
    61

UberMachine

Well-Known Member
#21
Actually, we don't know the open price yet since today (22nd AUG 2018) is a trading holdiay. We can fill this only tomorrow.:)

Dear UB,
in excell its time consuming , sometime errors also if any step mistaken....if we put bhavcopy in one sheet all other things need to come automaticly...otherwise we need to 3-4 steps to get orders ...
trading that close price is not good as its comes only after market hours ...for live trading its better to close positions @ 3.15
And, you nailed it regarding the errors; the python script would automate this process by just uploading the 2 files needed.

I use close prices for backtesting rather than the LAST price since the approximation is quite good. In real time, I close these orders at around 3:00 P.M it can be closed even sooner if the results are favourable
 
Last edited:

UberMachine

Well-Known Member
#22
So, the same system in Python. Instructions for use
  1. Unzip the file to a folder
  2. Navigate to this folder in cmd and run the notebook using jupyter notebook. You can also try jupyter lab if you are adventurous
  3. Follow the instructions in the System notebook
  4. Change only the PARAMETERS
I have included only the files for 20 and 21st, you can test it for any dates. So to do a backtest for the last 5 days, you can change the filename in PARAMETERS and save each results in a separate folder. Post in case of any doubts or clarifications
  • Don't get intimidated by a lot of code in the notebook. Most of them redundant and verbose. It's just to show each of the steps we peform
  • Don't try backtest for longer periods. There are easier methods to do it.
 

Attachments

VJAY

Well-Known Member
#23
Actually, we don't know the open price yet since today (22nd AUG 2018) is a trading holdiay. We can fill this only tomorrow.:)


And, you nailed it regarding the errors; the python script would automate this process by just uploading the 2 files needed.

I use close prices for backtesting rather than the LAST price since the approximation is quite good. In real time, I close these orders at around 3:00 P.M it can be closed even sooner if the results are favourable
Ok so its open price of trading day...I thought its closing price of previous day and we enter today @that price...
 
#25
Wow just reading your code ,small code to download files
Python:
import requests, zipfile, io
# to download specific date like 20 aug change cm21AUG2018bhav.csv.zip in link to cm20AUG2018bhav.csv.zip

r = requests.get('https://www.nseindia.com/content/historical/EQUITIES/2018/AUG/cm21AUG2018bhav.csv.zip')

z = zipfile.ZipFile(io.BytesIO(r.content))

z.extractall()
 

UberMachine

Well-Known Member
#27
Great appreciation for your work sir
So the Open prices have to updated manually or i am doing something wrong
Yes, the open prices are to be updated manually since we don't have connection to a data source so far. So you are basically going to do three runs.
  1. First update today's bhav copy and run it the next day to get the recommendations
  2. Fill in the OPEN price at the start of the next day to get the prices
  3. Update the next day's bhav copy at the end of the day to evaluate performance
As expected, this would definitely be automated.
I am just doing an iterative development; make the system better than the previous step
 

UberMachine

Well-Known Member
#28
Wow just reading your code ,small code to download files
Python:
import requests, zipfile, io
# to download specific date like 20 aug change cm21AUG2018bhav.csv.zip in link to cm20AUG2018bhav.csv.zip

r = requests.get('https://www.nseindia.com/content/historical/EQUITIES/2018/AUG/cm21AUG2018bhav.csv.zip')

z = zipfile.ZipFile(io.BytesIO(r.content))

z.extractall()
Appreciate it. Its coming soon including fetching the open data and get files automatically download without dates.
And I use the same code in my live system :up:
 
#29
Just for back testing i ended up using perv day output to filter current date eod so i have update prices automatically,i had some issue with OPEN and OPENPRICE
Correct me if i am wrong
ORDER_FILENAME=Day on which we select stocks as per criteria
RESULT_FILENAME=date on which actual trading happens
Python:
orders1 = pd.read_csv(RESULT_FILENAME, parse_dates=['TIMESTAMP'],
                    usecols=range(13))
symbols1 = pd.read_excel('output.xlsx').values.ravel()
df1 = orders1[orders1['SYMBOL'].isin(symbols1)]
df1 = df1[df1['SERIES'] == "EQ"].reset_index(drop=True)

df1[['TIMESTAMP', 'SYMBOL', 'OPEN']].to_excel('output1.xlsx', index=False)
print('Updated buy price in the output1.xlsx file')
df1[['TIMESTAMP', 'SYMBOL', 'OPEN']]
and used this to update current day prices just for little bit Backtesting and put this in
[Update OPEN PRICE in output.xlsx file and run the below file]
orders = pd.read_excel('output1.xlsx')
 
Last edited:
#30
For downloading this months files at once i ended up with this funny code
Python:
import requests, zipfile, io

#i=0

while i<24:
    if i<10:
        r = requests.get('https://www.nseindia.com/content/historical/EQUITIES/2018/AUG/cm0'+str(i)+'AUG2018bhav.csv.zip')
        if len(r.content)<300:
            
            i+=1
        else:
            
            z = zipfile.ZipFile(io.BytesIO(r.content))
            z.extractall()
            i+=1
    else:   
        r = requests.get('https://www.nseindia.com/content/historical/EQUITIES/2018/AUG/cm'+str(i)+'AUG2018bhav.csv.zip')
        if len(r.content)<300:
            i+=1
        else:
            z = zipfile.ZipFile(io.BytesIO(r.content))
            z.extractall()
            i+=1
 

Similar threads