[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Simulating the Leveraged ETFs



PureBytes Links

Trading Reference Links

Thanks Bruce ... your contributions are always excellent.

> I've long been active in another user community that has been doing >this
> for several years for hedging/spreading applications.  Lately, >proxies
> have also been used for back-testing of short term trading.

Very interesting.

Is it an open community?


> I was actually about to make a more detailed post about how to do >this
> when I read your note about the potential difficulty that you might >have
> implementing this.

Yes, I think anyone should be cautious about using code that they don't understand and if you understand it you can write it.


> NetROC = Leverage * IndexROC - DailyCompoundedCost

We should be able to calc this easily:

- it is the difference between our simulated ticker and the actual ticker, for the period that we have data for ETF
- presumably the ETF model/costs don't change around often or at all?
- we need to be cautious about projecting todays ETF costs backwards in time to when the ETF's didn't exist?

Grant also drew my attention to the fact that potentially 'simulated leveraged tickers' might be an easier way to test strategies that use margin compared to strategies that don't, without the need for complicated money management code (I am going to think about that one for a while).

--- In amibroker@xxxxxxxxxxxxxxx, "bruce1r" <brucer@xxx> wrote:
>
> Grant -
> 
> The idea that you are raising is the creation of something called a
> "proxy" that extends +/- leveraged index funds and ETF's back in time. 
> I've long been active in another user community that has been doing this
> for several years for hedging/spreading applications.  Lately, proxies
> have also been used for back-testing of short term trading.
> 
> I was actually about to make a more detailed post about how to do this
> when I read your note about the potential difficulty that you might have
> implementing this.  I unfortunately don't have the time right now to
> separate out the appropriate code that I've done and document it.  Maybe
> in the near future.
> 
> I'll try to quickly give you, and anyone else that is interested, the
> broad brush idea, though.
> 
> Rydex, Profunds, and Direxion operate on a business model that has a
> number of components that contribute to tracking error of the daily rate
> of change (ROC).  This generally nets out to a cost for long funds and a
> small credit for short funds.  The explanation for this is too detailed
> for now.  But, that consider their business objective is to manage that
> cost over time to yield a net profit.  So each DAY'S change is -
> 
> NetROC = Leverage * IndexROC - DailyCompoundedCost
> 
> The estimate error of this NetROC is then used to MINIMIZE the
> difference to actual via the SUM-SQUARED of -
> 
> EstError = ActualROC - NetROC
> 
> At this point, you have a "fitted" model, and can re-constitute the
> equity curve for the model via the basic technique -
> 
> eq = exp( Cum( log( 1 + NetROC / 100 ) ) ) * startequity
> 
> As a final touch, the estimated portion of the model can be spliced to
> the actual recent history.  That result can then be used for a number of
> purposes.  It has proven to be a decent approximation, but has a few
> limitations.  One interesting by-product has been that yields an
> approximate cost in yearly % for dealing with the companies.  They are
> not the same !
> 
> Hope that some of that helps -
> 
> BruceR
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "longarm61" <norm1@> wrote:
> >
> > I would actually love to become proficient in AFL, but being a
> full-time trader and family man, much of my time is spent on those
> things and I simply don't have a lot of time left in the day for
> learning this stuff. But I've copied your posts and downloaded your file
> and I'll try to chip away at it as time permits.
> >
> > Thanks again for your help.
> >
> > Grant
> >
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" brian_z111@ wrote:
> > >
> > > The download file has been overwritten with a new, slightly tidier,
> version.
> > >
> > > I find the key concepts, demonstrated in the file, very helpful
> indeed.
> > >
> > > Arithmetic Mean, Geometric Mean and StdDev are a beautiful things
> (and I am not even a mathematician).
> > >
> > > My teacher taught me that "an apple doesn't ripen overnight" ... he
> used it in a different context but Tomaasz said the same about AB when
> he said "it takes time to sink in" ... this is a fundamental truth of
> learning.
> > >
> > > There are some hints in the file for new programmers:
> > >
> > > - understand the logic first
> > > - lay the logic out
> > > - start at the top and work sequentially, line by line, (this rules
> covers the majority of basic situations)
> > > - test the veracity of your logic/code line by line (in AB I do that
> by plotting everything I can ... one line at at time if I am stuck ...
> as I get better I can skip more and more blocks of lines because
> experience tells me they are correct if the syntax and logic are
> correct.
> > >
> > > In this case:
> > >
> > > - focus on method one
> > > - start at the top of the worksheet and find a way to express each
> line in AFL
> > > - leverage could be a Param function or optimizeable or a static
> variable or a variable that you change manually in your code.
> > > - you have the price series e.g. Close
> > > - you have the begin value of the Close
> > > - use the functions to create the rows as arrays
> > > - substitute the numerical factor, in the manual OHLC example, for
> the ShiftFactor array.
> > >
> > > That is easy enough.
> > >
> > > The most important thing is to steep yourself in the logic.
> > >
> > >
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "longarm61" <norm1@> wrote:
> > > >
> > > > Thanks for the replies, Brian.  I'm very much inept when it comes
> to AFL so I'll have to try to make sense of it all.  In answer to your
> previous post, my plan was to use it for charting, but backtesting
> capability might come in handy too. Charting would be the priority
> though.
> > > >
> > > > Thanks again,
> > > >
> > > > Grant
> > > >
> > > >
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@>
> wrote:
> > > > >
> > > > > Grant,
> > > > >
> > > > > I found your idea interesting so I did a little bit more.
> > > > >
> > > > > > 1) make separate arrays for ROC(X,1) where X = O,H,L,C,Ave etc
> (as >required)
> > > > > >
> > > > > > factorO = ROC(O,1);//as GrowthFactor e.g. 2% = 1.02, -2% =
> 0.98
> > > > > > etc
> > > > >
> > > > > I missed a couple of steps out ... you probably figured that
> already but just in case here is an excel file that demos the logic ...
> I show two methods to produce a simulated leveraged price series from a
> base price series; log/antilog and relativeGeometricMean.
> > > > >
> > > > > Scroll down to section 2 Miscellaneous Files >>
> LeveragedPriceSeries.xls
> > > > >
> > > > > http://zboard.wordpress.com/downloads/
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@>
> wrote:
> > > > > >
> > > > > > To toggle your thinking:
> > > > > >
> > > > > > (I am just imagining a chart to start with ... not sure what
> your final objective is ... if PLOTOHLC helps you could work it towards
> a backtesting array version ... versions might be different depending on
> whether you want it for chart reading, backtesting or both)
> > > > > >
> > > > > > 1) make separate arrays for ROC(X,1) where X = O,H,L,C,Ave etc
> (as required)
> > > > > >
> > > > > > factorO = ROC(O,1);//as GrothFactor e.g. 2% = 1.02, -2% = 0.98
> > > > > > etc
> > > > > >
> > > > > > 2) substitute factorO, factorH etc in PLOTOHLC example
> > > > > > - when you want to go back to 'Price', instead of leveraged
> Price, use factor == 1, which is ROC neutral.
> > > > > >
> > > > > > 3) if you get something going there and you like it maybe
> ParamToggle will let you switch from Price to Leveraged Price in live
> chart mode
> > > > > >
> > > > > >     - ParamToggle is boolean so toggle P or LP yes or no?
> > > > > >     - conditional statement (if toggle is yes use leveraged
> price array)
> > > > > >
> > > > > > There would be other ways so comeback if you want options.
> > > > > >
> > > > > > I think ATC can store conditioned arrays so you could also use
> that and save leveraged Price arrays as pseudo tickers (if you aren't up
> to speed on ATC reference Hermans PDF tutorial at the UKB).
> > > > > >
> > > > > >
> > > > > >
> > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "longarm61" <norm1@> wrote:
> > > > > > >
> > > > > > > Thanks much, Brian, I will look into that.
> > > > > > >
> > > > > > > Grant
> > > > > > >
> > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@>
> wrote:
> > > > > > > >
> > > > > > > > What about  211. (indexed from AFL by name) PLOTOHLC
> (Exploration / Indicators) - plot custom OHLC chart (AFL 2.2)
> > > > > > > >
> > > > > > > > Will that do the job?
> > > > > > > >
> > > > > > > >
> > > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "longarm61" <norm1@>
> wrote:
> > > > > > > > >
> > > > > > > > > Hi, I'm guessing that this is a simple thing, but of
> course, it's not for me. I'm trying to simulate the performance of
> leveraged ETFs going back farther than they go back themselves, hence
> the following:
> > > > > > > > >
> > > > > > > > > I would like to plot a line which moves 2x
> percentage-wise the gain/loss of a particular stock PER DAY (bar). 
> E.g., if I have SPY up, and SPY moves up 1% on Monday, the line moves up
> 2%.  If SPY moves down .5% on Tuesday, the line moves down 1%.  And so
> on.  It'd be nice to have an option to switch between PRICE and
> PERCENTAGE on the current value (from the first bar showing to the
> last), but if it's a choice between one or the other, I'd prefer price.
> > > > > > > > >
> > > > > > > > > Thanks so much for any assistance on this.
> > > > > > > > >
> > > > > > > > > Grant
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>




------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/