CGC_Codes

neuralnetwork strategy

Jun 7th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.62 KB | None | 0 0
  1. using QuantSys.Analytics.Timeseries.Indicators.Oscillators;
  2. using QuantSys.DataStructures;
  3. using QuantSys.MachineLearning.NeuralNetwork;
  4. using QuantSys.MarketData;
  5. using QuantSys.TradeEngine.Simulation.Account;
  6.  
  7. namespace QuantSys.TradeEngine.Strategy
  8. {
  9.     public class NeuralNetworkStrategy : AbstractStrategy
  10.     {
  11.  
  12.         public Stage1NeuralNetwork NeuralNetwork { get; set; }
  13.  
  14.         private MovingQueue<double> dataList;
  15.         private double prevIndicatorTick = double.NaN;
  16.  
  17.         public NeuralNetworkStrategy(int window)
  18.         {
  19.             dataList = new MovingQueue<double>(window);
  20.             AttachIndicator("IND", new AC(60));
  21.         }
  22.  
  23.         public override void OnTick(params Tick[] t)
  24.         {
  25.             foreach (var indicator in indicatorList)
  26.             {
  27.                 indicator.Value.HandleNextTick(t[0]);
  28.             }
  29.  
  30.             if (!indicatorList["IND"][0].Equals(double.NaN))
  31.                 dataList.Enqueue(indicatorList["IND"][0]);
  32.  
  33.             if (dataList.Count == dataList.Capacity)
  34.             {
  35.                 double nextIndicatorTick = NeuralNetwork.PredictNext(dataList.ToArray());
  36.  
  37.                
  38.                 if (nextIndicatorTick > 0 && nextIndicatorTick > prevIndicatorTick && prevIndicatorTick < 0)
  39.                 {
  40.                     if (!IAccountManager.ExistsPositionForSymbol(t[0].Symbol))
  41.                     {
  42.                         IAccountManager.PlaceMarketOrder(t[0].Symbol, 10000, Position.PositionSide.Long, .001);
  43.                     }
  44.                 }
  45.  
  46.                
  47.                 if (nextIndicatorTick < prevIndicatorTick)
  48.                 {
  49.                     if (IAccountManager.ExistsLongPositionForSymbol(t[0].Symbol))
  50.                     {
  51.                         IAccountManager.ClosePosition(t[0].Symbol);
  52.                     }
  53.                 }
  54.  
  55.                 if (nextIndicatorTick < 0 && nextIndicatorTick < prevIndicatorTick && prevIndicatorTick > 0)
  56.                 {
  57.                     if (!IAccountManager.ExistsPositionForSymbol(t[0].Symbol))
  58.                     {
  59.                         IAccountManager.PlaceMarketOrder(t[0].Symbol, 10000, Position.PositionSide.Short, .001);
  60.                     }
  61.                 }
  62.  
  63.                 if (nextIndicatorTick > prevIndicatorTick)
  64.                 {
  65.                     if (IAccountManager.ExistsShortPositionForSymbol(t[0].Symbol))
  66.                     {
  67.                         IAccountManager.ClosePosition(t[0].Symbol);
  68.                     }
  69.                 }
  70.  
  71.                 prevIndicatorTick = nextIndicatorTick;
  72.  
  73.             }
  74.  
  75.  
  76.  
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment