/*
 * Copyright (c) 2015, StrategyQuant - All rights reserved.
 *
 * Code in this file was made in a good faith that it is correct and does what it should. 
 * If you found a bug in this code OR you have an improvement suggestion OR you want to include 
 * your own code snippet into our standard library please contact us at:
 * http://tasks.strategyquant.com/projects/snippets/
 *
 * This code can be used only within StrategyQuant products. 
 * Every owner of valid (free, trial or commercial) license of any StrategyQuant product 
 * is allowed to freely use, copy, modify or make derivative work of this code without limitations,
 * to be used in all StrategyQuant products and share his/her modifications or derivative work 
 * with the StrategyQuant community.
 *  
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES 
 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *  
 */
package com.strategyquant.extend.Test;

import com.strategyquant.lib.results.SQResult;
import com.strategyquant.lib.results.SQResultsGroup;
import com.strategyquant.lib.results.SQStats;
import com.strategyquant.lib.scripter.Program;
import com.strategyquant.lib.settings.SQConst;
import com.strategyquant.lib.tests.TestScript;


public class EAALoaderEAAReport extends TestScript {
	public EAALoaderEAAReport() {
		setCategory("EAA Loaders");
		setName("EAA Loader EAA Report");
	}
	
	@Override
	public void runTest() {
		testPortfolioEAA2();
		testPortfolio();
		testSingle();
		testSingle2();
	}
	
	public void testPortfolioEAA2() {
		try {
			SQResultsGroup strategyResults = (SQResultsGroup) Program.get("Loader").call("loadFile", "./tests/data/loaders/QSEA_full_Statement_EAA2.sqa");
			SQResult result;
			SQStats stats;
			
			// verify that correct loader was used
			assertEquals("PortfolioEAA2 Loader plugin", "SQ strategy loader", (String) strategyResults.get("PluginLoaderName"));
			
			// verify portfolio
			result = strategyResults.getResult(SQConst.SYMBOL_PORTFOLIO);
			stats = result.getStats(SQConst.DIRECTION_ALL, SQConst.PL_IN_MONEY, SQConst.KEY_SAMPLE_ALL);
		
			assertEquals("PortfolioEAA2 NumberOfTrades", 163, stats.getInt("NumberOfTrades"));
			
		} catch (Exception e) {
			fail("Exception "+ e.getMessage());
		}
	}
	
	public void testPortfolio() {
		try {
			SQResultsGroup strategyResults = (SQResultsGroup) Program.get("Loader").call("loadFile", "./tests/data/loaders/QSEA_full_Statement.sqa");
			SQResult result;
			SQStats stats;
			
			// verify that correct loader was used
			assertEquals("Portfolio Loader plugin", "SQ strategy loader", (String) strategyResults.get("PluginLoaderName"));
			
			// verify portfolio
			result = strategyResults.getResult(SQConst.SYMBOL_PORTFOLIO);
			stats = result.getStats(SQConst.DIRECTION_ALL, SQConst.PL_IN_MONEY, SQConst.KEY_SAMPLE_ALL);
		
			assertEquals("Portfolio NumberOfTrades", 163, stats.getInt("NumberOfTrades"));
			
		} catch (Exception e) {
			fail("Exception "+ e.getMessage());
		}
	}

	public void testSingle() {
		
		try {
			SQResultsGroup strategyResults = (SQResultsGroup) Program.get("Loader").call("loadFile", "./tests/data/loaders/QSEA_full_StatementSingle.sqa");
			SQResult result;
			SQStats stats;
			
			// verify that correct loader was used
			assertEquals("Single Loader plugin", "SQ strategy loader", (String) strategyResults.get("PluginLoaderName"));
			
			// verify portfolio
			result = strategyResults.getResult(SQConst.SYMBOL_PORTFOLIO);
			stats = result.getStats(SQConst.DIRECTION_ALL, SQConst.PL_IN_MONEY, SQConst.KEY_SAMPLE_ALL);
		
			assertEquals("Single NumberOfTrades", 163, stats.getInt("NumberOfTrades"));
			
		} catch (Exception e) {
			fail("Exception "+ e.getMessage());
		}
	}

	public void testSingle2() {
		
		try {
			SQResultsGroup strategyResults = (SQResultsGroup) Program.get("Loader").call("loadFile", "./tests/data/loaders/QSEA_full_StatementSingle2.sqa");
			SQResult result;
			SQStats stats;
			
			// verify that correct loader was used
			assertEquals("Single2 Loader plugin", "SQ strategy loader", (String) strategyResults.get("PluginLoaderName"));
			
			// verify portfolio
			result = strategyResults.getResult(SQConst.SYMBOL_PORTFOLIO);
			stats = result.getStats(SQConst.DIRECTION_ALL, SQConst.PL_IN_MONEY, SQConst.KEY_SAMPLE_ALL);
		
			assertEquals("Single2 NumberOfTrades", 163, stats.getInt("NumberOfTrades"));
			
		} catch (Exception e) {
			fail("Exception "+ e.getMessage());
		}
	}
}