Tuesday, March 29, 2011

trading optimization

i've been thinking about how to optimize trades for some algorithmic trading. i need to define objective functions, obviously, but how exactly? risk vs. return, but risk (for a liquid asset) depends on a portfolio state between transactions, and returns are realized upon the transaction. it just occurred to me that i can reduce it to simple shift and scaling operations on a (somewhat unknown) pdf. if i have a certain unhedged amount, x, of a risky asset, and i buy or sell to end up with a*x, then that scales the pdf f(x) to f(a*x)/a. the trade should give me a return, r, so the pdf of my total return after the trade would be something like f(a*x-r)/a. so i know what the shift and the scale are, even though i don't exactly know what f(x) is. now it's a question of whether f(a*x-r)/a is better than f(x), and i trade if it is (i.e., maximize whatever metrics to find the optimal r,a). does this answer the question of how to place limit orders away from the market prices? i'm not sure yet.

Thursday, March 17, 2011

factor shares

ib is offering its customers commision-free trades on factorshares spread etfs. this looks really interesting: diy hedge fund with asset classes. trying to figure out how the funds operate, based on the holdings info from their website... each of the 5 has basically $3m in treasuries, $2m in cash, and a thousand in a treasury fund. each one then takes a position in nearest future contract (long and short) for the two spread assets, for 2x the nav/share * 100k shares/unit * 2 units (currently). the treasuries are probably to offset the time discount on the futures contracts, and that and the cash are for margin, obviously. the fund is probably for a little bit of liquidity during the daily rebalance. i'm guessing the nav comes from the $5m risk free + net market value of the futures. the nav/share doesn't exactly match the price, probably given the constraints of the contract sizes and maybe the lower liquidity of the etf at the moment. the futures holdings are updated daily, to restore dollar neutrality (same forward contract dollar amounts). for the current number of shares and risk-free holdings, the funds basically started at $25/share. the s&p e minis are apparently for lots of 50. the 30yr tbill futures are for lots of 100. the 5 etfs are s&p/tbill, tbill/s&p, s&p/usd, oil/s&p, gold/s&p, where each is bull/bear. 2x leverage on each leg, for a 4x total leverage (but still just 2x on the spread). right now the volume is pretty light, around 10k/day, since they just lauched a few weeks ago. i wonder if there is any arbitrage opportunity for these, knowing their methodology. especially for s&p/tbill vs. tbill/s&p. does the rebalance accumulate anything based on independent underlying price movements? no, because all the money gained from selling an advancing future is put into the one that declined, and the same thing will happen at the end of the next day. but if i rebalance between these, it will. i'm just not sure if it's any better than just rebalancing among 2x single asset funds, unless you think they're anticorrelated instead of just uncorrelated. maybe it has the advantage of not needing to rebalance with cash, like single funds would. one thing maybe i can try is to arb the s&p/tbill vs. tbill/s&p like this: right now fse has 139 emini and -71 tbill, and fsa has -177 emini and 91 tbill. closing for fse was $22.57 and fsa was 28.18. if i could buy 177/139 fse it would cost 28.74, or 91/71 would cost 28.92. so if i had some of each, i could have sold fse and bought fsa near the end of the day, eg sell 9 fse for 203.13 and buy 7 fsa for 197.26. that would be selling a share of 1251 emini, -639 tbill and buying a share of -1239, 637. so the net would be 42, -2. nav calculation time is based on the first of the futures contracts to settle: s&b/tbond 3pm (ET) tbond/s&p 3pm s&p/usd 3pm oil/s&p 2:30pm gold/s&p 1:30pm the nav must depend on the price of the futures and what exposure they can be rebalanced to. futures prices might not be as easy to come by, so maybe i could compare to other leveraged etfs like sso, sds, dgl (or iau/gld (not leveraged) or dgp/dzz (monthly, not daily)), dbo (or dig?, uso, oil), tlt (not leveraged), tbt (or pst? no), udn (not leveraged) (or uup, not leveraged and bull instead of bear but much higher volume) (these only use dx contracts, not front month). this wouldn't necessarily be perfect since nav can deviate from price, but it should be close for the heavily traded ones. here's a good ref list for leveraged etfs

Saturday, March 12, 2011

aptitude tests

seems like a lot of companies are using tests by their hr department to screen applicants. shl is one that is mentioned a lot. this one was referred to as having good practice tests.

Friday, March 11, 2011

audio + video

figured out how to get an alternate audio into a video file: # take mp3 out of audio flv ffmpeg -i altAudio.flv -acodec copy altAudio.mp3 # take the video only out of the video mencoder -ni -ovc copy -nosound -o noAudio.mp4 origVideo.mp4 # put the audio and video together mencoder -ovc copy -oac copy -audiofile altAudio.mp3 -o out.avi noAudio.mp4 might not need both the ffmpeg step and -ni on the video extraction, but at least one of them is necessary. i tried without both and the video played at double speed while the audio was normal speed in the out.avi. might also be able to use a different format out with -of. not sure if avi transcodes it. EDIT: tried without -ni, still works fine. might need to adjust delay with - and +. also, i found that rtmpdump has very handy -e and -o options. i dropped the -A option with -e and it seems to work (kind of), not sure if that is absolutely necessary. now i'm trying to get mencoder on a file to let me playback faster. tried -vf filmdint and filmdint=io=2:1, and it doesn't hurt but doesn't seem to be essential. so far, best results are with just -fps 30000/1001 -ofps 20000/1001 and speed it up with ']'. -oac copy doesn't work; have to use something else like pcm (uncompressed) or mp3lame. the original audio is 48000Hz aac, which i can encode with -oac lavc -lavcopts acodec=aac, but that makes encoding really slow and messes up a/v sync, even when i try to compensate by changing -srate. so far this version looks promising, but the avi has no idx: mencoder -ovc copy -oac mp3lame -fps 30000/1001 -ofps 20000/1001 -o out.avi infile.mp4 could try -of mpeg or lavf, with a lavf format=mp4 for example, since the original is mp4 and plays pretty well (except when i speed it up too much). ok, this one seems to work pretty well: mencoder -ovc copy -oac mp3lame -fps 30000/1001 -ofps 20000/1001 -of lavf -lavfopts format=mp4 -o out.mp4 infile.mp4

Wednesday, March 2, 2011

national review online audio

outloudopinion.com has apparently been posting audio files of select nro articles for at least a year now, much to my surprise. even have a convenient rss feed.