Classification (U.S. stocks by Exchange)

Modified on 2014/06/27 08:38 by Eugene — Categorized as: Community Components


public Stock

public string Symbol; public string Exchange; public string CompanyName;

public Classification

public static void Classification.DeSerialize()

public List<Stock> StockList() public Stock FindSymbol(string symbol) public List<Stock> ByExchange(string exchange)

Parameter Description

symbolA valid U.S. stock symbol to look for the corresponding Stock object
exchangeA U.S. exchange. Possible values are: AMEX, NYSE and NASDAQ


Builds a U.S. stock classification using NASDAQ as the data source. Call DeSerialize to build the classification and to cache the data in an XML file in Wealth-Lab's AppData directory. On the first call, there's a slight delay while classification data is being downloaded from the web service. Subsequent calls are instant provided that the cache exists. If the stored data is older than 90 days, on next call it will be automatically refreshed.

An instance of the Stock class contains the following properties for U.S. stocks: symbol, company name, and exchange. Before calling the FindSymbol method with a stock symbol to return an instance of Stock, call DeSerialize to avoid delays caused by refreshing the data from the internet.

To get all stocks for a particular exchange - which can be AMEX, NASDAQ or NYSE - call ByExchange with the exchange name as the parameter.

Finally, the complete (unsorted) classification of all available stocks is accessible in the StockList property.


Note! Syntax has had a breaking change. Requires Community Components library version 2014.07 or greater.

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using Community.Components; /*** Requires installation of Community.Components Extension from > Extensions ***/

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { ClearDebug(); // Attempts to read classification from cache. Will download and rebuild automatically on absence or obsoleteness (90 days). Classification c = Classification.DeSerialize();

DrawLabel(PricePane, "Total stocks in Classification: " + c.StockList.Count.ToString() + Environment.NewLine); foreach( string ex in c.Exchanges ) { DrawLabel(PricePane, ex + " stocks: " + c.ByExchange(ex).Count.ToString() ); } // Example: retrieving the list of all AMEX stocks List<Stock> lst = c.ByExchange("AMEX"); PrintDebug( "All AMEX stocks:" + Environment.NewLine ); StringBuilder sb = new StringBuilder(); foreach( Stock s in lst ) sb.Append( s.Symbol + "," ); PrintDebug( sb.ToString() ); } } }