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).
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.
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.