Friday, April 25, 2014

Running backtesting with blotter in parallel

I was running backtestis with blotter package on many symbols and wanted to parallize the whole process with foreach loops.

Specifying portfolios inside the foreach loops like this:
.blotter <- new.env()
b.strategy <- paste(symbol, "strat", sep="_")
initPortf(b.strategy,symbol, initDate='2006-01-01')
initAcct(b.strategy,portfolios=b.strategy, initDate='2007-01-01', initEq=1e6)

Then running trough the data and adding transactions with:
        # enter long position
        addTxn(b.strategy, Symbol=symbol, TxnDate=CurrentDate,
               TxnPrice=ClosePrice, TxnQty = tradeSize , TxnFees=-1) 

It took some time to find out why I could not run updatePortf since it gave the error "object 'AAPL' not found".
Inside the loop I assigned the symbol with
assign(symbol, data)
Instead I needed to assign it with:
assign(symbol, data, envir=.GlobalEnv) since the parent frame to updatePortf inside the foreach loop is not the same as to assign and get.



Saturday, February 15, 2014

Wordcloud of tweets couple of hours after USA vs. Russia hockey game


Created with R from the twitter data-stream. Not quite possible to see who won from this data but one can see that there has been a hockey game and the most likely players were USA and Russia.