public void BuildFeaturesToStdOut() { //Test to see if the connection to the python interpreter is working correctly, not so much the accuracy of the results string[] labels = new string[] { "SMA_20", "ATR_3", "VOLAT_12", "VOL_12", "BB" }; string[] commands = new string[] { "whole", @"C:\ForexData\TestData\EURUSD_m60_Share_live_test.bin", "200", "SMA(20,close);ATR(3,close,high,low);VOLATILITY_LOG_MA(12,high,low);VOLUME_LOG_MA(12,volume);BBANDS(20,1.8,1,close);" }; string[] results = pb.RunScript("\"G:\\My Drive\\C Sharp Apps\\LinuxLiveTrader\\LinuxLiveTrader\\bin\\Debug\\build_features.py\"", commands); PreCalculatedFeatures pf = new PreCalculatedFeatures(); pf.FillFromCsv(results, labels); Assert.IsTrue(EqualityChecks.DoubleNearlyEqual((double)pf.Data[new DateTime(2019, 03, 14, 11, 00, 00)]["ATR_3"], 0.001917, 0.001), "Did not recieve correct information back from python"); }
static void CalculatePythonData(PythonBridge pb, string assetName, int timeframe, int barCount) { //do nothing if this timeframe is not listed as required if (!pythonCalcTimeframes.Contains(timeframe)) { return; } //get the relevant bars (whole lookback period) but not the zero index bar as this is incomplete Bar[] bars = priceData[assetName][timeframe].Skip(1).ToArray(); //save a temporary binary file to disk for python to read (faster than sending all the data via the stdout string tempData = @"C:\ForexData\ShareData\" + assetName + "_m" + timeframe + "_Share_live.bin"; DataBuilder.DatasetToBinary(tempData, bars, DataFeedType.Ask); //Create the python bridge and run the calculation commands string[] commands = new string[] { "whole", tempData, barCount.ToString(), pythonCalcCommands }; string[] results = pb.RunScript("build_features.py", commands); PreCalculatedFeatures pcFeatures = new PreCalculatedFeatures(); try { pcFeatures.FillFromCsv(results, pythonCalcLabels); } catch (Exception e) { DisplayError(e.Message); } //add this data to the asset if it doesnt exist if (!assetDetails[assetName].Data.ContainsKey(timeframe)) { assetDetails[assetName].Data.Add(timeframe, pcFeatures); } else { //remove the oldest one to save on memory creep assetDetails[assetName].Data[timeframe].RemoveOldest(); //we just add the data to the current set of data assetDetails[assetName].Data[timeframe].Merge(pcFeatures); } }