Below is a complete MRE, except for the asset data. When run with just the first 50 assets, everything works fine. But when the full asset list is used only long positions are entered. The printf output confirms that enterShort() is being called even though no short positions are actually taken. Is there a problem with the MRE script?


#include <r.h>

vars signals, ranks_01;

/// m-period simple return, at t steps back in time
var simple_returns(int t, int m) {
return priceClose(t) / priceClose(t + m) - 1;
}

function run()
{
Script = "DeepLearn";
StartDate = 19930101;
EndDate = 19931231;
BarPeriod = 1440;
LookBack = 240;

NumWFOCycles = 1;
DataSplit = 75;

set(RULES+PEEK+LOGFILE);
LifeTime = 1;
if(Train) Hedge = 2;

if(is(INITRUN)) {
// All 448 assets
assetList("Assets.KDH.1993.csv");
// First 50 assets only
//assetList("Assets.50.1993.csv");
printf("\nNumAssetsListed: %d", NumAssetsListed);

signals = malloc(NumAssetsListed * sizeof(var));
ranks_01 = malloc(NumAssetsListed * sizeof(var));
}

vars target_returns = series(simple_returns(-1, 1));

char* symbol;
int i = 0;
while(asset(symbol = loop(Assets))) {
var signal = adviseLong(NEURAL, target_returns[0], simple_returns(0, 1), simple_returns(1, 1), simple_returns(2, 1));
signals[i++] = signal;
}

sortRank(ranks_01, signals, NumAssetsListed);

i = 0;
for(listed_assets) {
asset(Asset);

// Convert to an integer rank between 1 and NumAssetsListed
int rank = round(ranks_01[i++] * (NumAssetsListed - 1)) + 1;
//printf("\nrank: %d", rank);

if(rank == 1) {
printf("\nGoing short...");
enterShort();
}
if(rank == NumAssetsListed) {
printf("\nGoing long...");
enterLong();
}
}
}


Last edited by JamesHH; 08/13/19 20:57. Reason: typo