Creating a trading system from scratch

How many lines of code you are comfortable with


  • Total voters
    61
#31
Really great work sir.....just a few issues from novice python coder why not use quantopian platform n find nse data source for it as you can immediately backtest on it.....n for web scraping you are using python....why not just use beautiful soup
means just saying why not just let all the user install all the lib at the beginning like matplotlib,beautiful soup,pycharm etc then we can start coding
And please if you are super busy can you provide us new guys with some algo trading links from where we can learn....Thanks a lot n keep up the good work...!!!
 
#32
And one more thing sir, I know most of the members have voted for less than 10 lines code.....maybe they are advance user....but doesnt shorter the code,more complicated it is....just will you try to make the code simple n trading system advance so that we can also tweak it as well...N thanks once again
 

VJAY

Well-Known Member
#33
And one more thing sir, I know most of the members have voted for less than 10 lines code.....maybe they are advance user....but doesnt shorter the code,more complicated it is....just will you try to make the code simple n trading system advance so that we can also tweak it as well...N thanks once again
Dear vinit,
IMO here most of us newbie not advances user :D...as far vote there no lesser line code mentioned in voting thats why we all voted for lesser lines...if there is 1 I will vote for that :D
 
#35
Dear vinit,
IMO here most of us newbie not advances user :D...as far vote there no lesser line code mentioned in voting thats why we all voted for lesser lines...if there is 1 I will vote for that :D
ya That's, why...means coding less than 10 lines, is highly ambitious...means importing library only will take nearly 5 lines...and then the main codes for minimizing spreads,slippage and all will be left out and that what algotrading is for right....!!!!
 
#36
Thanks UM for this beautiful thread. I was thinking of learning how to learn algo trading and found your thread.

Little bit busy now , will be active after 1st week of Sept. But definitely reading your posts whenever I get time.
 

UberMachine

Well-Known Member
#37
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')
Yes, you are right. You can use different filenames to collect backtesting data.
But we are not going to do follow this style since it becomes infeasible for large number of files
 

UberMachine

Well-Known Member
#38
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
You can look at this link for a better way to download files
 

UberMachine

Well-Known Member
#39
Really great work sir.....just a few issues from novice python coder why not use quantopian platform n find nse data source for it as you can immediately backtest on it.....n for web scraping you are using python....why not just use beautiful soup means just saying why not just let all the user install all the lib at the beginning like matplotlib,beautiful soup,pycharm etc then we can start coding
And please if you are super busy can you provide us new guys with some algo trading links from where we can learn....Thanks a lot n keep up the good work...!!!
  1. You can look at my thread Python installation for trading for installing everything in a single go. Its at the beginning of the thread along with the Python primer.
  2. Testing in quantopian is my ultimate aim but making it work with NSE is a big challenge. (I tried a couple of times and I am now fully on to it). I need to modify the source code to make things work plus the data should be in Panel format with all split and dividend information along with trading calendars. And it works only with Python 3.5 and configuring it on windows is another big problem (since I am not on windows). Presently, I am using fastbt to dirty check strategies before moving into a full fledged framework. And I don't see a need for web scraping.
  3. I am building this system from scratch only to bring a systematic approach to trading instead of taking discretionary trading or just plainly using indicator and charts. I am in no mood to reinvent the wheel. I believe this would help others in being more systematic and make algorithmic trading more accessible and do things on their own
  4. Regarding links to algo trading, I recommend quantopian lectures and pythonprogramming.net. Unfortunately, both don't cater to Indian markets
And one more thing sir, I know most of the members have voted for less than 10 lines code.....maybe they are advance user....but doesnt shorter the code,more complicated it is....just will you try to make the code simple n trading system advance so that we can also tweak it as well...N thanks once again
I want the system to be accessible for both who are comfortable with 10 lines of code and who could have more than 100 lines of code. I would abstract out a lot of things so that you are left with only 10 lines. If you look at my strategy, you could do it in just 5 lines of code. Would include libraries and files so that its accessible for all users. Again if you look at my first post, I expect this would take around 6-8 weeks to complete
 
Last edited:

UberMachine

Well-Known Member
#40
  1. You can look at my thread Python installation for trading for installing everything in a single go. Its at the beginning of the thread along with the Python primer.
  2. Testing in quantopian is my ultimate aim but making it work with NSE is a big challenge. (I tried a couple of times and I am now fully on to it). I need to modify the source code to make things work plus the data should be in Panel format with all split and dividend information along with trading calendars. And it works only with Python 3.5 and configuring it on windows is another big problem (since I am not on windows). Presently, I am using fastbt to dirty check strategies before moving into a full fledged framework. And I don't see a need for web scraping.
  3. I am building this system from scratch only to bring a systematic approach to trading instead of taking discretionary trading or just plainly using indicator and charts. I am in no mood to reinvent the wheel. I believe this would help others in being more systematic and make algorithmic trading more accessible and do things on their own
  4. Regarding links to algo trading, I recommend quantopian lectures and pythonprogramming.net. Unfortunately, both don't cater to Indian markets


I want the system to be accessible for both who are comfortable with 10 lines of code and who could have more than 100 lines of code. I would abstract out a lot of things so that you are left with only 10 lines. If you look at my strategy, you could do it in just 5 lines of code. Would include libraries and files so that its accessible for all users
Based on close price
1535030371289.png


Based on last price

1535030447004.png


In your open price column, the price is prev close. Not today's open :)
 

Similar threads