Syntax
public UpcomingSplit
public string Payable;
public DateTime ExDate;
public string Company;
public string Symbol;
public string Ratio;
public string AnnouncementDate;
public enum SplitProvider { Fidelity, Yahoo, Briefing, Nasdaq, NotDefined, All }
public UpcomingSplitDownloader
public UpcomingSplitDownloader(SplitProvider provider)
public static void UpcomingSplitDownloader.DeSerialize()
public List<UpcomingSplit> Splits
public UpcomingSplit FindSymbol(string symbol)
public UpcomingSplit FindSymbol(string symbol, SplitProvider provider
public bool IsStockSplit(string symbol, DateTime dt)
public bool IsStockSplit(string symbol, DateTime dt, SplitProvider provider
public double SplitFactor(string symbol, DateTime dt)
public double SplitFactor(string symbol, DateTime dt, SplitProvider provider
Parameter Description
symbol | A valid U.S. stock symbol to look for the corresponding UpcomingSplit object |
dt | Date used to determine if a stock splits on given date |
provider | (Optional) Choice of source for upcoming split data: query All the 4 providers, query Fidelity / Yahoo / Briefing / Nasdaq separately |
Description
Builds a database of U.S. stocks that are about to split in the upcoming month using
Fidelity,
Yahoo as the primary data source or
Nasdaq and
Briefing as backup data sources (should Yahoo fail for whatever reason). To download and to cache the data in an XML file in Wealth-Lab's AppData directory,
DeSerialize. On the first call, there's a slight delay while the data is being downloaded from the web service. Subsequent calls are instant provided that the cache exists. If the stored data is older than 1 day, on next call it will be automatically refreshed.
Since v2020.09 it's possible to extend the number of collected splits by quering all the 4 providers, or have a choice to target specific source (Fidelity, Yahoo, Briefing or Nasdaq). If this is not specified (default behavior), the class will start with Fidelity and fall back to the other sources on failure.
An instance of the
UpcomingSplit class contains the following properties for U.S. stocks: payable, ex-date, company, symbol, ratio and announcement date. Before calling the
FindSymbol method with a stock
symbol to return an instance of
UpcomingSplit, call
DeSerialize to avoid delays caused by refreshing the data from the internet.
To determine if stock splits on given date, call
IsStockSplit. To determine the split factor for a given stock on given date, use
SplitFactor.
Finally, the complete classification of all stocks about to split is accessible in the
Splits property.
Example
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using Community.Components; /*** Requires installation of Community.Components Extension from www.wealth-lab.com > Extensions ***/
namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
protected override void Execute()
{
ClearDebug();
// Attempts to read splits from cache. Will download and rebuild automatically on absence or obsoleteness (every day)
//var c = new UpcomingSplitDownloader(SplitProvider.All);
//var c = new UpcomingSplitDownloader();
var c = new UpcomingSplitDownloader(SplitProvider.Fidelity);
c = UpcomingSplitDownloader.DeSerialize();
DrawLabel(PricePane, "Upcoming splits: " + c.Splits.Count.ToString() + Environment.NewLine);
ClearDebug();
PrintDebug( "Upcoming splits: " + c.Splits.Count + "\n" );
foreach( var s in c.Splits ) {
PrintDebug( s );
}
bool split = c.IsStockSplit( Bars.Symbol, Bars.Date[Bars.Count-1] );
DrawLabel(PricePane, "Current symbol " + (split ? "splits today!" : "doesn't split today") + Environment.NewLine);
//TEST: Get ratio of AAPL 2014/06/09 split, if still present in cache
double ratio = c.SplitFactor( "AAPL", new DateTime(2014,06,09) );
DrawLabel(PricePane, "AAPL 2014/06/09 split factor: " + Bars.FormatValue(ratio).ToString() + Environment.NewLine);
}
}
}