/*
 * 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.MoneyManagementTypes;

import com.strategyquant.futurelib.backtester.SymbolsTable;
import com.strategyquant.lib.language.L;
import com.strategyquant.lib.results.SQOrder;
import com.strategyquant.lib.results.SQOrderList;
import com.strategyquant.lib.snippets.MoneyManagementSim.MoneyManagementType;

public class FixedAmount extends MoneyManagementType {

	private double mmRisk;
	private double mmLots;
	private double mmMaxLots;
	
	public FixedAmount() {
		setName(L.t("Fixed amount"));
		setNote(L.tHtml("<b>Risk fixed amount of money</b><br/>Strategy will risk a given amount of money for every trade.<br/><br/>This is a basic money management without compounding. It can be used to test real performance of strategies where Stop loss is based on volatility (ATR)."));
		
		addDoubleParameter("Risk", L.t("Risk in $"), 500d, 1d, 10000d, 10d, L.t("How much money will be risked in every trade?"));
		addDoubleParameter("Lots", L.t("Lots if no MM"), 1d, 0.01d, 1000000d, 0.1d, L.t("How many lots should be traded if we disable or cannot use Money Management - for example when no Stop Loss is defined for the order"));
		addDoubleParameter("MaxLots", L.t("Maximum lots"), 5d, 0.01d, 1000000d, 0.1d, L.t("The biggest lot size allowed"));

		setFormatedName(L.t("Fixed amount: ${Risk}, {Lots} lots, {MaxLots} max. lots"));
	}
	
	@Override
	public void init(SQOrderList originalOrderList, SymbolsTable symbolsTable) throws Exception {
		mmRisk = this.getDoubleParameterValue("Risk");
		mmLots = this.getDoubleParameterValue("Lots");
		mmMaxLots = this.getDoubleParameterValue("MaxLots");
	}

	@Override
	public double computeTradeSize(SQOrder order, double tickSize, double pointValue) {
		return mmLots;
	}
}