diff --git a/04 Research Environment/06 Indicators/02 Data Point Indicators/04 Create Indicator Timeseries.html b/04 Research Environment/06 Indicators/02 Data Point Indicators/04 Create Indicator Timeseries.html deleted file mode 100644 index a7df26787e..0000000000 --- a/04 Research Environment/06 Indicators/02 Data Point Indicators/04 Create Indicator Timeseries.html +++ /dev/null @@ -1,120 +0,0 @@ -

You need to subscribe to some market data and create an indicator in order to calculate a timeseries of indicator values. In this example, use a 20-period 2-standard-deviation BollingerBands indicator.

-
-
var bb = new BollingerBands(20, 2);
-
bb = BollingerBands(20, 2)
-
- -

You can create the indicator timeseries with the Indicator helper method or you can manually create the timeseries.

- -

Indicator Helper Method

-

To create an indicator timeseries with the helper method, call the Indicator method.

-
-
// Create a dataframe with a date index, and columns are indicator values.
-var bbIndicator = qb.Indicator(bb, symbol, 50, Resolution.Daily);
-
# Create a dataframe with a date index, and columns are indicator values.
-bb_dataframe = qb.indicator(bb, symbol, 50, Resolution.DAILY)
-
-Historical bollinger band data - - -

Manually Create the Indicator Timeseries

-

Follow these steps to manually create the indicator timeseries:

- -
    -
  1. Get some historical data.
  2. -
    -
    // Request historical trading data with the daily resolution.
    -var history = qb.History(symbol, 70, Resolution.Daily);
    -
    # Request historical trading data with the daily resolution.
    -history = qb.history[TradeBar](symbol, 70, Resolution.DAILY)
    -
    - -
  3. Create a RollingWindow for each attribute of the indicator to hold their values.
  4. -
    -
    // Create a window dictionary to store RollingWindow objects.
    -var window = new Dictionary<string, RollingWindow<decimal>>();
    -// Store the RollingWindow objects, index by key is the property of the indicator.
    -var time = new RollingWindow<DateTime>(50);
    -window["bollingerbands"] = new RollingWindow<decimal>(50);
    -window["lowerband"] = new RollingWindow<decimal>(50);
    -window["middleband"] = new RollingWindow<decimal>(50);
    -window["upperband"] = new RollingWindow<decimal>(50);
    -window["bandwidth"] = new RollingWindow<decimal>(50);
    -window["percentb"] = new RollingWindow<decimal>(50);
    -window["standarddeviation"] = new RollingWindow<decimal>(50);
    -window["price"] = new RollingWindow<decimal>(50);
    -
    -
    # Create a window dictionary to store RollingWindow objects.
    -window = {}
    -# Store the RollingWindow objects, index by key is the property of the indicator.
    -window['time'] = RollingWindow[DateTime](50)
    -window["bollingerbands"] = RollingWindow[float](50)
    -window["lowerband"] = RollingWindow[float](50)
    -window["middleband"] = RollingWindow[float](50)
    -window["upperband"] = RollingWindow[float](50)
    -window["bandwidth"] = RollingWindow[float](50)
    -window["percentb"] = RollingWindow[float](50)
    -window["standarddeviation"] = RollingWindow[float](50)
    -window["price"] = RollingWindow[float](50)
    -
    -
    -
  5. Attach a handler method to the indicator that updates the RollingWindow objects.
  6. -
    -
    // Define an update function to add the indicator values to the RollingWindow object.
    -bb.Updated += (sender, updated) => 
    -{
    -    var indicator = (BollingerBands)sender;
    -    time.Add(updated.EndTime);
    -    window["bollingerbands"].Add(updated);
    -    window["lowerband"].Add(indicator.LowerBand);
    -    window["middleband"].Add(indicator.MiddleBand);
    -    window["upperband"].Add(indicator.UpperBand);
    -    window["bandwidth"].Add(indicator.BandWidth);
    -    window["percentb"].Add(indicator.PercentB);
    -    window["standarddeviation"].Add(indicator.StandardDeviation);
    -    window["price"].Add(indicator.Price);
    -};
    -
    # Define an update function to add the indicator values to the RollingWindow object.
    -def update_bollinger_band_window(sender: object, updated: IndicatorDataPoint) -> None:
    -    indicator = sender
    -    window['time'].add(updated.end_time)
    -    window["bollingerbands"].add(updated.value)
    -    window["lowerband"].add(indicator.lower_band.current.value)
    -    window["middleband"].add(indicator.middle_band.current.value)
    -    window["upperband"].add(indicator.upper_band.current.value)
    -    window["bandwidth"].add(indicator.band_width.current.value)
    -    window["percentb"].add(indicator.percent_b.current.value)
    -    window["standarddeviation"].add(indicator.standard_deviation.current.value)
    -    window["price"].add(indicator.price.current.value)
    -
    -bb.updated += UpdateBollingerBandWindow
    -
    -

    When the indicator receives new data, the preceding handler method adds the new IndicatorDataPoint values into the respective RollingWindow.

    - -
  7. Iterate through the historical market data and update the indicator.
  8. -
    -
    foreach(var bar in history)
    -{
    -    bb.Update(bar.EndTime, bar.Close);
    -}
    -
    for bar in history:
    -    bb.update(bar.end_time, bar.close)
    -
    -
  9. Display the data.
  10. -
    -
    Console.WriteLine($"time,{string.Join(',', window.Select(kvp => kvp.Key))}");
    -foreach (var i in Enumerable.Range(0, 5).Reverse())
    -{
    -    var data = string.Join(", ", window.Select(kvp => Math.Round(kvp.Value[i],6)));
    -    Console.WriteLine($"{time[i]:yyyyMMdd}, {data}");
    -}
    -
    - Historical bollinger band data - -
  11. Populate a DataFrame with the data in the RollingWindow objects.
  12. -
    -
    bb_dataframe = pd.DataFrame(window).set_index('time')
    -
    - Historical bollinger band data -
- diff --git a/04 Research Environment/06 Indicators/02 Data Point Indicators/04 Create Indicator Timeseries.php b/04 Research Environment/06 Indicators/02 Data Point Indicators/04 Create Indicator Timeseries.php new file mode 100644 index 0000000000..bd419e30ad --- /dev/null +++ b/04 Research Environment/06 Indicators/02 Data Point Indicators/04 Create Indicator Timeseries.php @@ -0,0 +1,58 @@ +

You need to subscribe to some market data and create an indicator in order to calculate a timeseries of indicator values. In this example, use a 20-period 2-standard-deviation BollingerBands indicator.

+
+
var bb = new BollingerBands(20, 2);
+
bb = BollingerBands(20, 2)
+
+ +'; + +$setWindowSizeExampleContainer=' +
+
// Set the window.size to the desired timeseries length
+bb.Window.Size=50;
+bb.LowerBand.Window.Size=50;
+bb.MiddleBand.Window.Size=50;
+bb.UpperBand.Window.Size=50;
+bb.BandWidth.Window.Size=50;
+bb.PercentB.Window.Size=50;
+bb.StandardDeviation.Window.Size=50;
+bb.Price.Window.Size=50;
+
# Set the window.size to the desired timeseries length
+bb.window.size=50
+bb.lower_band.window.size=50
+bb.middle_band.window.size=50
+bb.upper_band.window.size=50
+bb.band_width.window.size=50
+bb.percent_b.window.size=50
+bb.standard_deviation.window.size=50
+bb.price.window.size=50
+
'; + +$dataDisplayStep = ' +
  • Display the data.
  • +
    +
    foreach (var i in Enumerable.Range(0, 5).Reverse())
    +{
    +    Console.WriteLine($"{bb[i].EndTime:yyyyMMdd} {bb[i].Value:f4} {bb.LowerBand[i].Value:f4} {bb.MiddleBand[i].Value:f4} {bb.UpperBand[i].Value:f4} {bb.BandWidth[i].Value:f4} {bb.PercentB[i].Value:f4} {bb.StandardDeviation[i].Value:f4} {bb.Price[i].Value:f4}");
    +}
    +
    + Historical bollinger band data + +
  • Populate a DataFrame with the data in the Indicator object.
  • +
    +
    bb_dataframe = pd.DataFrame({
    +        "current": pd.Series({x.end_time: x.value for x in bb}),
    +    "lower_band": pd.Series({x.end_time: x.value for x in bb.lower_band}),
    +    "middle_band": pd.Series({x.end_time: x.value for x in bb.middle_band}),
    +    "upper_band": pd.Series({x.end_time: x.value for x in bb.upper_band}),
    +    "band_width": pd.Series({x.end_time: x.value for x in bb.band_width}),
    +    "percent_b": pd.Series({x.end_time: x.value for x in bb.percent_b}),
    +    "standard_deviation": pd.Series({x.end_time: x.value for x in bb.standard_deviation}),
    +    "price": pd.Series({x.end_time: x.value for x in bb.price})
    +}).sort_index()
    +
    + Historical bollinger band data \ No newline at end of file diff --git a/04 Research Environment/06 Indicators/03 Bar Indicators/04 Create Indicator Timeseries.html b/04 Research Environment/06 Indicators/03 Bar Indicators/04 Create Indicator Timeseries.html deleted file mode 100644 index 82649f04d6..0000000000 --- a/04 Research Environment/06 Indicators/03 Bar Indicators/04 Create Indicator Timeseries.html +++ /dev/null @@ -1,96 +0,0 @@ -

    You need to subscribe to some market data and create an indicator in order to calculate a timeseries of indicator values. In this example, use a 20-period AverageTrueRange indicator.

    -
    -
    var atr = new AverageTrueRange(20);
    -
    atr = AverageTrueRange(20)
    -
    - -

    You can create the indicator timeseries with the Indicator helper method or you can manually create the timeseries.

    - -

    Indicator Helper Method

    -

    To create an indicator timeseries with the helper method, call the Indicator method.

    -
    -
    // Create a dataframe with a date index, and columns are ATR indicator values. 
    -var atrIndicator = qb.Indicator(atr, symbol, 50, Resolution.Daily);
    -
    # Create a dataframe with a date index, and columns are ATR indicator values.
    -atr_dataframe = qb.indicator(atr, symbol, 50, Resolution.DAILY)
    -
    -Historical average true range data - - - -

    Manually Create the Indicator Timeseries

    -

    Follow these steps to manually create the indicator timeseries:

    - -
      -
    1. Get some historical data.
    2. -
      -
      // Request historical trading data with the daily resolution.
      -var history = qb.History(symbol, 70, Resolution.Daily);
      -
      # Request historical trading data with the daily resolution.
      -history = qb.history[TradeBar](symbol, 70, Resolution.DAILY)
      -
      -
    3. Create a RollingWindow for each attribute of the indicator to hold their values.
    4. -
      -
      // Create a window dictionary to store RollingWindow objects.
      -var window = new Dictionary<string, RollingWindow<decimal>>();
      -// Store the RollingWindow objects, index by key is the property of the indicator.
      -var time = new RollingWindow<DateTime>(50);
      -window["averagetruerange"] = new RollingWindow<decimal>(50);
      -window["truerange"] = new RollingWindow<decimal>(50);
      -
      -
      # Create a window dictionary to store RollingWindow objects.
      -window = {}
      -# Store the RollingWindow objects, index by key is the property of the indicator.
      -window['time'] = RollingWindow[DateTime](50)
      -window['averagetruerange'] = RollingWindow[float](50)
      -window["truerange"] = RollingWindow[float](50)
      -
      -
      -
    5. Attach a handler method to the indicator that updates the RollingWindow objects.
    6. -
      -
      // Define an update function to add the indicator values to the RollingWindow object.
      -atr.Updated += (sender, updated) => 
      -{
      -    var indicator = (AverageTrueRange)sender;
      -    time.Add(updated.EndTime);
      -    window["averagetruerange"].Add(updated);
      -    window["truerange"].Add(indicator.TrueRange);
      -};
      -
      # Define an update function to add the indicator values to the RollingWindow object.
      -def update_average_true_range_window(sender: object, updated: IndicatorDataPoint) -> None:
      -    indicator = sender
      -    window['time'].add(updated.end_time)
      -    window["averagetruerange"].add(updated.value)
      -    window["truerange"].add(indicator.true_range.current.value)
      -
      -atr.updated += UpdateAverageTrueRangeWindow
      -
      -

      When the indicator receives new data, the preceding handler method adds the new IndicatorDataPoint values into the respective RollingWindow.

      - -
    7. Iterate through the historical market data and update the indicator.
    8. -
      -
      foreach(var bar in history){
      -    // Update the indicators with the whole bar.
      -    atr.Update(bar);
      -}
      -
      for bar in history:
      -    atr.update(bar)
      -
      -
    9. Display the data.
    10. -
      -
      Console.WriteLine($"time,{string.Join(',', window.Select(kvp => kvp.Key))}");
      -foreach (var i in Enumerable.Range(0, 5).Reverse())
      -{
      -    var data = string.Join(", ", window.Select(kvp => Math.Round(kvp.Value[i],6)));
      -    Console.WriteLine($"{time[i]:yyyyMMdd}, {data}");
      -}
      -
      - Historical average true range data - -
    11. Populate a DataFrame with the data in the RollingWindow objects.
    12. -
      -
      atr_dataframe = pd.DataFrame(window).set_index('time')
      -
      - Historical average true range data -
    - diff --git a/04 Research Environment/06 Indicators/03 Bar Indicators/04 Create Indicator Timeseries.php b/04 Research Environment/06 Indicators/03 Bar Indicators/04 Create Indicator Timeseries.php new file mode 100644 index 0000000000..a74db7f1d9 --- /dev/null +++ b/04 Research Environment/06 Indicators/03 Bar Indicators/04 Create Indicator Timeseries.php @@ -0,0 +1,40 @@ +

    You need to subscribe to some market data and create an indicator in order to calculate a timeseries of indicator values. In this example, use a 20-period AverageTrueRange indicator.

    +
    +
    var atr = new AverageTrueRange(20);
    +
    atr = AverageTrueRange(20)
    +
    + +'; + +$setWindowSizeExampleContainer=' +
    +
    // Set the window.size to the desired timeseries length
    +atr.Window.Size = 50;
    +atr.TrueRange.Window.Size = 50;
    +
    # Set the window.size to the desired timeseries length
    +atr.window.size = 50
    +atr.true_range.window.size = 50
    +
    '; + +$dataDisplayStep = ' +
  • Display the data.
  • +
    +
    foreach (var i in Enumerable.Range(0, 5).Reverse())
    +{
    +    Console.WriteLine($"{atr[i].EndTime:yyyyMMdd} {atr[i].Value:f4} {atr.TrueRange[i].Value:f4}");
    +}
    +
    + Historical average true range data + +
  • Populate a DataFrame with the data in the Indicator object.
  • +
    +
    atr_dataframe = pd.DataFrame({
    +    "current": pd.Series({x.end_time: x.value for x in atr}), 
    +    "truerange": pd.Series({x.end_time: x.value for x in atr.true_range})
    +}).sort_index()
    +
    + Historical average true range data'; +include(DOCS_RESOURCES."/indicators/create-indicator-timeseries.php"); +?> \ No newline at end of file diff --git a/04 Research Environment/06 Indicators/04 Trade Bar Indicators/04 Create Indicator Timeseries.html b/04 Research Environment/06 Indicators/04 Trade Bar Indicators/04 Create Indicator Timeseries.html deleted file mode 100644 index bba40d46af..0000000000 --- a/04 Research Environment/06 Indicators/04 Trade Bar Indicators/04 Create Indicator Timeseries.html +++ /dev/null @@ -1,91 +0,0 @@ -

    You need to subscribe to some market data and create an indicator in order to calculate a timeseries of indicator values. In this example, use a 20-period VolumeWeightedAveragePriceIndicator indicator.

    -
    -
    var vwap = new VolumeWeightedAveragePriceIndicator(20);
    -
    vwap = VolumeWeightedAveragePriceIndicator(20)
    -
    - -

    You can create the indicator timeseries with the Indicator helper method or you can manually create the timeseries.

    - -

    Indicator Helper Method

    -

    To create an indicator timeseries with the helper method, call the Indicator method.

    -
    -
    // Create a dataframe with a date index, and columns are indicator values.
    -var vwapIndicator = qb.Indicator(vwap, symbol, 50, Resolution.Daily);
    -
    # Create a dataframe with a date index, and columns are indicator values.
    -vwap_dataframe = qb.indicator(vwap, symbol, 50, Resolution.DAILY)
    -
    -Historical VWAP data - - -

    Manually Create the Indicator Timeseries

    - -

    Follow these steps to create an indicator timeseries:

    - -
      -
    1. Get some historical data.
    2. -
      -
      // Request historical trading data with the daily resolution.
      -var history = qb.History(symbol, 70, Resolution.Daily);
      -
      # Request historical trading data with the daily resolution.
      -history = qb.history[TradeBar](symbol, 70, Resolution.DAILY)
      -
      -
    3. Create a RollingWindow for each attribute of the indicator to hold their values.
    4. -
      -
      // Create a window dictionary to store RollingWindow objects.
      -var window = new Dictionary<string, RollingWindow<decimal>>();
      -// Store the RollingWindow objects, index by key is the property of the indicator.
      -var time = new RollingWindow<DateTime>(50);
      -window["volumeweightedaveragepriceindicator"] = new RollingWindow<decimal>(50);
      -
      -
      # Create a window dictionary to store RollingWindow objects.
      -window = {}
      -# Store the RollingWindow objects, index by key is the property of the indicator.
      -window['time'] = RollingWindow[DateTime](50)
      -window['volumeweightedaveragepriceindicator'] = RollingWindow[float](50)
      -
      -
      -
    5. Attach a handler method to the indicator that updates the RollingWindow objects.
    6. -
      -
      // Define an update function to add the indicator values to the RollingWindow object.
      -vwap.Updated += (sender, updated) => 
      -{
      -    time.Add(updated.EndTime);
      -    window["volumeweightedaveragepriceindicator"].Add(updated);
      -};
      -
      # Define an update function to add the indicator values to the RollingWindow object.
      -def update_vwap_window(sender: object, updated: IndicatorDataPoint) -> None:
      -    window['time'].add(updated.end_time)
      -    window["volumeweightedaveragepriceindicator"].add(updated.value)
      -
      -vwap.updated += UpdateVWAPWindow
      -
      -

      When the indicator receives new data, the preceding handler method adds the new IndicatorDataPoint values into the respective RollingWindow.

      - - -
    7. Iterate through the historical market data and update the indicator.
    8. -
      -
      foreach(var bar in history){
      -    // Update the indicators with the whole TradeBar.
      -    vwap.Update(bar);
      -}
      -
      for bar in history:
      -    vwap.update(bar)
      -
      -
    9. Display the data.
    10. -
      -
      Console.WriteLine($"time,{string.Join(',', window.Select(kvp => kvp.Key))}");
      -foreach (var i in Enumerable.Range(0, 5).Reverse())
      -{
      -    var data = string.Join(", ", window.Select(kvp => Math.Round(kvp.Value[i],6)));
      -    Console.WriteLine($"{time[i]:yyyyMMdd}, {data}");
      -}
      -
      - Historical VWAP data - -
    11. Populate a DataFrame with the data in the RollingWindow objects.
    12. -
      -
      vwap_dataframe = pd.DataFrame(window).set_index('time')
      -
      - Historical VWAP data -
    - diff --git a/04 Research Environment/06 Indicators/04 Trade Bar Indicators/04 Create Indicator Timeseries.php b/04 Research Environment/06 Indicators/04 Trade Bar Indicators/04 Create Indicator Timeseries.php new file mode 100644 index 0000000000..cc4e555263 --- /dev/null +++ b/04 Research Environment/06 Indicators/04 Trade Bar Indicators/04 Create Indicator Timeseries.php @@ -0,0 +1,37 @@ +

    You need to subscribe to some market data and create an indicator in order to calculate a timeseries of indicator values. In this example, use a 20-period VolumeWeightedAveragePriceIndicator indicator.

    +
    +
    var vwap = new VolumeWeightedAveragePriceIndicator(20);
    +
    vwap = VolumeWeightedAveragePriceIndicator(20)
    +
    + +'; + +$setWindowSizeExampleContainer=' +
    +
    // Set the window.size to the desired timeseries length
    +vwap.Window.Size = 50;
    +
    # Set the window.size to the desired timeseries length
    +vwap.window.size = 50
    +
    '; + +$dataDisplayStep = ' +
  • Display the data.
  • +
    +
    foreach (var i in Enumerable.Range(0, 5).Reverse())
    +{
    +    Console.WriteLine($"{vwap[i].EndTime:yyyyMMdd} {vwap[i].Value:f4}");
    +}
    +
    + Historical VWAP data + +
  • Populate a DataFrame with the data in the Indicator object.
  • +
    +
    vwap_dataframe = pd.DataFrame({
    +    "current": pd.Series({x.end_time: x.value for x in vwap}))
    +}).sort_index()
    +
    + Historical VWAP data'; +include(DOCS_RESOURCES."/indicators/create-indicator-timeseries.php"); +?> \ No newline at end of file diff --git a/Resources/indicators/create-indicator-timeseries.php b/Resources/indicators/create-indicator-timeseries.php new file mode 100644 index 0000000000..1a2ca637db --- /dev/null +++ b/Resources/indicators/create-indicator-timeseries.php @@ -0,0 +1,38 @@ +

    You can create the indicator timeseries with the Indicator helper method or you can manually create the timeseries.

    + +

    Indicator Helper Method

    +

    To create an indicator timeseries with the helper method, call the Indicator method.

    +
    +
    // Create a dataframe with a date index, and columns are indicator values.
    +var Indicator = qb.Indicator(, symbol, 50, Resolution.Daily);
    +
    # Create a dataframe with a date index, and columns are indicator values.
    +_dataframe = qb.indicator(, symbol, 50, Resolution.DAILY)
    +
    + + +

    Manually Create the Indicator Timeseries

    +

    Follow these steps to manually create the indicator timeseries:

    + +
      +
    1. Get some historical data.
    2. +
      +
      // Request historical trading data with the daily resolution.
      +var history = qb.History(symbol, 70, Resolution.Daily);
      +
      # Request historical trading data with the daily resolution.
      +history = qb.history[TradeBar](symbol, 70, Resolution.DAILY)
      +
      + +
    3. Set the indicator Window.Sizewindow.size for each attribute of the indicator to hold their values.
    4. + + +
    5. Iterate through the historical market data and update the indicator.
    6. +
      +
      foreach (var bar in history)
      +{
      +    .Update();
      +}
      +
      for bar in history:
      +    .update()
      +
      + +
    \ No newline at end of file