2022-04-19 14:35:10 -07:00
|
|
|
namespace QuanTAlib;
|
2022-04-19 22:34:42 -07:00
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
/* <summary>
|
|
|
|
|
Random Bars generator - used for testing, validation and fun
|
|
|
|
|
Returns 'bars' number of candles that follow common market movement.
|
|
|
|
|
volatility defines how 'jumpy' is the series of
|
|
|
|
|
startvalue defines beginning closing price that then guides the rest of series
|
|
|
|
|
|
|
|
|
|
</summary> */
|
2022-04-19 14:35:10 -07:00
|
|
|
|
|
|
|
|
public class RND_Feed : TBars
|
|
|
|
|
{
|
2022-04-19 22:34:42 -07:00
|
|
|
public RND_Feed(int bars, double volatility = 0.05, double startvalue = 100.0)
|
2022-04-19 14:35:10 -07:00
|
|
|
{
|
|
|
|
|
Random rnd = new();
|
|
|
|
|
double c = startvalue;
|
2022-04-19 22:34:42 -07:00
|
|
|
for (int i = 0; i < bars; i++)
|
2022-04-19 14:35:10 -07:00
|
|
|
{
|
|
|
|
|
double o = Math.Round(c + c * (volatility * 0.1 * rnd.NextDouble() - 0.005), 2);
|
|
|
|
|
double h = Math.Round(o + c * volatility * rnd.NextDouble(), 2);
|
|
|
|
|
double l = Math.Round(o - c * volatility * rnd.NextDouble(), 2);
|
|
|
|
|
c = Math.Round(l + (h - l) * rnd.NextDouble(), 2);
|
|
|
|
|
double v = Math.Round(1000 * rnd.NextDouble(), 2);
|
2022-04-19 22:34:42 -07:00
|
|
|
this.Add(DateTime.Today.AddDays(i - bars), o, h, l, c, v);
|
2022-04-19 14:35:10 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|