Pair Trading - Exploring The Low Risk Statistical Arbitrage Trading Concepts

ncube

Well-Known Member
http://prntscr.com/kgror7 Ncube Sir today this pair gave close to 20 points per pair in the ratio of 1long Hindzinc for every 2.5 shares short of NMDC. So for 100:250 shares profits of Rs.2000 and 500:1250 profits of Rs.10000. Only paper trade. Is it right ?
@nurav, I am not clear about your calculation on how you got 20 points, I presume that you are calculating the spread between Hindzinc & NMDC in the ratio 1:2.5, but since we dont trade spread directly, it may not be accurate, hence suggest it would be better to consider the actual prices of the stocks while taking the trade and calculate the P&L.

I did not day trade it yesterday, I was tracking it for my positional trades, but if one would have day traded it yesterday and used 15min candle breakout, he could have made about 2.5-3 rs per share of NMDC short and Hindzinc would have been break even.
 
Last edited:

VJAY

Well-Known Member
@VJAY, Is this ok now?



The prices of HDFCBANK & ICICIBANK are not at same scale, HDFC is about 7 times that of ICICI, hence while plotting this pair change the resolution ratio to 7:1 as follows: xres=700, yres=100, what this does is while plotting SS1 value is divided by xres=700 and SS2 value by yres=100

So that they both are in the same scale as the zScore.

plot_pairs(df,SS1,SS2,lb=20,xres=700,yres=100)

You can change these values and make the required adjustment for the pairs.
No ...play button missing....
 

VJAY

Well-Known Member
For the cell you have selected, check what is the value in the dropdown next to the run button at the top of the notebook. It should be code, if its not code change the value to code in the dropdown.

View attachment 27329
Yes its code...But play button not showing!!!!!!!!!!

1533897556457.png
 

ncube

Well-Known Member
Yes its code...But play button not showing!!!!!!!!!!

View attachment 27339
@VJAY, there are no separate play button, the "Run" button at the top is the one you need to click to run the cell. If you want to run all the cells then you can click the "Cell" --> "Run All".

You can go through following quick start video of Jupyter notebook on youtube, it will make your life easy..:)


Go through this video has voice and has used stock data as example:


 
Last edited:

travi

Well-Known Member
@VJAY bhai.
now that weekend has started and no trading, you can skip a party or two and peacefully go through the tutorials :D
There's a lot to catch, use help button, go through inbuilt tutorial.

Try from "Cell" Menu > "Run All"

You can create a fresh ipynb and test things there.
 

lvgandhi

Well-Known Member
I have installed python 3.7. as per post 13 of this thread.
After pip install pandas, I got message as follows
The scripts conv-template.exe, f2py.exe and from-template.exe are installed in 'e:\program files\python37\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
How to add this folder in PATH permanently?

It also asked for upgrading pip from 10 to 18. I did that.
Then I did pip install matplotlib. Went OK.
Then I did
pip install statsmodels .
This gave following error.
Command ""e:\program files\python37\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\lvgan\\AppData\\Local\\Temp\\pip-install-v6hlip87\\statsmodels\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\lvgan\AppData\Local\Temp\pip-record-r2r3qjdr\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\lvgan\AppData\Local\Temp\pip-install-v6hlip87\statsmodels\

How to solve this error?
 

VJAY

Well-Known Member
I have installed python 3.7. as per post 13 of this thread.
After pip install pandas, I got message as follows
The scripts conv-template.exe, f2py.exe and from-template.exe are installed in 'e:\program files\python37\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
How to add this folder in PATH permanently?

It also asked for upgrading pip from 10 to 18. I did that.
Then I did pip install matplotlib. Went OK.
Then I did
pip install statsmodels .
This gave following error.
Command ""e:\program files\python37\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\lvgan\\AppData\\Local\\Temp\\pip-install-v6hlip87\\statsmodels\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\lvgan\AppData\Local\Temp\pip-record-r2r3qjdr\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\lvgan\AppData\Local\Temp\pip-install-v6hlip87\statsmodels\

How to solve this error?
Dear lvgandhi,
Please go through next few posts we some are experienced this type of problems which ncube brother cleared...please check
 

lvgandhi

Well-Known Member
Dear lvgandhi,
Please go through next few posts we some are experienced this type of problems which ncube brother cleared...please check
Thanks for the response. I have gone through the thread including your posts. I added path as suggested. I have installed visual c++2015 redistributable x64 also.
Still path problem is there.
Last error I am unable to understand. Have you got same error?
 

ncube

Well-Known Member
Thanks for the response. I have gone through the thread including your posts. I added path as suggested. I have installed visual c++2015 redistributable x64 also.
Still path problem is there.
Last error I am unable to understand. Have you got same error?
@lvgandhi , sometimes OS dependencies would cause python installation errors. If one faces these issues and new to python it is recommended to install anaconda as it bundles all the important packages and takes care of dependencies. However it is about 600MB in size and will occupy about 1.5GB after installation on your computer harddisk.

You can download anaconda from the following url:
https://www.anaconda.com/download/

Nice guide by @UberMachine , to explain the installation steps:
http://www.traderji.com/community/threads/python-installation-for-trading.106753/#post-1297784
 
Last edited: