a) Is it possible to set (or at least verify) the "Required Capital Assumptions in Margin Trading" / "Potential Loss Per Contract" in a script? and if so, how would I do that?
b) Is there an easy way to see which trades are skipped because of a lack of capital? Ideally, it would be nice to see in the Performance Report an item under "Trade Analysis" that are the skipped / reduced size trades.
c) When setting my position size in a PMM script, it gets calculated on every call of the script for every symbol. This seems very inefficient. Is it possible to only calculate the position size when an order is being placed for a given symbol? I am struggling with finding a way to identity that an order has been placed in the Signal script from the PMM script.
Portfolio MM Script Questions
- Angelina MultiСharts
- Posts: 260
- Joined: 28 Dec 2016
- Has thanked: 28 times
- Been thanked: 66 times
Re: Portfolio MM Script Questions
Hello GTrader!
Let me address your questions in order:
a) No, I’m afraid that’s not possible.
b) There isn’t an easier way to do that. If you want this functionality in MultiCharts, please, leave a feature request at this web page:
http://www.multicharts.com/pm/
с) Can you provide an example of what you're trying to do?
Let me address your questions in order:
a) No, I’m afraid that’s not possible.
b) There isn’t an easier way to do that. If you want this functionality in MultiCharts, please, leave a feature request at this web page:
http://www.multicharts.com/pm/
с) Can you provide an example of what you're trying to do?
Re: Portfolio MM Script Questions
Hi Angelina,
Please see the following example. I am setting the position sizing in the PMM script. The size is set on each bar update. Ideally it would only need to be set on each order. When running against a large portfolio I would think the overhead would be expensive. Any ideas on how to make this more efficient?
Please see the following example. I am setting the position sizing in the PMM script. The size is set on each bar update. Ideally it would only need to be set on each order. When running against a large portfolio I would think the overhead would be expensive. Any ideas on how to make this more efficient?
Code: Select all
using ATCenterProxy.interop;
using PowerLanguage.Function;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PowerLanguage.Strategy
{
public class Gt_PortfolioManager : PortfolioSignalObject
{
private const double bps_to_percent = 0.0001;
public Gt_PortfolioManager(object _ctx) : base(_ctx)
{
SizingMethod = Gt_SizingMethod.FixedRisk;
AtrLength = 21;
RiskInBps = 25;
TraceOutput = false;
}
protected override void Create()
{
if (TraceOutput)
{
Output.Clear();
}
}
protected override void StartCalc()
{
if (Environment.ApplicationCode != EApplicationCode.Portfolio)
{
ExecControl.Abort("This is a money-management signal for MC's Portfolio Trader.");
}
}
protected override void CalcBar()
{
/************** PORTFOLIO *************************************/
double m_currentEquity = this.PortfolioEquity();
/************** PORTFOLIO PERFORMANCE *************************/
IPortfolioPerformance m_performance = this.Portfolio;
/************** STRATEGY INSTANCE FOR EACH SYMBOL *************/
foreach (IPortfolioStrategy m_strategyBySymbol in PortfolioStrategies)
{
/********** SIGNAL *************************************/
foreach (IStrategy m_signal in m_strategyBySymbol.Signals)
{
//if(m_signal.Bars.CurrentBar >= 0 && m_signal.Bars.Time[0] == Bars.Time[0])
//{
if (TraceOutput)
{
/******* LETS REVIEW OPEN TRADES *******************/
foreach (IMarketPosition p in m_signal.Positions)
{
int n = 0;
foreach (ITrade t in p.OpenTrades)
{
Output.WriteLine(" {0} {1} {2} {3} {4} of {5} at {6} = {7}",
m_signal.Bars.Time[0].Date,
m_signal.Bars.Time[0].TimeOfDay,
++n,
Enum.GetName(typeof(EOrderAction), t.EntryOrder.Action),
t.EntryOrder.Contracts,
m_signal.Bars.Info.Name,
t.EntryOrder.Price.ToString("N2"),
(t.EntryOrder.Contracts * t.EntryOrder.Price).ToString("N2"));
}
}
}
/******* SET CONTRACT SIZE *************************/
var m_contracts = 0;
var m_capitalAtRisk = RiskInBps * bps_to_percent * m_currentEquity;
if (SizingMethod == Gt_SizingMethod.FixedCash)
{
m_contracts = (int)(m_capitalAtRisk / m_signal.Bars.Close[0]);
}
else if (SizingMethod == Gt_SizingMethod.FixedRisk)
{
var m_atr = m_signal.AverageTrueRange(AtrLength);
m_contracts = (int)((m_atr > 0) ? m_capitalAtRisk / m_atr : 0);
}
var m_cost = m_contracts * m_signal.Bars.Close[0];
m_strategyBySymbol.EntryContracts = m_contracts;
// }
}
}
}
#region PROPERTIES
[Input]
public Gt_SizingMethod SizingMethod { get; set; }
[Input]
public int AtrLength { get; set; }
[Input]
public double RiskInBps { get; set; }
[Input]
public bool TraceOutput { get; set; }
#endregion
#region ENUMS
public enum Gt_SizingMethod
{
FixedCash = 1,
FixedRisk = 2,
}
#endregion
}
}