Saturday, August 4, 2012
Wednesday, August 1, 2012
Options Expiration Friday Range
I was curious as to how much the SPY fluctuated every third Friday of the month (options expiration Friday). Here's a graph of SPY range (high minus low) over the opening price. The percentage is shown on the y, and the x has the month.
For reference, the average range percentage over this period is 1.3%. So it doesn't look like options expiration has recently caused that much more volatility than on other days, at least for the SPY itself. (Sorry, I didn't get July's expiration range in there, albeit ~.5%)
For reference, the average range percentage over this period is 1.3%. So it doesn't look like options expiration has recently caused that much more volatility than on other days, at least for the SPY itself. (Sorry, I didn't get July's expiration range in there, albeit ~.5%)
Tuesday, July 31, 2012
Covered Calls
There's a huge push by a certain group of "advisers" for covered call writing. It is always presented, at least it feels this way to me, as a source of free money. These picks, for instance, seem rather poor choices to me.
I haven't gotten around to doing my own in-depth analysis of covered call writing, but I read this one earlier today. I love this quote:
The strategy is not a magic money maker. It is, if anything, a portfolio volatility reducer.
I haven't gotten around to doing my own in-depth analysis of covered call writing, but I read this one earlier today. I love this quote:
"As shown, they also partially hedge in downtrends. But the best use of covered calls is if you can see into the future and pick when your stock is going to go sideways."They are great if you know the stock isn't going to go up too much. It's because writing covered calls limits your upside. It doesn't magically make money appear out of thin air. Plus, if you're not already long the underlier, you're taking on significant downside risk. The stock can still go to zero, and you would be taking that loss. While the stock can go to infinity as well, you're limited by whatever your upside call was sold at.
The strategy is not a magic money maker. It is, if anything, a portfolio volatility reducer.
Monday, July 30, 2012
Charts and Cliff-Hanger Analysis
Can it really be that easy? No. No, it can’t. Of course, I can’t make any comments on anything
but what I see (which appears rather like an advertisement for the premium
service that they offer), I have to say what I see appears somewhat misleading.
Now, I know—it is merely a short post exhibiting an
interesting result, a result that seems to hold well enough for profit. What really gets me is the lack of a legitimate
disclaimer. And the question at the end. I suppose Bespoke
is looking to start conversation. Maybe. Or they’re just not interested in
sharing their information. Which is mostly likely the case.
I should be grateful for the small insight they are
providing. Of course, I would love to see the data and the process they used to form the
chart (which, yes, I could probably do on my own). But, I also would like to
see something commenting on the divergence at the beginning of the year (January
to April) and what some of the other presidential years looked like. Again, I’m
not paying for anything from them, so what can I expect? (Maybe I’ll post some
of my own analysis…if I have time).
I guess what really gets me is that I don’t believe this is
enough information to go by to make a good decision to go long at the current
moment.
And, now that I look at the graph (and the axes labels) I am
slightly confused. But with a quick comparison to the SPX's current return anyone could sort that out...
Oh well. An interesting chart in the least--as long as you
do your due diligence.
MATLAB VWAP, Part II: Backtest
After reading some Coding Horror (this specifically), I decided I might as well begin sharing more results. Albeit not terribly useful from a trading perspective--I'll explain shortly--, here are some results utilizing a small database of GS minute values (approximately just short of two weeks). The backtest uses an extension of the VWAP code from yesterday following the simple rules of long when the 100 minute VWAP > 500 minute VWAP and short when 100 min VWAP < 500 min VWAP. A pretty simple, standard, elementary test.
Link to previous article: MATLAB VWAP (Part I)
Here are the results (with image):
Return: +13.36% (rounded)
PLEASE DO NOT TRADE ON THESE RESULTS.
As I mentioned above, this should not be used from a trading perspective for several reasons:
1) It is run on far too few data points. Perhaps it just happened to work perfectly for this interval. I have no clue if this holds. (If you would like to donate historical data, please let me know!)
2) This is done during earnings, and, as you would see if you ran this for other stocks, could be hit or miss, especially with overnight holding (and, again, especially through earnings).
3) There are plenty of stocks this does not work for. Some with similar sized returns, although negative.
4) My data could be flawed, my routine should be suspect and you should always perform tests read on the internet for yourself!
5) I am sure there are 10 more reasons.
Now, here is the "backtest" code in function form. It's for MATLAB and requires that you have some data in a MySQL database (very easy if you use my IB Historical Data Downloader/Importer):
function sum_log_change = vwap_backtest(symbol_string)
clear close_mat
clear volume_mat
clear vwap
clear vwap_2
clear buy_sell_matrix
clear trade
clear trade_prices
clear sum_log_change
vwap_length = 100;
vwap_length_2 = 500;
format long
symbol_string
%connect to the database CHANGE PASSWORD FROM ***** TO WHATEVER YOUR PASSWORD IS!!!
conn = database('stocks','root','****','com.mysql.jdbc.Driver','jdbc:mysql://localhost:3306/stocks');
%query the symbols in the database
str_query_close = ['SELECT close, volume FROM stock_prices_minute WHERE symbol = ''',symbol_string, ''''];
close_cell = fetch(conn, str_query_close);
close_mat = cell2mat(close_cell(:,1));
volume_mat = cell2mat(close_cell(:,2));
close_times_volume = close_mat .* volume_mat;
for i = vwap_length:length(close_times_volume)
volume_total = 0;
volume_price_sum = 0;
for j = 0:(vwap_length - 1)
volume_total = volume_total + volume_mat(i-j);
volume_price_sum = volume_price_sum + volume_mat(i-j)*close_mat(i-j);
end
vwap(i-(vwap_length - 1)) = volume_price_sum / volume_total;
end
for i = vwap_length_2:length(close_times_volume)
volume_total = 0;
volume_price_sum = 0;
for j = 0:(vwap_length_2 - 1)
volume_total = volume_total + volume_mat(i-j);
volume_price_sum = volume_price_sum + volume_mat(i-j)*close_mat(i-j);
end
vwap_2(i-(vwap_length_2 - 1)) = volume_price_sum / volume_total;
end
%do comparing
for i = 1:(length(close_times_volume) - (vwap_length_2 - 1))
if vwap_2(i) < vwap(i+(vwap_length_2 - vwap_length))
buy_sell_matrix(i) = 1;
else
buy_sell_matrix(i) = -1;
end
end
buy_sell_matrix;
%calculate trade prices
for i = 1:(length(close_times_volume) - (vwap_length_2 - 1))
if i == 1
trades(i) = close_mat(i + vwap_length_2);
else
if buy_sell_matrix(i) ~= buy_sell_matrix(i-1)
trades(i) = close_mat(i + vwap_length_2);
elseif i == (length(close_times_volume)-(vwap_length_2 - 1))
trades(i) = close_mat(length(close_mat));
else
trades(i) = 0;
end
end
end
trades;
j = 1;
%matrix of prices trades took place at
for i = 1:length(trades)
if trades(i) ~= 0
trade_prices(j) = trades(i);
j = j + 1;
end
end
trade_prices;
log_change = 0;
sum_log_change = 0;
%now you can calculate lognormal return
for i = 1:(length(trade_prices) - 1)
if buy_sell_matrix(1) == 1
if mod(i,2) == 0
log_change = -(log(trade_prices(i+1)) - log(trade_prices(i)));
else
log_change = log(trade_prices(i+1)) - log(trade_prices(i));
end
sum_log_change = sum_log_change + log_change;
else
if mod(i,2)==0
log_change = log(trade_prices(i+1)) - log(trade_prices(i));
else
log_change = -(log(trade_prices(i+1)) - log(trade_prices(i)));
end
sum_log_change = sum_log_change + log_change;
end
end
sum_log_change;
x = [1:length(close_mat)];
x2 = [(vwap_length):length(close_mat)];
x3 = [(vwap_length_2):length(close_mat)];
plot(x, close_mat)
hold on
plot(x2, vwap, '-r')
hold on
plot(x3, vwap_2, '-g')
Link to previous article: MATLAB VWAP (Part I)
Saturday, July 28, 2012
MATLAB VWAP
Here's a simple MATLAB script to extract data from a MySQL Database (here, specifically one that was created using my IB historical data extractor) and plot close data along with two VWAPs (volume weighted average prices) of your desired length. It's pretty simple but could be expanded upon to backtest VWAP strategies using the created VWAP matrices. (Also, I think I fixed the way source code is displayed on this site...should now be easier to copy and paste).
Update: Here's part II.
Update: Here's part II.
clear close_mat
clear volume_mat
clear vwap
clear vwap_2
vwap_length = 100;
vwap_length_2 = 500;
format long
%connect to the database
conn = database('stocks','root','***','com.mysql.jdbc.Driver','jdbc:mysql://localhost:3306/stocks');
%query the symbols in the database
str_query_close = 'SELECT close, volume FROM stock_prices_minute WHERE symbol = ''GOOG''';
close_cell = fetch(conn, str_query_close);
close_mat = cell2mat(close_cell(:,1))
volume_mat = cell2mat(close_cell(:,2));
close_times_volume = close_mat .* volume_mat;
for i = vwap_length:length(close_times_volume)
volume_total = 0;
volume_price_sum = 0;
for j = 0:(vwap_length - 1)
volume_total = volume_total + volume_mat(i-j);
volume_price_sum = volume_price_sum + volume_mat(i-j)*close_mat(i-j);
end
vwap(i-(vwap_length - 1)) = volume_price_sum / volume_total;
end
for i = vwap_length_2:length(close_times_volume)
volume_total = 0;
volume_price_sum = 0;
for j = 0:(vwap_length_2 - 1)
volume_total = volume_total + volume_mat(i-j);
volume_price_sum = volume_price_sum + volume_mat(i-j)*close_mat(i-j);
end
vwap_2(i-(vwap_length_2 - 1)) = volume_price_sum / volume_total;
end
x = [1:length(close_mat)];
x2 = [(vwap_length):length(close_mat)];
x3 = [(vwap_length_2):length(close_mat)];
plot(x, close_mat)
hold on
plot(x2, vwap, '-r')
hold on
plot(x3, vwap_2, '-g')
Thursday, July 26, 2012
WSJ/FT Paywall Bypass
Here's a guide on how to bypass the WSJ paywall. It also works with FT.
Basically, just copy the article name you want to read and paste it into Google. Then select the article from the search results. Now, you can read it as though you had a subscription!
Basically, just copy the article name you want to read and paste it into Google. Then select the article from the search results. Now, you can read it as though you had a subscription!
Subscribe to:
Posts (Atom)

