Margin: .01
Margin Requirment: $100
USDJPY trading at 108.71 so lot size = 10000 / (.01 * 108.71 * (1/USDJPY)) = 10000 / (.01 * 108.71 * 1/108.71) = 100000
AUDUSD trading at .8094 so lot size = 10000 / (.01 * .8094 * 1) = 1235000
USDJPY trading at 109.47 with ATR .7415 = 10000 / (.7415 * (1/USDJPY) = 10000 / (.7415 * (1/109.47)) = 1476000
AUDUSD trading at .80704 with ATR .00575 = 10000 / (.00575 * 1) = 1739000
I'm not sure if this is what you're looking for or not, but here's how I calculate position size. Personally I throw margin/leverage out of the calculation. I do use leverage, but I size based on stop loss size and percentage risk of account equity, and to come close to margin limits my percentage risk would have to be enormous.
So I use the simple calculation:
(Capital / SL ) * (Risk * 100) = Position size (in units)
Where:
Capital = Current dollar amount of trading account equity
SL = Stop loss size, in pips
Risk = Percentage risk in decimal form, I almost always use 0.02
Example for a $1000 account using a 20 pip stop loss and risking 2%:
(1000 / 20) * (2 * 100) = 10000 units
As another example here's my MultiCharts function called functionGetPositionSize (the inputPricePerPip variable is passed as MinMove/PriceScale * 10):
inputs:
inputAccountID (stringsimple),
inputSymbolCurrencyCode (numericsimple),
inputPricePerPip (numericsimple),
inputPipsInitialStopLoss (numericsimple);
variables:
numberAccountBalance (0),
numberPipValuePerStandardLot (0),
numberConversionRate (0),
numberCapitalAtRisk (0);
numberAccountBalance = GetRTCashBalance (inputAccountID);
if (numberAccountBalance > 0) then begin
if (inputSymbolCurrencyCode = USD) then begin
numberPipValuePerStandardLot= inputPricePerPip * 100000;
functionGetPositionSize= ((numberAccountBalance * 0.02) / (inputPipsInitialStopLoss * numberPipValuePerStandardLot)) * 100000;
end else begin
numberConversionRate= convert_currency (DateTime, USD, inputSymbolCurrencyCode, 1);
numberPipValuePerStandardLot= (inputPricePerPip / numberConversionRate) * 100000;
numberCapitalAtRisk= numberAccountBalance * 0.02;
functionGetPositionSize= (NumberCapitalAtRisk / (inputPipsInitialStopLoss * numberPipValuePerStandardLot)) * 100000;
end;
end else begin
functionGetPositionSize= (1 / (inputPricePerPip / 10)) * (20 / inputPipsInitialStopLoss);
end;
Also, as far as commissions:
In spot FX obviously you've got both spreads and commissions. On some of the more exotic pairs, and even on the majors during certain times, the spread can get considerable so it has to be factored in. I handle this in MultiCharts by using 2 streams of data from my broker-- bid price and ask price. That way, calculating the spread is easy.
Then, assuming you're using an ECN broker, there's a commission on top of the spread. However, the commission is generally fixed (or at least the trader should know what his commission would be while running a backtest/simulation, all the variable commission structures I've seen are dependent on very large differences in trading size). So the commission would be a lot easier to calculate than the spread.
I'm not sure if any of this helps or not but let me know and I'll try to clarify anything I can. Hopefully other FX traders that do things a little differently can chime in as well.
Ok, so we can just use arbitrary stop level as 1 ATR (have to consider not every strategy has a stop - if stop enabled then would use that instead). I would be curious to hear others takes as well. Using your formula above and my price values from #2 we would have
EURGBP .8780 .00509 = (10000 / 50.9) * (2 * 100) = 39000
USDJPY 109.47 .7415 = (10000 / 74.15) * (2 * 100) = 27000
AUDUSD .80704 .00575 = (10000 / 57.5) * (2 * 100) = 35000
Does this look right?
The idea with #1 in my post was that user wants equal dollar amounts in each position for portfolio testing or basket search of strategies. So how can I buy $10,000 worth of EURGBP, USDJPY, AUDUSD? Is #1 above correct?
Thanks
Yeah the ATR based sizing looks right.
For the sizing in #1, if you wanted to buy $10K worth of a spot currency that ends in USD you would just be buying 10000 units (or .1 lot, depending on how your broker notates it). There's no contract multiple or anything like that in spot FX. The closest it comes is the standardization of minilots (.1 lot, 10K units) and lots (100K units) but most brokers will let you buy in whatever unit size you want.
It looks like the calculations in #1 would be for maximizing position size to the minimum margin requirements if that makes any sense. So you'd be buying 12.3 lots of AUD/USD which would be $1.23M with $10K equity, etc.
Also-- sorry, when I looked at the sizing you posted above (for ATR based stop sizing) I only looked at AUD/USD. For non base pairs you'd need to use a modifier for the exchange rate etc. The function I pasted above works for that. There's probably a solid python function out there for it already as well, I can look around later today.
Can you help me out and rework the EURGBP and USDJPY ATR examples to include this exchange rate modifier?
Yeah let me get you a way better manual calc-- I'm actually doing the ones for #1 BACKWARDS now that I went to plug them in to my broker to check. I haven't manually calculated positions in forever, as it's kind of a mess in FX. Disregard the specific amounts I've posted so far for #1. Any calcs you've done based on that function I pasted would be correct, though.
The issue I'm running into with using python is that when I do the calculation in MultiCharts, I'm using some variables provided by the broker (when originally setting up the symbol in QuoteManager). The "price scale" setting in QuoteManager is effectively a multiplier for the current exchange rate. Otherwise you end up with yen pairs being massive distorted, etc. I'm trying to find a python function/library that already has this taken into account.
From MultiCharts docs.
Returns a numerical value, indicating the fractional unit equivalent of a single whole unit price change for the data series that the study is applied to.
Usage
PriceScale
Notes PriceScale = BigPointValue/PointValue
I can calculate this no problem. How would it be used in final calculation?
What we ultimately want is this (in MC I'm using the exchange rate and PriceScale to calculate StandardLotDollarValuePerPip) :
(RiskCapital / (StopLoss * StandardLotDollarValuePerPip)) * 100000
So if $200 is being risked (2% of $10K) then RiskCapital is $200. StandardLotDollarValuePerPip would be $10 for pairs ending in USD. The resulting position would be 100,000 units. The market dollar value would be $123,979.
StandardLotDollarValuePerPip would change for pairs ending in other currencies dependent on exchange rate. Right now it's 9.38 for USD/JPY. So ($200 / (20 * 9.38)) * 100000 would give us a position size of 106,496 units if we wanted to risk $200 (2% of $10K) with a 20 pip stop loss. The market dollar value of this position would be $106,496.
For EUR/GBP, StandardLotDollarValuePerPip would be $13.97 currently. So ($200 / (20 * 13.97)) * 100000 would give us a position size of 71,581. The current market value of that position would be $88,720.
I double checked these by plugging them into my broker.
Let me figure out how exactly PriceScale is being used to calculate that standard lot dollar per pip value.
I would like to calculate this without a % of account determined. That is really the trick. There are users that prefer to test systems then go back and determine appropriate size/risk for them and others who would be happy with this method. I need the flexibility ha
Maybe we turn 1 ATR unit into Risk capital? Could you re-work with that?
Maybe we turn 1 ATR unit into Risk capital? Could you re-work with that?
Yeah I was going to try and figure out a non-SL based calculation after this- I was starting from the % risk angle since I figured it would help me remember how I wrote the MC function to begin with. I should have documented all of this.
To clarify, the goals would be--
For #1, purchase a set base currency amount of a certain currency?
For #2, use ATR as a stop size?
The calculation for #1 should just need StandardLotDollarValuePerPip, the exchange rate, and the amount of money. The StandardLotDollarValuePerPip would tell us how much 100,000 units of that particular pair is worth in dollars and we should be able to calculate from there. This can be done easily without StandardLotDollarValuePerPip if the pair isn't a yen pair:
DesiredMarketValue / ExchangeRate = PositionSizeInUnits
So for AUD/USD: $10,000 / 0.7872 (current exchange rate for AUDUSD) = 12,703 units
For EUR/USD: $10,000 / 1.2396 (current exchange rate for EURUSD) = 8,067 units
For EUR/GBP: $10,000 / 1.2396 (current exchange rate for EURUSD) = 8,067 units
For EUR/AUD: $10,000 / 1.2396 (current exchange rate for EURUSD) = 8,067 units
Etc. I verified all of these on my broker.