DataSeries.ToList

Modified on 2016/12/28 11:38 by Eugene — Categorized as: Community Components

Syntax

public static List<double> ToList(this DataSeries ds)

Parameter Description

dsDataSeries object

Description

LINQ provides a convenient and terse way to write SQL-like queries, allowing to filter, aggregate, group, sort and so on. While Wealth-Lab's DataSeries doesn't support LINQ natively, Community.Components users can employ the so called extension method .ToList() to run LINQ queries on DataSeries.

There also is a companion method ToArray with identical syntax.

Example

The following quick example shows the average price of a DataSeries by virtue of LINQ's Average function.

Note: Add reference to System.Core before using the sample code:

Example:

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using System.Linq;
/*** Requires installation of Community.Components Extension from www.wealth-lab.com > Extensions, 2012.10 or later***/

namespace WealthLab { public class MyStrategy : WealthScript { protected override void Execute() { var ds2List = Bars.Close.ToArray(); var dsAverage = ds2List.Average( i => i ); PrintDebug(dsAverage); } } }