A Blog Of Random Coding Techniques & Experiments Robert Askam

Setup and Run anfederico/Clairvoyant for social/historical cues for short term stock movement Post Setup and Run anfederico/Clairvoyant for social/historical cues for short term stock movement 1 year ago

A git project I have been very much interested in at the moment is a way of machine learning Stock Predicitons. Here are my findings.

Step 1

$git clone $https://github.com/anfederico/Clairvoyant.git BackTest
$cd BackTest/
$pip install clairvoyant
$python setup.py
cd clairvoyant/
$python __init__.py
$pip install -r requirements.txt
cd clairvoyant/
pip install nsepy

Step 2

Create a folder Tests in BackTest/clairvoyant.

Step 3

You can get Stock Codes for this example from NSE, I'm using RELIANCE.
Create a file called RELIANCE.py and add the following.
from clairvoyant import Backtest
from pandas import read_csv
from nsepy import get_history
from datetime import date

# Testing performance on a single stock

variables = ["Open", "Close", "High", "Low", "Volume"] # Financial indicators of choice # "SSO", "SSC"
trainStart = '2013-02-01' # Start of training period
trainEnd = '2015-07-15' # End of training period
testStart = '2015-07-16' # Start of testing period
testEnd = '2016-07-16' # End of testing period
buyThreshold = 0.1 # Confidence threshold for predicting buy (default = 0.65)
sellThreshold = 0.1 # Confidence threshold for predicting sell (default = 0.65)
C = 1 # Penalty parameter (default = 1)
gamma = 10 # Kernel coefficient (default = 10)
continuedTraining = False # Continue training during testing period? (default = false)
history = get_history(symbol="RELIANCE",
start=date(2013, 1, 1),
end=date(2017, 1, 1),
backtest = Backtest(variables, trainStart, trainEnd, testStart, testEnd, buyThreshold = 0.1, sellThreshold = 0.1)
data = read_csv("RELIANCE.csv") # Read in data
data = data.round(3) # Round all values
backtest.stocks.append("RELIANCE") # Inform the model which stock is being tested
for i in range(0,10): # Run the model 10-15 times

Step 5

$ python RELIANCE.py 
X1: Open
X2: Close
X3: High
X4: Low
X5: Volume
Buy Threshold: 10.0%
Sell Threshold: 10.0%
C: 1
gamma: 10
Continued Training: False
RELIANCE | Training: 02/01/2013-07/15/2015 Testing: 07/16/2015-07/15/2016

Total Buys: 2460
Buy Accuracy: 50.81%
Total Sells: 0
Sell Accuracy: 0.0%


How to remove the single quote from in front of the number Libre Office

Download the sample data as a CSV from Yahoo Data

In Libre Office convert the date column to the Format US MM/DD/YYYY
Highlight the column and then click Data->Text to Columns.