- Introduction
- Installation
- Usage
- Contributing
- License
- Contact
- Disclaimer
- References
- Appendix
- Changelog
- This repository is an implementation of the ideas mentioned in the book 'stocks on the move'. The book is written by Andreas Clenow.
- The book is about momentum investing
- Clone the repository
- Install the requirements (
pip install -r requirements.txt
) - Copy the file
app.properties.sample
toapp.properties
- We leverage Zerodha to pull OHLCV data and you need to have a Zerodha account. Log into your Zerodha account
at https://kite.zerodha.com/ and copy the
enctoken
from the cookies to app.properties file - I was initially relying on
kite.trade
to fetch the date, but I don't want to spend 4k every month for it when I can get it for free. - Look at the other properties and change them as per your needs
- We leverage Zerodha to pull OHLCV data and you need to have a Zerodha account. Log into your Zerodha account
at https://kite.zerodha.com/ and copy the
- Run the code by executing the main.py file (
python main.py
) - To get the current portfolio run
http://localhost:7999/api/portfolio
. This makes calls to Zerodha to get last closing price, So expect some time to get the response. Zerodha calls are cached, so subsequent calls become faster. - To rebalance the portfolio run
http://localhost:7999/api/rebalance
. This will take a while. If your stock universe is NIFTY_200, then it will take 4-5 minutes. Response will be visible on the screen. This will generate few files along with way, who's contents are mentioned below - Enjoy!
The code is written in python. The code is written in a modular way.
Details about the properties mentioned in app.properties file:
- app.host=
localhost
(This is the host on which the code will run) - app.port=
7999
(This is the port on which the code will run) - app.debug=
True
(This is the debug flag. If set to True, the code will run in debug mode) - kite.ui.base_url=
https://kite.zerodha.com
(This is the base url of the kite website) - kite.ui.client_id=
KWxxxx
(This is the client id of your Zerodha account) - kite.ui.enctoken=
xxxxxxx
(This is the enctoken of your Zerodha account) - portfolio.file=
portfolio.csv
(This is the file where the initial portfolio will be stored) - trade_day=
SUNDAY
(This is the day on which all the trades will be executed) - stock_universe_index=
NIFTY 50
(Stocks from this index will be considered for the portfolio) - num_historical_lookup_days=
365
(Number of days to look back for historical data)
Files generated by the code:
- ranking.csv - This file contains the ranking of all the stocks in the stock universe. The stocks are ranked based on their volatility adjusted momentum.
- portfolio.csv - This file contains the initial portfolio.
- portfolio_self_momentum_**.csv - These files are created when the code is run. These files contain the portfolio after each rebalancing.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
You can contact me at LinkedIn Or email me at [email protected]
- I am not a financial advisor.
- This is not a financial advice.
- I am not responsible for any losses incurred by you.
- Please do your own research before investing in any stocks.
Please refer to the book 'Stocks on the move' by Andreas Clenow for more details.
https://www.amazon.in/Stocks-Move-Beating-Momentum-Strategies-ebook/dp/B00YPHZO3W