Skip to content

lukasotocerny/Neural-Networks-Yahoo-Finance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Haskell implementation of Neural Networks

Introduction

This project aims to analyze the US Stock Market through a simple single-hidden layer neural network, using the backpropagation algorithm. The data are fetched from Yahoo API, using YQL queries. There are 3 modules in this repository, each is described bellow.

FrontEnd.hs

The `FrontEnd.hs` file is used for user interaction and serves as the combining element of `Parser` and `NeuralNet` module. It has couple of methods.
data Quote = Quote {
    symbol :: String,
    date :: Int,
    open :: Double,
    high :: Double,
    low :: Double,
    close :: Double,
    volume :: Int,
    adj_close :: Double
    } deriving (Show, Generic)

The Quote data constructor corresponds to the information received in JSON format from YQL API. Module Data.Aeson converts JSON data into this data type generically through the decode command.

stockToData :: Int -> [Quote] -> [([Double],Double)]

This method generates n-dimensional inputs with the target value, in the form (input vector, target).

NeuralNet.hs

The data constructors are not exported, therefore they serve as an abstract data type for other modules. ```haskell construct :: [Int] -> Network ``` Construct a network with dimensions of `[n1,n2,n3,...,ni]`, where `n1` is input layer, `ni` output layer and other hidden layers. Weighs are randomly initialized in the range of [0,1].
train :: Network -> Maybe [([Double],Double)] -> Double -> Int -> Network

Trains the network with the backpropagation algorithm given Maybe [([Double],Double)] as training set. Maybe is used for simplicity when used in FrontEnd.hs due to the conversion from JSON. Takes learning rate and number of epochs as arguments as well.

output :: Network -> [Double] -> Double

Produces an output given an input vector.

predict :: Network -> [Double] -> Int -> [Double]

Predicts the evolution of stock for n days given an initial input.

mistake :: Network -> Maybe [([Double],Double)] -> Double

Calculates the square error summed over all the training set.

Parser.hs

Parses the JSON results from the YQL queries.
writeStockData :: String -> String -> String -> IO ()

Writes stock data in a JSON format given the company, start and end date as arguments. E.g. writeStockData "YHOO" "2016-01-01" "2016-12-14"

getNDaysForw :: String -> String -> Int -> IO [Double]
getNDaysBack :: String -> String -> Int -> IO [Double]

Returns the opening prices for the following/previous n days.

About

Haskell implementation of Neural Networks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published