Overall Statistics
namespace QuantConnect.Algorithm.Data.Custom

open System
open System.Net
open System.Diagnostics
open QuantConnect
open QuantConnect.Data
open QuantConnect.Data.Market

type YFinance() = 
    inherit BaseData()
    member val Open = 0m with get,set 
    member val High = 0m with get,set 
    member val Low = 0m with get,set 
    member val Close = 0m with get,set 
    member val AdjClose = 0m with get,set
    member val Volume = 0 |> int64 with get,set 

    override this.GetSource(config: SubscriptionDataConfig, date:DateTime, isLiveMode:bool) =
        //Trace.WriteLine <| sprintf "%O" date
        this.Symbol <- config.Symbol
        let fromDate = sprintf "&a=%i&b=%i&c=%i" (date.Month - 1) date.Day date.Year
        let toDate = sprintf "&d=%i&e=%i&f=%i" (date.Month - 1) date.Day date.Year
        let url = sprintf "http://real-chart.finance.yahoo.com/table.csv?s=%s%s%s&ignore=.csv&g=d" config.Symbol.Value fromDate toDate
        //Trace.WriteLine <| sprintf "%s" url
        new SubscriptionDataSource(url, SubscriptionTransportMedium.RemoteFile)

    override this.Reader(config:SubscriptionDataConfig, line:string, date:DateTime, isLiveMode:bool) = 
        let retval = 
                let data = line.Split(',')
                new YFinance(
                    Time = DateTime.ParseExact(data.[0],"yyyy-MM-dd",null),
                    Open = Convert.ToDecimal(data.[1]),
                    High = Convert.ToDecimal(data.[2]),
                    Low = Convert.ToDecimal(data.[3]),
                    Close = Convert.ToDecimal(data.[4]),
                    Volume = Convert.ToInt64(data.[5]),
                    AdjClose = Convert.ToDecimal(data.[6]),
                    Value = Convert.ToDecimal(data.[4])
            | ex -> new YFinance()

        //f# not smart enough to get base-class type
        //" does not have the correct type to override any given virtual method" error throw if not cast to BaseData type
        retval :> BaseData
open QuantConnect.Algorithm
type FSharpCustomData() = 
    inherit QCAlgorithm()
    let ticker = "2012.HK"
    override this.Initialize() =

    member this.OnData(data : YFinance) =