Documentation for the project “Predicting stock prices using I Ching”

This is the documentation for a python package for predicting the stock prices using I Ching.

Table of contents:

  1. Installation and setup
  2. Drawing the 8×8-Gua rotating plane
  3. Drawing the 64 c-Guas
  4. Drawing the 64 c-Guas and their corresponding Xiangs
  5. Predicting the stock prices

1. Installation and setup

Python version tested: python2.7

Download the folder (“projects/I-Ching”, temporarily available by private email request), and run the following bash (i.e., in the terminal of your linux/IOS system) commands inside the “I-Ching” folder:

pip install -r requirements.txt

python download_datasets.py

2. Drawing the 8×8-Gua rotating plate

Run “draw-8×8-rotating-plate.py”. You will get the follow figure inside “drawings/”:

8x8-gua

3. Drawing the 64 c-Guas

Run “draw-64gua.py”. You will get the follow figure inside “drawings/”:

64gua

4. Drawing the 64 c-Guas and their corresponding Xiangs

Run “draw_guas.py” and you will get 8 figures in the “drawings/guas/” folder such as the following one:

rotate-0

Run “draw_xiangs.py” and you will get 8 figures in the “drawings/xiangs/” folder such as the following one, which are the corresponding Xiangs of the above Guas:

rotate-0

5. Predicting the stock prices

Note: you should follow strictly the sequences bellow.

5.1 Obtaining the basic mode of velocities

Run “get-basic-mode.py” and you will get the parameters for the basic mode of velocities for the company specified by the parameter “sym_i” (by default it is IBM’s; and you can change it to get other companies’ ).

After obtaining the basic modes of velocities for several companies, you can run “plot_basic_modes.py” to plot the modes. The figure will be saved under “predictions/basic_modes/”.  You may also modify the code to plot the “cumsum()” of the velocities (the figure on the left below) to get the “basic modes of prices” (the figure on the right). Here is an example of the figures you are expecting to get:

5.2 Generating the dataset for training the neural network

Run “data-gen-64gua.py” with the parameter “sym” properly set to the name of the company, and you can specify how many samples to generate with the parameter “n_samples”.

5.3 Training the neural network

Run “train-predicter.py” and you will get the neural network trained for a company set by the parameter “sym”. After training for the first time, you can set “continued” to be “True” so that the next training would continue from the last training.

5.4 Doing prediction

Run “predict_empirical.py” you can generate predictions for the empirical dataset of the company specified by  the parameter “sym”. The parameter “n_samples” controls how many sample predictions you want to generate. The figures will be saved in “predictions/empirical/”. Here is a sample figure for the prediction.

3-34

Similarly, run “predict_simulation.py” you can generate predictions for the simulational dataset of the company specified by  the parameter “sym”. The parameter “n_samples” controls how many sample predictions you want to generate. The figures will be saved in “predictions/simulations/”. Here is a sample figure for the prediction.

8-2

5.5 Drawing the heat maps

Run “heatmap_8x8-sim.py”, and you will get the heat map for the simulational dataset. The parameter “N” controls how many samples you’d like to use. The heat map will look like the following:

Run “heatmap_8x8-sim.py”, and you will get the heat map for the simulational dataset. The parameter “N” controls how many samples you’d like to use. The heat map will look like the following:

5.6 Analyzing the residuals

Run “residuals-prediction-vs-null.py” you can get the residual analysis for the predictions for the company specified by the parameter “sym”. It will look like the following figure:

residuals

For any technical question, you may shoot me an email.

Publication: (preparing)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s