Gain and Drawdown

Modified on 2015/03/27 11:51 by Eugene — Categorized as: Community Components

Syntax


public class GainAndDrawdown(WealthScript ws, Bars bars, DateTime start, DateTime end, string dividenditemstring)

Parameter Description

wsA WealthScript instance (pass this)
barsBars from a secondary series must be synchronized
startStarting date
endEnding date
dividenditemstringPer share dividend fundamental item used to calculate total return

Description

This class helps chart the total return (% gain/loss plus dividends, % peak gain, % gain after DD Low) and % drawdown (max DD%) of multiple symbols over some duration.

Example

Image

Code below illustrates the class usage. The script demonstrates comparing the clicked symbol with the "SPY" benchmark:


using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using Community.Components;

namespace WealthLab.Strategies { public class PerformanceDataDemo : WealthScript { protected override void Execute() { /* Edit string according to your dividend source */ string dividenditemstring = "Dividend (Yahoo! Finance)"; GainAndDrawdown pd = new GainAndDrawdown(this, Bars, Date[0], Date[Bars.Count - 1], dividenditemstring); pd.DisplayData(PricePane); ChartPane ddPane = CreatePane(40, true, true); ChartPane gainPane = CreatePane(60, true, true); PlotSeries(gainPane, pd.GainSeries, Color.Green, LineStyle.Histogram, 1); PlotSeries(gainPane, pd.TotalReturnSeries, Color.Blue, LineStyle.Solid, 2); PlotSeries(ddPane, pd.DrawdownSeries, Color.Red, LineStyle.Histogram, 1); // Compare to a benchmark. Make sure to use sync'd Bars Bars bmbars = GetExternalSymbol("SPY", true); GainAndDrawdown bm = new GainAndDrawdown(this, bmbars, Date[0], Date[bmbars.Count - 1], dividenditemstring); PlotSeries(gainPane, bm.TotalReturnSeries, Color.Black, LineStyle.Solid, 2); PlotSeries(ddPane, bm.DrawdownSeries, Color.Black, LineStyle.Solid, 2); } } }