Click or drag to resize

Return

Return computes arithmetic rate of return. LogReturn computes logarithmic or continuously compounded rate of return.

Return 001

Return 002

where Return 003 is the initial value for the given period and Return 004 is the final value for the given period.

Chart Example

Return 005
 

Implementation and Usage

To implement rates of return in your strategy you can use of the following constructors:

Return- creates Return indicator with default period equal to 1.

Return(Int32)- creates Return indicator with point window and allows to set window length.

Return(TimeSpan) - creates Return indicator with time window and allows to set time window length.

LogReturn- creates LogReturn indicator with default period equal to 1.

LogReturn(Int32)- creates LogReturn indicator with point window and allows to set window length.

LogReturn(TimeSpan) - creates LogReturn indicator with time window and allows to set time window length.

The values of each of these indicators are updated by simple prototype of method Add():

Add(Double)

Add(Double, DateTime)

Use Result property to get the current value.

Example

This example demonstrates LogReturn implementation in a strategy:

C#
 1public partial class InstrumentExecutor : InstrumentExecutorBase
 2{
 3-    #region LocalVariables
 4 
 5     //LogReturn indicator
 6     LogReturn logReturn;
 7     //LogReturn chart line
 8     Line logReturnLine;
 9 
10     #endregion
11
12-    #region Events
13     public override void OnInit()
14     {
15         //init logReturn indicator
16         logReturn = new LogReturn(10);
17         logReturnLine = Charting.CreateLine("LogReturn", "", Symbol, Pens.Black, LineStyle.Line, Charting.PriceChart, 2);
18     }
19 
20     public override void OnBarClose()
21     {
22         logReturn.Add(CurrentPrice);
23         //LogReturn chart
24         logReturnLine.Draw(CurrentTime, logReturn.Result);
25     }
26     #endregion
27}