GBM_Feed fix

This commit is contained in:
Miha Kralj
2022-09-06 12:10:18 -07:00
parent 439044911c
commit c8ec1d1294
2 changed files with 236 additions and 191 deletions
+46 -1
View File
@@ -3,7 +3,52 @@
#r "nuget:QuanTAlib;"
using QuanTAlib;
YAHOO_Feed tqqq = new(30,"TQQQ");
#!csharp
public class GBM1_Feed : TBars
{
static double seed;
readonly double drift, volatility;
public GBM1_Feed(int Bars = 252, double Volatility = 1.0, double Drift = 0.05, double Seed = 100.0) {
seed = Seed;
volatility = Volatility*0.01;
drift = Drift*0.01;
for (int i = 0; i <Bars; i++) {
DateTime Timestamp = DateTime.Today.AddDays(i - Bars);
this.Add(Timestamp);
}
}
public void Add(DateTime timestamp, bool update = false) {
double Open = GBM_value(seed, volatility*volatility, drift);
double Close = GBM_value(Open, volatility, drift);
double OCMax = Math.Max(Open,Close);
double High = (GBM_value(seed, volatility*0.5, 0));
High = (High<OCMax)? 2*OCMax-High : High;
double OCMin = Math.Min(Open,Close);
double Low = (GBM_value(seed, volatility*0.5, 0));
Low = (Low>OCMin)? 2*OCMin-Low : Low;
double Volume = GBM_value(seed*10, volatility*2, Drift:0);
base.Add((timestamp, Open, High, Low, Close, Volume), update);
seed = Close;
}
private static double GBM_value (double Seed, double Volatility, double Drift) {
Random rnd = new((int)(DateTime.UtcNow.Ticks));
double U1 = 1.0-rnd.NextDouble();
double U2 = 1.0-rnd.NextDouble();
double Z = Math.Sqrt(-2.0 * Math.Log(U1)) * Math.Sin(2.0 * Math.PI * U2);
return Seed * Math.Exp( Drift - (Volatility*Volatility*0.5) + Volatility * Z);
}
}
#!csharp
GBM1_Feed tqqq = new(30);
TSeries data = tqqq.Close;
SMA_Series sma = new(data, 5, false);
MED_Series med = new(data, 5);
+190 -190
View File
File diff suppressed because one or more lines are too long