GithubHelp home page GithubHelp logo

ekloberdanz / tradingplatform-machinelearning Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 1.53 MB

Machine learning trading platform: a neural net for technical analysis and a natural language processing model for sentiment analysis of webscraped news articles. Achieved returns 4% above market.

Python 100.00%

tradingplatform-machinelearning's Introduction

Developed a neural net for technical analysis and a natural language processing model for sentiment analysis of webscraped news articles. Achieved returns 4% above market.

All programs must be run with Python3. I used Python 3.5.2 on Ubuntu 16.04.

The code base contains two machine learning models: 
(1) Neural Net for predicting if S&P 500 index will rise or fall
(2) Natural Language Processing (NLP) for assessign if market sentiment is positive or negative

These two models are then combined to generate two trading strategies: Buy & Sell, and Buy & Hold. 


List of programs:

(1) NN.py: Neural Net that loads S&P_train.csv as training data and outputs a trained model NN.pickle. Takes path to S&P_train.csv as argument form command line

(2) trainingSentiment.py: Natural Language Processing that loads posive and negative movie reviews from a directory and outputs a trained NLP model naivebayes1.pickle
Takes a long time to run on a powerful machine.

(3) testingPositiveSentiment.py: Tests the accuracy of the NLP model on 12,000 positve movie reviews. Takes two arguments from command line: the directory where positive movie reviews are and naivebayes1.pickle 
Example: python3 testingNegativeSentiment.py '/home/eliska/Iowa State/Principles of AI/Stock-Picker/MovieTrain/test/pos' 'naivebayes1.pickle'

(4) testingNegativeSentiment.py: Tests the accuracy of the NLP model on 12,000 negative movie reviews. Takes two arguments from command line: the directory where negative movie reviews are and naivebayes1.pickle 
Example: python3 testingNegativeSentiment.py '/home/eliska/Iowa State/Principles of AI/Stock-Picker/MovieTrain/test/neg' 'naivebayes1.pickle'

(5) downloadAndSaveArticles.py: Webscrapes five years worth of daily Wall Street Journal articles and saves them in a directory. Takes one argument from command line: the directory where you want the articles to be saved.


(6) htmlClassify.py: Applies the NLP model (naivebayes1.pickle) to the downloaded articles, classifies each day as posivie or negative, and outputs a csv file wsjSentiment.csv
Can be run from terminal with two arguments: the file path to Articles and naivebayes1.pickle. Example: python3 htmlClassify.py '/home/eliska/Iowa State/Principles of AI/Stock-Picker/Articles' 'naivebayes1.pickle'

(7) TechAndSent.py: Final program that combines the Neural Net and NLP models. It loads S&P_test.csv as input for the Neural Net that is called from the NN.pickle file. It also loads wsjSentiment.csv, which are the results from the NLP model. Then it simulates two trading strategies: Buy&Sell and Buy&Hold. 
In case of the first strategy, a decision to buy is made when either the neural net predicts that the next day price will increase or when the natural language processing model assesses that the market sentiment is positive. If neither condition applies, the model makes a decision to sell. The second strategy works the same way, except for it just holds a position instead of selling when neither condition applies. 


Instructions for TA on how to run the program:
Install dependencies: pip install -r requirements.txt 

Please run TechAndSent.py from the terminal with three arguments as follows: python3 TechAndSent.py "NN.pickle" "S&P_test.csv" "wsjSentiment.csv". 
This script uses the results of the six other programs (trained NN model, trained NLP model, classified Wall Street Journal articles) as input and produces the final product of this project.

tradingplatform-machinelearning's People

Contributors

ekloberdanz avatar

Stargazers

Laeeth Isharc avatar  avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.