module Main where import Data.Time.LocalTime import HQuant.History import HQuant.LoadHistory import HQuant.Technical import HQuant.Studies import Data.List import Data.Maybe import HQuant.Chart nperiods = 10 spy = readHistory "SPY" buydate d (h:hs) = if hdate h == d then Just $ (PDay $hdate h, open h) else Nothing selldate d (h:hs) = if hdate h == d then Just $ ( PDay $ hdate h, close h) else Nothing buyShares shares a b = a + b * shares sellShares shares a b = a + b * shares main = do hs <- spy let hsplot = map (\h -> PlotPoint (hperiod h) (close h)) hs :: [PlotPoint] let smaspy = simpleMovingAverage nperiods hs :: [PlotPoint] print smaspy let start = head hsplot let end = head $ reverse hsplot let match = drop (nperiods-1) hsplot print start print end let buys = reverse $crossesBelow1 smaspy match let sells = reverse $crossesAbove1 smaspy match --let profit = foldPlot (buyShares 100) 0 $ reverse $ drop 1 $ reverse buys --let loss = foldPlot (buyShares 100) 0 sells --print profit --print loss --print $ profit - loss --buyAndHold start end 100 priceChartBuySells ("SMA("++show nperiods++")") (map plotLocalTime match) (map plotLocalTime smaspy) buys sells --renderableToPNGFile (chart (map plotLocalTime match) (map plotLocalTime smaspy)) 640 480 "spysma.png" --renderableToWindow (chart (map plotLocalTime match) (map plotLocalTime smaspy)) 640 480