[R-SIG-Finance] Blotter package - problem with example.

Joshua Ulrich josh.m.ulrich at gmail.com
Wed Jan 20 20:31:46 CET 2010


Brian / Jan,

It's not updated yet, but I know what needs to be done and plan to
update the post this evening.

Best,
Josh
--
http://www.fosstrading.com



On Wed, Jan 20, 2010 at 12:49 PM, Brian G. Peterson <brian at braverock.com> wrote:
> Jan,
>
> I believe that Josh has updated his example on the FOSStrading site.
>
> demo('longtrend') should work as expected.
> demo('turtles') is broken, I haven't gotten around to updating it yet
> demo('amzn') is working
>
> 'blotter' is currently under very heavy development to integrate more
> complex instrument types and multiple currencies.
>
> Last week, the interfaces of several of the core functions changed with the
> introduction of an environment to store trade, position, and P&L data.
>
> As such, old examples will be broken until updated.
>
> addTxn(), for example, no longer returns a portfolio object, but instead
> assigns the updated portfolio back into the environment.
>
> Take a look at the two working examples (above) and then I'd be happy to
> help make your example work on the new code if you're still having trouble.
>
> The good news is that much of the major surgury is completed, and the code
> is much faster than it was a couple weeks ago, and more flexible.
>
> Regards,
>
>   - Brian
>
> Jan Vandermeer wrote:
>>
>> Hi Folks;
>>
>> Seems that dissimilar but related problems happen with blotter for me. See
>> <
>> https://stat.ethz.ch/pipermail/r-sig-finance/2009q4/005014.html>
>>
>> I was playing with the FOSS Trading blog example Tactical Asset Allocation
>> Using Blotter <
>>
>> http://blog.fosstrading.com/2009/11/tactical-asset-allocation-using-blotter.html>
>> and initially it ran faultlessly. I then updated my R packages, this this:
>>
>> update.packages() using a local mirror (University of Waterloo) and
>> example
>> no longer worked.
>>
>> When I reran the tactical example R spat out:
>>
>> "source("tactical.R") -  (This is a verbatim copy of Josh's code in the
>> article)
>> Loading required package: xts
>> Loading required package: zoo
>> Loading required package: Defaults
>> Loading required package: TTR
>> Loading required package: FinancialInstrument
>>
>> Package PerformanceAnalytics (1.0.0) loaded.
>> Econometric tools for performance and risk analysis.
>> (c) 2004-2009 Peter Carl, Brian G. Peterson. License: GPL
>> http://braverock.com/R/
>>
>>
>> Attaching package: 'PerformanceAnalytics'
>>
>>
>>        The following object(s) are masked from package:graphics :
>>
>>         legend
>>
>> [1] "Loading data"
>> [1] "Setting up indicators"
>> [1] "Initializing portfolio and account structure"
>> Error in vector("list", length = length(symbols)) : element 1 is empty;
>>   the part of the args list of 'length' being evaluated was:
>>   (symbols)
>>
>>
>> I then went and tried the example in the blotter package. It did not work
>> either and I then tried Jeff Ryan's suggestion and updated
>> blotter, xts & quantmod and reran the example:
>>
>> # Construct a portfolio object and add some transactions
>> library(blotter)
>> # Download price data
>> symbols = c("IBM","F","MMM")
>> require(quantmod)
>> getSymbols(symbols, from='2007-01-01', to='2007-01-31',
>> index.class="POSIXct")
>>
>> # Initialize a portfolio object 'p'
>> print('Creating portfolio \"p\"...')
>> p = initPortf(symbols=symbols)
>>
>> ## Trades must be made in date order.
>> print('Adding trades to \"p\"...')
>> # Make a couple of trades in IBM
>> p = addTxn(p, "IBM", '2007-01-03', 50, 96.5, -0.05*50)
>> p = addTxn(p, "IBM", '2007-01-04', 50, 97.1, -0.05*50)
>>
>> # ...a few in F...
>> p = addTxn(p, "F", '2007-01-03', -100, 7.60, -0.05*100)
>> p = addTxn(p, "F", '2007-01-04', 50, 7.70, -0.05*50)
>> p = addTxn(p, "F", '2007-01-10', 50, 7.78, -0.05*50)
>>
>> # ...and some in MMM
>> p = addTxn(p, "MMM", '2007-01-05', -50, 77.9, -0.05*50)
>> p = addTxn(p, "MMM", '2007-01-08', 50, 77.6, -0.05*50)
>> p = addTxn(p, "MMM", '2007-01-09', 50, 77.6, -0.05*50)
>>
>> print('Updating portfolio \"p\"...')
>> p = updatePortf(p,'2007-01')
>> calcPortfSummary(p)
>> getBySymbol(p,'Pos.Qty')
>>
>> print('Creating account \"a\" for portfolio \"p\"...')
>> a = initAcct(portfolios="p")
>> print('Updating account \"a\"...')
>> a = updateAcct(a,'2007-01') # Check out the sweet date scoping. Thanks,
>> xts.
>> a = updateEndEq(a,'2007-01')
>> print(a)
>>
>> which gave me:
>>
>> source("Blotter_ex.R")
>> Loading required package: xts
>> Loading required package: zoo
>> Loading required package: quantmod
>> Loading required package: Defaults
>> Loading required package: TTR
>> Loading required package: FinancialInstrument
>> [1] "Creating portfolio \"p\"..."
>> [1] "Adding trades to \"p\"..."
>> [1] "2007-01-03 IBM 50 @ 96.5"
>> Error in get(paste("portfolio", pname, sep = "."), envir = .blotter) :
>>  object 'portfolio.list(txn = c(0, 50, 0, 96.5, 0, 0, 0, 4825, 0, 96.5, 0,
>> 50, 0, 96.5, 0, 0, 0, 1), posPL = c(0, 1, 1, 0, 0, 0, 0, 0, 0))' not found
>> In addition: Warning message:
>> In addTxn(p, "IBM", "2007-01-03", 50, 96.5, -0.05 * 50) :
>>  Instrument IBM  not found, using contract multiplier of 1
>>
>> I've tried to puzzle my way through this. I seems that there are updates
>> that introduce these different errors. Are they related ?
>>
>> Any assistance would be appreciated.
>>
>> Jan Vandermeer
>>
>>        [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-SIG-Finance at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions
>> should go.
>>
>
>
> --
> Brian G. Peterson
> http://braverock.com/brian/
> Ph: 773-459-4973
> IM: bgpbraverock
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>



More information about the R-SIG-Finance mailing list