I wrote this script to plot the historical financial data:
open FSharp.Data
#load "C:\Users\Nick\Documents\Visual Studio 2013\Projects\TryFsharp\packages\FSharp.Charting.0.90.9\FSharp.Charting.fsx"
open FSharp.Charting
open System
let plotprice nasdaqcode =
let url = "http://ichart.finance.yahoo.com/table.csv?s="+nasdaqcode
let company = CsvFile.Load(url)
let companyPrices = [ for r in company.Rows -> r.GetColumn "Date", r.GetColumn "Close" ]
(companyPrices
|> List.sort
|> Chart.Line).WithTitle(nasdaqcode, InsideArea=false)
plotprice "MSFT"
plotprice "ORCL"
plotprice "GOOG"
plotprice "NTES"
This works well.
Question:
Some of the data starts from the year 1986, some from 2000. I would like to plot the data from year 2000 to 2015. How to select this time period?
Is it possible to display the time when the mouse hovers over the chart?
If you are accessing Yahoo data, then it's better to use the
CsvProvider
rather than usingCsvFile
from F# Data. You can find more about the type provider here. Sadly, the naming in the standard F# Data library and on TryFSharp.org is different, so this is a bit confusing.The CSV type provider will automatically infer the types:
I'm not sure if the F# Charting library has a way for showing the price based on mouse pointer location - it is based on standard .NET Windows Forms charting controls, so you could have a look at the documentation for the underlying library.