Saturday, November 4, 2017

How I Create My 1st Backtest With Python | Example: Google (GOOG)

Finally finished up my 1st backtest with Python.
Just shoot this video to help remind myself the basics
and hopefully, this can help people get their feet wet
on Python coding ... (advanced users feel free to jump around using the time table below)

Here, I am showing you 2 videos where the first one is the Python setup (from scratch)
and the second one is the backtest creation.

YouTube video link - Install Python & Related Packages:

*Note that I installed Python to specific folder "py362"  but you can feel free to decide the destination folder location.
**Also, I setup the Sublime Text 3 as my code editor.  Again, you can pick your own editor.
In the backtest creation video, I used the Python built-in editor (IDLE).
***I created the virtualenv (virtual environment) for my trade algo.
You don't need that for backtest.  But it's highly recommended if you want to build Python projects, other than trade algo.




YouTube video link - Creating backtest:
https://www.youtube.com/watch?v=D73NyNb2YZs


Time Table |English Version
hh:mm:ss
00:00:09 - 00:08:24 | part 1| Get stock data from Yahoo Finance + Save to Excel
00:08:26 - 00:14:49 | part 2.1| Strategy class - defininng basic parameters
00:14:50 - 00:21:21 | part 2.2| Strategy class - calculate moving averages
00:21:22 - 00:30:53 | part 2.3| Strategy class - calculate trend details
00:30:54 - 00:37:58 | part3.1| Signal class - calculate trade signal and order
00:30:59 - 00:45:51 | part4.1| Portfolio class - calculate trade amount
00:45:52 - 00:52:26 | part4.2| Portfolio class - calculate cash balance and asset position
00:52:26 - 00:57:56| part 5.1| calculate profit and loss + plot graph


For part 4.2 "cash_balance and asset position",
you can read Isaac Kwan's code for traditional stock trade style.
He offered great help in explaining the use of abstract-based class of Python (I am still figuring that out :))

https://gitlab.com/snippets/1681494


Python script: (underlying stock being changed to 0388.HK)
https://github.com/clueple/algo/blob/master/hkex_full_example.py

Isaac Kwan's link on part 4.2 - cash balance and asset position
https://gitlab.com/snippets/1681494



Finally, please read the video disclaimer
and by no means, this video be used for real trade.

No comments:

Post a Comment