syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

Question:
Quantiacs On Linux Lesson 2?

In Lesson 1 we learned that Quantiacs is a startup which helps me use Data Science to invest in markets.

Also we learned how to run one of the python-sample scripts on Linux.

I just got a new laptop so, I started lesson 2 by installing VirtualBox on my laptop:

https://www.virtualbox.org/wiki/Downloads

Inside of VirtualBox I installed Ubuntu 14:

http://releases.ubuntu.com/14.04/ubuntu-14.04.3-desktop-amd64.iso

I logged into Ubuntu and installed some packages:
apt-get install zip openssh-server emacs wget curl
Next I created an account named 'qq' which is the account I use when I work with Quantiacs:
useradd -m -s /bin/bash qq
passwd qq
Then, I logged into the qq account:
ssh -YA qq@localhost
Next, I downloaded Anaconda which contains Python:
mkdir -p ~qq/Downloads
cd       ~qq/Downloads
wget https://3230d63b5fc54e62148e-c95ac804525aac4b6dba79b00b39d1d3.ssl.cf1.rackcdn.com/Anaconda-2.3.0-Linux-x86_64.sh
Then, I installed Anaconda Python:
cd   ~qq/Downloads
bash Anaconda-2.3.0-Linux-x86_64.sh
After the install I adjusted ~qq/.bashrc:
echo export PATH=${HOME}/anaconda/bin:{$PATH} >> ~qq/.bashrc
Also I did a bug-work-around in Anaconda:
mv ${HOME}/anaconda/bin/curl ${HOME}/anaconda/bin/curl_anaconda
And, I verified:
qq@nia110 ~ $ 
qq@nia110 ~ $ 
qq@nia110 ~ $ python
Python 2.7.10 |Anaconda 2.3.0 (64-bit)| (default, May 28 2015, 17:02:03) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> 
qq@nia110 ~ $ 
qq@nia110 ~ $ 
qq@nia110 ~ $ 
I noticed that I installed Python 2.7.x.
Quantiacs wants me to run Python 2.7.x., not Python 3.x.y.

Next, I installed some Quantiacs software:
pip install quantiacsToolbox
I wrote a tiny two-line Python script:
# ~/q14.py
import quantiacsToolbox
returnDict = quantiacsToolbox.runts('/home/qq/q14q.py')
# end
The above script calls this script:
# q14q.py

import numpy as np

def myTradingSystem(DATE, OPEN, HIGH, LOW, CLOSE, VOL, exposure, equity, settings):
    myd    = DATE[0]
    mymnth = str(myd)[4:6]
    if (mymnth=='05') or (mymnth=='06') or (mymnth=='07') or (mymnth=='08') or (mymnth=='09'):
      # Sell in May, Go Away.
      weights = np.array([[2.0,-1.0]])
      # Above, I want to be -100% weighted in F_ES.
      # The cash I get from that short-sale forces me to be
      # 200% weighted in CASH.
    else:
      # Return in Oct
      weights = np.array([[0.0,1.0]])
      # Above, I want to be 100% weighted in F_ES.
      # So, I should be 0% weighted in CASH.
    return weights, settings


def mySettings():
    settings= {}
    # Futures Contracts
    settings['markets']  = ['CASH','F_ES']
    settings['lookback']= 2
    settings['budget']= 10**6
    settings['slippage']= 0.05
    return settings
The above script implements this English logic.
  • On the first trading day of every May,
    sell-short F_ES such that I am -100% weighted in F_ES.
    I hold the short position until October.
  • On the first trading day in October,
    replace the short position with a long position.
    This position should make me 100% weighted in F_ES.
I ran a simple shell command to run my script:
python q14.py
I saw this syntax in my shell:
qq@nia110 ~ $ 
qq@nia110 ~ $ 
qq@nia110 ~ $ python q14.py
Downloading CASH
Downloading F_ES
Loading Data...
Done! 
Evaluating Trading System
qq@nia110 ~ $ 
qq@nia110 ~ $ 
qq@nia110 ~ $ 


Also, a window appeared:


According to that chart, the 'Sell in May' strategy failed during the Y2K crash and the 2008 crash.

Quantiacs has no data for 1987 but, also it would have failed during the 1987 crash.

Other than those crashes, the 'Sell in May' strategy seems to work better than 'Go Long'.


syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me