0. This needs sim market data **not** to be merged with replay (or cert), so we can create our own markets.

1. This is a proprietary algo so its hidden behind a config key. Enable it by adding the following to config
DynamicAlgos{
   value {
      enable_tascounter: true
   }
}

2. We will run this test on the grain markets, speficially corn, so make sure you have ZC (it could also be run for other
grain products, but this test is written for ZC)

3. Open up Algo Studio and make a TASCounter algo.
Concepts : 
ZC expirations = Mar, May, Jul, Sep, Dec
T1 contracts are adjacent calendar spreads so if the front month is May 
T1 Front = May-Jul 
T1 Second = Jul-Sep
T1 Third = Sep-Dec 

T2 skips an expiration
T2 Front = May-Sep
T2 Second = Jul-Dec
T2 Third is not used

T3 skips 2 expirations
T3 Front = May-Dec

Set up those contracts for the algo.

4. The TAS contracts are the corresponding TAS contracts for ZC (ZCT is the TAS product for ZC).
T1 Front = ZCT May-Jul
T1 Second = ZCT Jul-Sep
T1 Third = ZCT Sep-Dec 

(Since we are running SIM, if these contracts are not available, choose any other contracts that are not used above)

5. For T1 Front time, T1 Qty, and T1 Order Enabled enter 60, 10 and false respectively. Do the same for 
T2 Front time, T2 Qty, and T2 Order Enabled, as well as T3 Front time, T3 Qty, and T3 Order Enabled.

6. This algo runs during the settlement window of the product (ZC in this case). This is an input parameter which will 
also make it easier for us to run this test. So enter a time (remember if your server is on Central time, make the adjustment)
3 or 4 mins from now. Enter the settlement period as 180 seconds.

7. Give the algo a name and save it.

8. Bring up ladders and timesales for all 6 non TAS contracts. Bring up ladder for the TAS contracts.

9. The contracts, price and qty are already part of the algo, so we can launch it from any ladder, with any price, or qty. Launch the algo

10. Bring up the orderbook, and make sure the input params are correct.

11. Make sure there is an output params grid under the input params. All other values except for "Seconds To Settle" should be NAN.
"Seconds To Settle" should downcount toward the settle window, and should go to 0 when in settlement period.

12. Now once you enter the settlement period, enter a few orders and cross them, across all 6 non TAS contracts. Enter them at a few
price levels. Make sure they show up in the timesales window.

13. Make sure the VWAP for all these 6 contracts is correct. VWAP is simply sum(price*qty) for all trades / sum (qty).

14. Now make sure the Projected Settles for T1 Front, Second and Third is correct. This is how they are calculated
T1 Front Projected Settle = VWAP (T1 Front)
T1 Second Projected Settle = VWAP (T2 Front) - VWAP (T1 Front)
T1 Third Projected Settle = VWAP(T3 Front) - VWAP(T1 Front) - VWAP(T1 Second)
These values are rounded to the nearest tick (0.25 in this case)

15. The last step it to make the algo actually shoot orders. I will explain what the concept is and that can be used for testing.
This is a market making algo, so the trader wants to buy at the bid or sell at the offer. The TAS contract is a special contract that
gives delivery of the actual contract at the price the TAS was traded at. So for example if you bought N TAS contracts on product X 
at -1.0, it means you will get delivery of X at settlement (of X) +(-1). If you sold the TAS contract at 0, you will go short on X
at settlement + 0.
With this in mind, the algo watches the TAS market and crosses an order (ie buys at the offer or sells at the bid) if it gets delivery
on the actual product such that its a buy at or below the bid or a sell at or above the offer.
So for example the TAS Market is Bid=0, Ask=0-2. If we sell at Bid we will go short in the main product at Settlement + 0. 
If our projected settle (from 14.) is >= the offer of the main product we will sell the TAS.
The algo will buy or sell the TAS contract if the condition above holds AND if its Order Enabled = True and Time is within the window.

Repeat the above for T1 Front, Second and Third.