#ifndef <r.h>
#include <r.h>
#endif
int myTMF(var myTradeID)
{
//pull vector from R session
Rset("TradeID" , myTradeID);
static var localvec[40];
Rv("tmf_agrs_list[[as.character(TradeID)]]", localvec, 40);
//vector pulled
Rx("tmf_agrs_list[[as.character(TradeID)]] <- NULL"); //free memory (delete list item)
if(TradeIsClosed)
{
printf("n=============================");
printf("nTradeID was %.0f", myTradeID);
int i;
for(i = 0; i < 40; i++)
{
printf("nlocalvec[%d] = %.5f", i, localvec[i]);
}
}
}
function run()
{
set(STEPWISE);
StartDate = 20070101;
EndDate = 20080101;
BarPeriod = 15;
static int myTradeID = 0;
if(is(INITRUN))
{
if(!Rstart("", 2)) //enable verbose output
//if(!Rstart("", 1)) //less output
{
printf("nError - could not start R session!");
quit();
}
Rx("tmf_agrs_list <- list()"); //create empty list to hold TMF arguments
}
var tmf_agrs[40];
int i;
//create some vector - you can easily see how the data moves from the outside into the TMF!
for(i = 0; i < 40; i++)
{
tmf_agrs[i] = myTradeID;
if(i > 10) tmf_agrs[i] = random();
}
//pass vector to R session and store it in the list
Rset("TradeID" , myTradeID);
Rset("tmf_agrs", tmf_agrs, 40);
Rx ("tmf_agrs_list[[as.character(TradeID)]] <- tmf_agrs");
if(!is(LOOKBACK))
{
printf("n=============================");
printf("nTradeID is %d - passing these elements into the TMF:", myTradeID);
int i;
for(i = 0; i < 40; i++)
{
printf("nglobalvec[%d] = %.5f", i, tmf_agrs[i]);
}
LifeTime = 1;
enterLong(myTMF, myTradeID);
myTradeID = myTradeID + 1;
}
}