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 EAALoaderZuluTrade extends TestScript {
	
	public EAALoaderZuluTrade() {
		setCategory("EAA Loaders");
		setName("EAA Loader ZuluTrade");
	}
	
	@Override
	public void runTest() {
		test1();
		test2();
		test3();
		test4();
	}
	
	public void test1() {
		try {
			SQResultsGroup strategyResults = (SQResultsGroup) Program.get("Loader").call("loadFile", "./tests/data/loaders/Zulu_TradeHistory_ETE_19870429_20140914.xlsx");
			SQResult result;
			SQStats stats;

			// verify portfolio
			result = strategyResults.getResult(SQConst.SYMBOL_PORTFOLIO);
			stats = result.getStats(SQConst.DIRECTION_ALL, SQConst.PL_IN_MONEY, SQConst.KEY_SAMPLE_ALL);
		
			assertEquals("ZuluTrade 1 NumberOfTrades", 6796, stats.getInt("NumberOfTrades"));
			assertEquals("ZuluTrade 1 NetProfit", 323116.52, stats.getDouble("NetProfit"));
		} catch (Exception e) {
			fail("Exception "+ e.getMessage());
		}
	}
	
	public void test2() {
		try {
			SQResultsGroup strategyResults = (SQResultsGroup) Program.get("Loader").call("loadFile", "./tests/data/loaders/Zulu_TradeHistory_JackTheP1pper_19870429_20140914.xlsx");
			SQResult result;
			SQStats stats;

			// verify portfolio
			result = strategyResults.getResult(SQConst.SYMBOL_PORTFOLIO);
			stats = result.getStats(SQConst.DIRECTION_ALL, SQConst.PL_IN_MONEY, SQConst.KEY_SAMPLE_ALL);
		
			assertEquals("ZuluTrade 2 NumberOfTrades", 2338, stats.getInt("NumberOfTrades"));
			assertEquals("ZuluTrade 2 NetProfit", 495901.91, stats.getDouble("NetProfit"));
		} catch (Exception e) {
			fail("Exception "+ e.getMessage());
		}
	}
	
	public void test3() {
		try {
			SQResultsGroup strategyResults = (SQResultsGroup) Program.get("Loader").call("loadFile", "./tests/data/loaders/Zulu_TradeHistory_Denver_19870429_20140914.csv");
			SQResult result;
			SQStats stats;

			// verify portfolio
			result = strategyResults.getResult(SQConst.SYMBOL_PORTFOLIO);
			stats = result.getStats(SQConst.DIRECTION_ALL, SQConst.PL_IN_MONEY, SQConst.KEY_SAMPLE_ALL);
		
			assertEquals("ZuluTrade 3 NumberOfTrades", 2929, stats.getInt("NumberOfTrades"));
			assertEquals("ZuluTrade 3 NetProfit", 325777.22, stats.getDouble("NetProfit"));
		} catch (Exception e) {
			fail("Exception "+ e.getMessage());
		}
	}
	
	public void test4() {
		try {
			SQResultsGroup strategyResults = (SQResultsGroup) Program.get("Loader").call("loadFile", "./tests/data/loaders/Zulu_TradeHistory_Ghigou_19870429_20140914.csv");
			SQResult result;
			SQStats stats;

			// verify portfolio
			result = strategyResults.getResult(SQConst.SYMBOL_PORTFOLIO);
			stats = result.getStats(SQConst.DIRECTION_ALL, SQConst.PL_IN_MONEY, SQConst.KEY_SAMPLE_ALL);
		
			assertEquals("ZuluTrade 4 NumberOfTrades", 2408, stats.getInt("NumberOfTrades"));
			assertEquals("ZuluTrade 4 NetProfit", 407844.33, stats.getDouble("NetProfit"));
		} catch (Exception e) {
			fail("Exception "+ e.getMessage());
		}
	}
}
