25 June 2017

Scrap/Automate the Windows Terminal of Zerodha PI Scanner

Scenario:
Consider a case where you already have your Trading Strategy on Zerodha PI. This is written in TadeScript. Normally this code can be re-written in any other platform. But there is a catch - What if you are using some TradeScript specific built-in function like TREND . As per the manual, the TREND function is built-in to the core of the programming language ,  "primitives" , as they call it.

Recreating the TREND  in a programming language like Python calls for reverse engineering.  And despite my efforts, I was not able to do so accurately. My take is that identifying the trend of any financial instrument goes a long way In determining the profitability of a trader. And the Trend function in TradeScript is pretty good.  So the best way forward is to retain the strategy "as is"  in TradeScript and merely Scarp the data from the Scanner output of Zerodha. 


Approach:
I first tried to scarp the data using AutoIt . But then the reality dawned upon me that AutoIt does not support  .NET based WinForms and Windows Presentation Forms (WPF).   This can be determined with the help of the Inspect tool provided in   Windows 10SDK .  ( On Win10, the following path should help you to locate Inspect.exe: C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x86 ). The  UIA Verify can also be used and is installed with the Windows Software Development Kit (SDK). It is located in the \bin\<platform>\UIAVerify folder of the SDK installation path (VisualUIAVerifyNative.exe).

Although AutoIt didn’t help, thankfully Pywinauto was up and ready with version  0.6.1 that fully supports  MSUI Automation (UIA support for WinForms, WPF, Qt, browsers, Store apps and more).

A point to note here is that once we identify the type of Controls of the Zerodha Pi Scanner Output  using Inspect / Spy ++ / UIAVerify / AutoIt Window Info , put these tools to rest. For use in the Python program,  use the name of the specific dialog by using the  Control Identifiers from   print_control_identifiers() method of Pywinauto 


03 June 2017

Get Real Time Data from Google Finance for NSE - Multi Threaded

This program is very similar to Get Real Time Data from Google for NSE . The difference is that this program uses concurrent.futures module in Python 3.5 to launch parallel tasks
  • The purpose of this program is to retrieve  Google Intraday Data for a list of symbols from the NSE stock exchange . Designed to run until 15:30 hrs Indian Standard Time(IST)
  • The Input file for this program is an Excel Spreadsheet. Name it as "stock_symbols". Enter the list of stocks in the  first column of the sheet for which you would like to retrieve the Google Intraday Data. 
  • This is a multi threaded program that uses the  concurrent.futures module (only from version Python 3.2) for asynchronously executing callables (Synchronous tasks are essentially Sequential in nature ie; when you do something synchronously, you wait for it to finish before moving on to another task. When you do something asynchronously, you can move on to next task before it finishes.)
  • The following arguments are required for the program :  sheetname time_in_minutes
  • Write's the output in OHLCV format in a CSV file
            When tested on a Intel I3-2367M processor for a list of 200 stocks:
            • For sequential processing , the time taken was about 30 seconds.
            • For asynchronous processing, the time taken was about 16 seconds.



            Test it yourself and verify the results for yourself. The results will vary based upon the machine that you use and your net speed.

            Program on GitHub  

            Cheers Maadi !!!