An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110826/0f8b7967/attachment.pl>
Quantstrat - trading not just Crossovers (e.g. Moving Average)
3 messages · Igor Chernukhin, Kent Russell, Brian G. Peterson
See if this helps http://www.google.com/m/url?ei=ULhXTtiYCqOIsgeo54kY&q=http://timelyportfolio.blogspot.com/2011/07/quantstrat-to-build-on-part-6.html&ved=0CCcQFjAE&usg=AFQjCNHmJsPa1uDfZKwfqPsHy42kxK7nlg Kent
On Aug 26, 2011, at 7:39 AM, igor_vilcek_external at tatrabanka.sk wrote:
Thanks, works fine for me in this case. I am just wondering, however, how to use this solution in case i want to set my own order sizing function (e.g. order size based on a % of current portfolio equity). In other words, how to trade my system (above Moving Average, not crossover) and use flexible order quantity as well. Igor Vil?ek Joshua Ulrich <josh.m.ulrich at gmail.com> 25.08.2011 03:16 To "Brian G. Peterson" <brian at braverock.com> cc igor_vilcek_external at tatrabanka.sk, r-sig-finance at r-project.org Subject Re: [R-SIG-Finance] Quantstrat - trading not just Crossovers (e.g. Moving Average) On Mon, Aug 22, 2011 at 10:33 AM, Brian G. Peterson <brian at braverock.com> wrote:
On Mon, 2011-08-22 at 17:19 +0200, igor_vilcek_external at tatrabanka.sk wrote:
Hi, I've encountered a problem in quanstrat framework, in case I want to
trade
not just signalCrossovers (or better said, the modified version of a Crossover). Specifically i would like to e.g. go Long if Price>MovingAverage and
Exit
if Price<MovingAverage. This means, that if we have on a <b>starting </b>day
Price>MovingAverage
(not a crossover, just "above"), i want the system to buy immediately
on a
starting day. However, just once. If i tried sigComparison, this solved the problem with trading
immediately
on a starting day, but started trading <b>anytime</b> a Price>MovingAverage (every day in a row). To sum up, I need to know how to modify sigCrossover to trade also in
case
"ABOVE" (not just crossover, e.g. on a start day if condition is met)
or
how to modify sigComparison to make only 1 Long order (not every day
the
condition is met, only on 1st and then not until Exit is made).
use osMaxPos and set a maximum position instead of the default osNoOp order sizing function. Details in the documentation, or I can work up a quick example later in the week.
I just wrote a blog post with an example strategy that uses osMaxPos and addPosLimit to do this. Here's the link: http://goo.gl/yBKDr Best, Josh
Regards, - Brian -- Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock
-- Joshua Ulrich | FOSS Trading: www.fosstrading.com
____________________________________________________________________ Informacie obsiahnute v tomto dokumente su urcene vylucne pre potreby jeho adresata. Dokument moze obsahovat informacie chranene ako bankove alebo obchodne tajomstvo, pripadne informacie podliehajuce ochrane podla inych pravnych predpisov. Preto Vas v pripade, ak Vam bol mylne doruceny, vyzyvame, aby ste sa zdrzali jeho odtajnenia ci jeho pouzitia pre vlastne potreby. Zaroven si Vas dovolujeme poziadat, aby ste nas o takomto pripade bez zbytocneho odkladu informovali a dokument nasledne zlikvidovali. Information stated in this document is intended only for needs of proper addressees of this document. This document can contain information protected as a bank or business secret, or information protected by other legal regulations. Thus in case of receiving the document by error, we kindly ask you not to disclose, or use the document for your own needs. Likewise we kindly ask you to notify us immediately upon such a case by sending an email message to the sender's address, and subsequently delete the document. Tatra banka, a.s. http://www.tatrabanka.sk Hodzovo namestie 3, 811 06 Bratislava 1 ICO: 00 686 930 Zapisana v obchodnom registri Okresneho sudu Bratislava I Oddiel: Sa, vlozka cislo: 71/B [[alternative HTML version deleted]] _______________________________________________ R-SIG-Finance at r-project.org 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.
On Fri, 2011-08-26 at 14:39 +0200, igor_vilcek_external at tatrabanka.sk wrote:
Thanks, works fine for me in this case. I am just wondering, however, how to use this solution in case i want to set my own order sizing function
*Everything* in quantstrat is modular. You can define your own functions for indicators, signals, rules, order sizing, even the fill simulator or P&L. We've tried to provide reasonable default functions. It is typical when I am modeling 'real' strategies for me to write custom indicators, signals, and order sizing functions. We've provided two example order sizing functions. osNoOp, and osMaxPos. You can use these as templates to code your own custom order sizing function.
(e.g. order size based on a % of current portfolio equity).
We'll get around to an equity-aware order sizing function, as Josh pointed out in his most recent blog post: http://blog.fosstrading.com/2011/08/tactical-asset-allocation-using.html The challenge for us in doing this is making it fast. On daily OHLC data, speed is less of an issue, but on tick data, it would be very easy to take a huge performance hit in recalculating account equity. There are some possible 'shortcuts' to this, 1> you could use realized transaction P&L as a proxy for account equity, and not have to update all the statistics in the portfolio and account. 2> you could repeatedly call applyStrategy on different non-overlapping time periods (e.g. months for daily data), calling updatePortf and and updateAcct at the end of each period, and updating your maxPos for each asset. osMaxPos is already aware of the maximum position at any given timestamp, so changing it periodically should be fine unless you're levered up to nosebleed levels. I've used variations on both the methods with quantstrat on tick data, but haven't gotten around to reworking those things in a generic fashion to put in to the package.
In other words, how to trade my system (above Moving Average, not crossover) and use flexible order quantity as well.
Hope this helps, - Brian
Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock