- Receive and archive real time data
- Create buy and sell signals
- Keep track of open positions and P&L
- Manage risk positions
- Evaluate performance
- Cost estimation
nov29 = CalUtils.createStrikeDate(29, 11, 2010)
portfolio = Portfolio()
market = Market()
# EURCHF - how many CHF to buy 1 EUR
op1 = EuropeanLongCall(0.01440, 1.3335, nov29, "EURCHF", 20000)
op2 = EuropeanShortCall(0.00220, 1.3615, nov29, "EURCHF", 200000)
# CHFEUR - how many EUR to buy 1 CHF
debt = Loan(nov29, "CHFEUR", 1300)
portfolio.add(op1)
portfolio.add(op2)
portfolio.add(debt)
# Simulation
print "EURCHF", ",", "Payoff", ",", "Loan"
for a in xrange((1.3800 - 1.3280) / 0.0001):
x = a * 0.0001 + 1.3280;
market.setPrice(nov29, "EURCHF", x)
market.setPrice(nov29, "CHFEUR", 1/x)
portfolio.setMarket(market)
print x, ",", portfolio.getProfit(nov29) - portfolio.totalCost(), ",", debt.getProfit(nov29)
//+------------------------------------------------------------------+
//| collectPrices.mq4 |
//| luisf.canals@.... |
//| |
//+------------------------------------------------------------------+
#property copyright "luisf.canals@..."
#property link ""
#property library
#include "..\include\collectPrices.mqh"
/**
* Gets the matrix of prices for currencies.
*
* Return a Matrix with first line for prices on moment T-K,T-K+1,...T-1.
*
* Each line has: High, Low, Open, Close, Volume and RSI for symbol[0],
* symbol[1],...,symbol[N-1].
*
* 'prices' matrix should have 1 + K x 6*ArraySize(symbols) dimensions,
* the first one for timestamps.
*
* Returns false if prices cannot be get.
*/
bool collectPrices(string symbols[], int K, double &prices[][]) {
int period = PERIOD_M1;
int timebase = ((TimeCurrent()/60) - 1) * 60;
if(timebase<=prices[K-1][0]) return (false);
double line[];
ArrayResize(line, (6*ArraySize(symbols))+1);
for(int i=0; i<ArraySize(line); i++) line[i]=0;
while(true) {
for(int s=0;s<ArraySize(symbols); s++) {
int j=6*s + 1;
Print(symbols[s] + ":" + iTime(symbols[s], period, 1)
+ " - timebase=" + timebase);
if(line[j]==0 && iTime(symbols[s],period,1)>=timebase) {
// Go back in time if iTime>timebase
if(iTime(symbols[s],period,1)<timebase
&& symbols[s]==Symbol()) {
return (false);
}
if(iTime(symbols[s], period, 1)>timebase) {
return (false);
}
int t = 1;
line[j] = iHigh(symbols[s], period,t);
j++;
line[j] = iLow(symbols[s], period,t);
j++;
line[j] = iOpen(symbols[s], period,t);
j++;
line[j] = iClose(symbols[s], period,t);
j++;
line[j] = iVolume(symbols[s], period,t);
j++;
line[j] = iRSI(symbols[s], 0, 14, PRICE_CLOSE, t);
j++;
}
}
bool completed = true;
for(s=0; s<ArraySize(symbols); s++) {
if(line[6*s + 1]==0) {
completed = false;
break;
}
}
if(completed) break;
Sleep(200);
}
line[0] = timebase;
for(i=0; i<K-1; i++) {
for(j=0;j<ArraySize(line); j++) {
prices[i][j] = prices[i+1][j];
}
}
for(j=0; j<ArraySize(line); j++) {
prices[K-1][j] = line[j];
}
return (true);
}
| eurchf | usdchf | usdjpy | gbpjpy | gbpusd | eurusd | |
| LSSVM earn | 37 | -35 | 126 | 25 | 107 | 0 |
| LSSVM bolli | 11 | 47 | 170 | 127 | 59 | 1 |
| LSSVM rstuvw | 2 | -90 | 224 | 189 | 133 | 1 |
| Simpl. earn | -10 | -43 | 517 | 89 | 419 | 31 |
| Simpl. bolli | -133 | 0 | 198 | -320 | 133 | -251 |
| Simpl. rstuvw | -65 | 1 | 623 | -117 | 386 | -476 |
function [long short] = ais(HLOC, timeframe, pips)
%
% ais
%
% [long short] = ais(HLOC, timeframe, pips)
%
% Indicator of maximum profit for each moment open a position in just
% this moment
%
% Parameters:
% HLOC, matrix with High,Low,Open,Close prices values in columns.
% timeframe, size of the window to before closing the position
% pips, spread between opening and closing position
%
% Output:
%
%
[p1 p2] = size(HLOC);
long = [];
short = [];
for ii=1:p1-timeframe
% Long positions
profit = -inf;
for jj=ii+1:ii+timeframe
profit2 = (HLOC(jj,1) - HLOC(ii,3)-pips)/HLOC(ii,3);
if profit2 > profit
profit = profit2;
end
end
long = [long
profit];
% Short positions
profit = -inf;
for jj=ii+1:ii+timeframe
profit2 = (HLOC(jj,3) - HLOC(ii,2)-pips)/HLOC(ii,3);
if profit2 > profit
profit = profit2;
end
end
short = [short
profit];
end
The main problem related to simplistic is the "stability" against training variances.
When training set suffers a little change (for instance 10 minutes more or less), the results are unpredictable, incurring into great loses or earnings…. apparently randomness (is chaotic, now I remember!)
I've tried to solve it using a linear LSSVM. With a RBF LSSVM, stupid results are got (everything has the same value per day, depending only on the set of train data… mmmmm….. it would be interesting….). With polynomial kernel, better stability and no loss in precision is got. Ok, let's try with LSSVM and polynomial kernels.
aispos(t) = max. profit if a long position has been opened at time t-T
aisneg(t) = max. profit if a short position has been opened at time t-T
With this indicator, we try to study correlation and mutual information between different forex.
Considering the forex EURCHF, USDCHF, USDJPY, GBPJPY, GBPUSD, EURUSD numbered from 1 to 6, I'm showing here the graphical results:

