私の名前はイアンです。私は現在、www.tryfsharp.org の「株価の分析」チュートリアルに取り組んでいます。適切なライブラリを使用して、Visual Studio 2012 で Web コンテンツを再現しようとしています。
MathNET ライブラリの "descriptivestatistics" 関数が機能しない理由がわかりません。以下のスニペット。
返されたエラー:
エラー FS0041: メソッド 'DescriptiveStatistics' に一致するオーバーロードがありません。利用可能なオーバーロードを以下に示します (または [エラー リスト] ウィンドウに表示します)。可能なオーバーロード: 'DescriptiveStatistics(data: Collections.Generic.IEnumerable) : unit'。型制約の不一致。タイプ CsvProvider<...> はタイプ Collections.Generic.IEnumerable と互換性がありません タイプ 'CsvProvider<...>' はタイプ 'Collections.Generic.IEnumerable' と互換性がありません。考えられるオーバーロード: 'DescriptiveStatistics(data: Collections.Generic.IEnumerable>) : unit'. 型制約の不一致。タイプ CsvProvider<...> は、タイプ Collections.Generic.IEnumerable> と互換性がありません タイプ「CsvProvider<...>」は、タイプ「コレクション」と互換性がありません。
特定のコードと別の考えられる手がかり:
//統計を取得
let stats = DescriptiveStatistics(msftClosesUsd)
// std を計算します。開発者
standardDeviation [ for r in msftData.Data -> float r.Close ] //タイプを一致させるために r.Close に 'float' を追加する必要がありました
注: descriptiveStatistics はコードの最後にあり、standardDeviation はその中間にあります。どんな助けでも大歓迎です!
// *****************************************************************
// ********************Analyzing Stock Prices***********************
// *****************************************************************
// URL: http://www.tryfsharp.org/Learn/financial-computing#analyzing-stock-prices
#r @"...\FSharp.Data.1.1.5\lib\net40\FSharp.Data.dll"
#load @"...\FSharp.Charting.0.82\FSharp.Charting.fsx"
open FSharp.Data
open FSharp.Charting
open System
// Provides a strongly typed view of the file
type Stocks = CsvProvider<"C:\...\Documents\F#\MSFT.csv">
// Get the stock prices from yahoo on MSFT stock
[<Literal>]
let msftUrl = "http://ichart.finance.yahoo.com/table.csv?s=MSFT"
let msftData = Stocks.Load(msftUrl)
// **************** Calculating Standard Deviation *****************
let standardDeviation prices =
let count = Seq.length prices
let avg = Seq.average prices
let squares = [ for p in prices -> (p - avg) * (p - avg) ]
sqrt ((Seq.sum squares) / (float count)) // Convert count to float to be able to divide into Seq.sum squares
//"F# does not insert any numberical conversions implicitly" - website
standardDeviation [ for r in msftData.Data -> float r.Close ] //had to add 'float' to r.Close to match type
// **************** Introducing Units of Measure *****************
type [<Measure>] USD
type [<Measure>] EUR
let msftClosesUsd = [ for r in msftData.Data -> float r.Close * 1.0<USD> ] //had to change r.close to float to get this to work
let msft = msftClosesUsd
// Average price in USD
let avg = msftClosesUsd |> Seq.average
// Convert EUR to USD
let euroToUsd eur = eur * 1.30<USD/EUR> // As of 2013-06-29
// Is the average price greater than 25 Euros?
let limit = 25.0<EUR>
if avg > (euroToUsd limit) then printfn("Greater!") // 1.3*25 = 32.5. Type 'avg' to see average. Mine was 29.4802.
let standardDeviationUnits (prices:seq<float<USD>>) = //"Could annotate the argument with seq<float<'u>> allowing for generic units." -URL
let count = Seq.length prices
let avg = Seq.average prices
let squares = [ for p in prices -> (p - avg) * (p - avg) ]
sqrt ((Seq.sum squares) / (float count))
// Unquote for calc below.
//standardDeviationUnits msftClosesUsd
// Get Math.NET Numerics Library Here: http://numerics.mathdotnet.com/
// Install and continue.
#r @"...\MathNet.Numerics.2.5.0\lib\net40\MathNet.Numerics.dll"
open MathNet.Numerics.Statistics
//get Stats
let stats = DescriptiveStatistics(msftClosesUsd)