Creating a trading system from scratch

How many lines of code you are comfortable with


  • Total voters
    61

VJAY

Well-Known Member
UberMachine.. Awesome is just one word to describe your process. I have been trading on your strategy for about a week. I'm net positive and have seen far better returns on intraday strategies. Thank you so much..
 
I am facin some issues. After lot of tests, te backtest notebook is workin. but facin issues wit SystemNew. orders.csv is not creatin and terefore te output.xlsx.
sould ORDER_FILENAME be named? I tried wit ORDER_FILENAME = 'orders.csv', but trows oter errors.
I did put orders.csv file in te folder and tried, but sows readin error.
Need expert comment pls.
Also tanks for suc beautiful tutorial.

(two alpabats not workin in my kepad, so te words like tat!)

oder filename.png
 

VJAY

Well-Known Member
You need to put open price in output file ...
 
You need to put open price in output file ...
It is not workin...I tried as you said.
as per te code open price comes later, first it to read te ORDER_FILENAME, read symbols from universe.xlsx, ten it will update te values in in output.xlsx puttin open price as 0.
 
Now I understood tat wit puttin bhav copy files for ORDER_FILENAME and RESULT_FILENAME, old system works.
So still in doubt for system new notebook.
sould we define tem manually as old file?
 

VJAY

Well-Known Member
Now I understood tat wit puttin bhav copy files for ORDER_FILENAME and RESULT_FILENAME, old system works.
So still in doubt for system new notebook.
sould we define tem manually as old file?
Yes ..bhavcopy need as like before...its not changed ...only code added for out put order csv to put oreders in nest
 
today i thought of using new system and i was not able to trade;)i thought that utils will auto update open price :D there is sell missing in place order so i added orders['order'] = 'SELL' and columns.update({'Order Type': 'SL'}) in between
here is the workaround for updating prices till master finishes new system
Python:
import requests
import re
orders = pd.read_csv(ORDER_FILENAME, parse_dates=['TIMESTAMP'],
                    usecols=range(13))
symbols = pd.read_excel('universe.xlsx', sheet_name=UNIVERSE, header=None).values.ravel()
df = orders[orders['SYMBOL'].isin(symbols)]
df = df[df['SERIES'] == "EQ"].reset_index(drop=True)
df['RET'] = (df['CLOSE']/df['PREVCLOSE']) - 1
result = df.sort_values(by='RET', ascending = False).iloc[:NUM_STOCKS]
df = orders[orders['SYMBOL'].isin(symbols)]
result['OPENPRICE'] = 0
s=[]
for symbol in result['SYMBOL']:
    url = 'https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?symbol='+symbol
    header = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64)AppleWebKit/537.11 (KHTML, like Gecko)Chrome/23.0.1271.64 Safari/537.11','Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3','Accept-Encoding': 'none','Accept-Language': 'en-US,en;q=0.8','Connection': 'keep-alive'}
    fetch = requests.get(url, headers=header)
    pp='"open":"(.+?)"'
    price=re.findall(pp,fetch.text)
    price
    s.append(price)
newop = pd.Series((num[0] for num in s))
result=result.reset_index(drop=True)
result['OPENPRICE']=newop
result[['TIMESTAMP', 'SYMBOL', 'OPENPRICE']].to_excel('output.xlsx', index=False)
print('Update OPENPRICE in the output.xlsx file')
result[['TIMESTAMP', 'SYMBOL', 'OPENPRICE']]
 

UberMachine

Well-Known Member
SystemNew updated on git

The following features are added
  1. Automatic quote lookup. So no need to manually updated output.xlsx
  2. Automatic order generation for NEST
  3. Daily orders are now saved in orders folder (so that you can keep track of them)
  4. Trading logic and pricing logic separated into different cells so that you can try out new strategies
  5. Performance is completely removed.; all performance to be done in backtest only
Requirements
  1. Create a new orders directory in your tradingsystem directory
  2. Download utils.py file and save it in the current folder
  3. Run all the cells
  4. For NEST order generation, update your ACCOUNTID
Else, git pull origin master to get things workling

What it does?
  • Get the returns from the file
  • Automatically get preopen returns
  • Generate an ``orders_to_place.csv`` for NEST orders
  • Save your orders for the day in orders folder with orders_date as filename
I have used NIFTY preopen json file for looking up quotes. This looks up quotes for NIFTY 50 only. If you need preopen price for all symbols, replace nifty.json with all.json in the utils.py file. If you want to go live, use atleast 2 indices (NIFTY 50 and NIFTY MIDCAP 50) for better performance. If you need to select 3 from each, create 2 separate tradingsystem folders and merge the orders at the time of order placement.

Beware preopen prices are updated only after 9:10:00. So, running this script before 9:10:00 would populate prices with previous data. So check before placing orders

If you are doing this tutorial for the first time, try out System before using SystemNew
 

Similar threads