StockFetcher Forums · Filter Exchange · Statistic for up/down comparison with SPY<< >>Post Follow-up
cpatriaw
8 posts
msg #110275
Ignore cpatriaw
1/16/2013 7:32:21 PM

The idea is, testing in the last 100 days, how many times this stock is close green when SPY is green, and vice versa. Any idea ?

guru_trader
485 posts
msg #110307
Ignore guru_trader
modified
1/18/2013 2:25:47 AM

While working on this filter, I discovered a few issues -- some related to your request and some related to Stockfetcher.

LEGEND: "up" = ( close > open )"; "down" = ( close < open ); "flat" = ( close = open ); SYM is the abbreviation for any symbol

First, there are several combinations of scenarios that need clarification. How should the following be treated?
SPY.....SYM
up........up = both up
up........down = both not up
up........flat = both up? both not up? both not up or down?

down........up = both not up
down........down = both down
down........flat = both down? both not down? both not down or up?

flat..........up = both up? both not up? both not up or down?
flat..........down = both down? both not down? both not down or up?
flat..........flat = both up? both down? both not up or down? both equal to 0?

You see, we could, at least, add another category equal to both being flat, but that seems like a rare event (only 2 days in the last 100 for SPY). It's more likely that either SPY or SYM will, independently, be flat while the other closes up or down. Alternatively, the flat days could be lumped into the "up" (or "down") category. So, how should those be handled?

Another, potentially bigger, problem is Stockfetcher not returning the expected value for sym_up (close>open), sym_dn (close
In theory, there should be no such day in which all of these conditions added together is greater than 1 ... (close > open) and/or (close < open) and/or (close = open). (I had to add paragraphs because, for some reason, the Stockfetcher forum is chopping up my post and omitting parts).

However, Stockfetcher is reporting about 20-30 symbols equal to 2 -- sort column "sum_sym" descending and see for yourself. That "bug" (or "quirk", or "feature") will negate some of our efforts to properly categorize up, down, and flat days.

Anyway, here is the uncluttered version ...
Fetcher[
/* today's stats on SPY */
set{spy_clop, ind(SPY,close) - ind(SPY,open)} /* close - open on SPY */
set{spy_up, count(spy_clop > 0, 1)} /* was today an "up" day for SPY, 1 = yes, 0 = no */
set{spy_dn, count(spy_clop < 0, 1)} /* was today a "down" day for SPY, 1 = yes, 0 = no */
set{spy_flat, count(spy_clop equals 0, 1)} /* was today a "flat" day for SPY, 1 = yes, 0 = no */
set{tmp_sum_spy, spy_up + spy_dn}
set{sum_spy, tmp_sum_spy + spy_flat} /* verify that there is no such thing as a sum of 2 or 3 */

/* 100 day stats on SPY */
set{spy_up_100d, count(spy_clop > 0, 100)} /* count number of "up" days for SPY over last 100 days */
set{spy_dn_100d, count(spy_clop < 0, 100)} /* count number of "down" days for SPY over last 100 days */
set{spy_flat_100d, count(spy_clop equals 0, 100)} /* count number of "flat" days for SPY over last 100 days */

/* today's stats on symbol */
set{sym_clop, close - open} /* close - open on SYM */
set{sym_up, count(sym_clop > 0, 1)} /* was today an "up" day for SYM, 1 = yes, 0 = no */
set{sym_dn, count(sym_clop < 0, 1)} /* was today a "down" day for SYM, 1 = yes, 0 = no */
set{sym_flat, count(sym_clop equals 0, 1)} /* was today a "flat" day for SYM, 1 = yes, 0 = no */
set{tmp_sum_sym, sym_up + sym_dn}
set{sum_sym, tmp_sum_sym + sym_flat} /* verify that there is no such thing as a sum of 2 or 3 */

/* 100 day stats on SYM */
set{sym_up_100d, count(sym_clop > 0, 100)} /* count number of "up" days for SYM over last 100 days */
set{sym_dn_100d, count(sym_clop < 0, 100)} /* count number of "down" days for SYM over last 100 days */
set{sym_flat_100d, count(sym_clop equals 0, 100)} /* count number of "flat" days for SYM over last 100 days */

add column separator

set{both_up_1d, spy_up + sym_up} /* count number of times "SPY" and "SYM" were "up" in the same day over the last 1 day */
set{both_up_100d, count(both_up_1d equals 2, 100)} /* count number of times "SPY" and "SYM" were "up" in the same day over the last 100 days */
add column both_up_100d

set{both_dn_1d, spy_dn + sym_dn} /* count number of times "SPY" and "SYM" were "down" in the same day over the last 1 day */
set{both_dn_100d, count(both_dn_1d equals 2, 100)} /* count number of times "SPY" and "SYM" were "down" in the same day over the last 100 days */
add column both_dn_100d

set{both_flat_1d, spy_flat + sym_flat} /* count number of times "SPY" and "SYM" were "flat" in the same day over the last 1 day */
set{both_flat_100d, count(both_flat_1d equals 2, 100)} /* count number of times "SPY" and "SYM" were "flat" in the same day over the last 100 days */
add column both_flat_100d

add column separator

set{sum_updn_100d, both_up_100d + both_dn_100d} /* count the number of times "SPY" and "SYM" were "up" and "down" over the last 100 days */
add column sum_updn_100d

set{sum_updnflat_100d, sum_updn_100d + both_flat_100d} /* count the number of times "SPY" and "SYM" were "up" and "down" and "flat" over the last 100 days */
add column sum_updnflat_100d

add column separator

sort column 11 descending
]



Here is the full ("cluttered") version, for viewing the "bug" (or "quirk", or "feature") in Stockfetcher ... see the column labeled, "sum_sym" ... I don't think it should include any values greater than 1, but it does.

Fetcher[
add column separator

/* today's stats on SPY */
set{spy_clop, ind(SPY,close) - ind(SPY,open)} /* close - open on SPY */
add column spy_clop
set{spy_up, count(spy_clop > 0, 1)} /* was today an "up" day for SPY, 1 = yes, 0 = no */
add column spy_up
set{spy_dn, count(spy_clop < 0, 1)} /* was today a "down" day for SPY, 1 = yes, 0 = no */
add column spy_dn
set{spy_flat, count(spy_clop equals 0, 1)} /* was today a "flat" day for SPY, 1 = yes, 0 = no */
add column spy_flat
set{tmp_sum_spy, spy_up + spy_dn}
set{sum_spy, tmp_sum_spy + spy_flat} /* verify that there is no such thing as a sum of 2 or 3 */
add column sum_spy

add column separator

/* 100 day stats on SPY */
add column sum_spy
set{spy_up_100d, count(spy_clop > 0, 100)} /* count number of "up" days for SPY over last 100 days */
add column spy_up_100d
set{spy_dn_100d, count(spy_clop < 0, 100)} /* count number of "down" days for SPY over last 100 days */
add column spy_dn_100d
set{spy_flat_100d, count(spy_clop equals 0, 100)} /* count number of "flat" days for SPY over last 100 days */
add column spy_flat_100d

add column separator

/* today's stats on symbol */
set{sym_clop, close - open} /* close - open on SYM */
add column sym_clop
set{sym_up, count(sym_clop > 0, 1)} /* was today an "up" day for SYM, 1 = yes, 0 = no */
add column sym_up
set{sym_dn, count(sym_clop < 0, 1)} /* was today a "down" day for SYM, 1 = yes, 0 = no */
add column sym_dn
set{sym_flat, count(sym_clop equals 0, 1)} /* was today a "flat" day for SYM, 1 = yes, 0 = no */
add column sym_flat
set{tmp_sum_sym, sym_up + sym_dn}
set{sum_sym, tmp_sum_sym + sym_flat} /* verify that there is no such thing as a sum of 2 or 3 */
add column sum_sym

add column separator

/* open and close values added to confirm problem with sum_sym = 2 */
add column open
add column close

add column separator

/* 100 day stats on SYM */
add column sum_sym
set{sym_up_100d, count(sym_clop > 0, 100)} /* count number of "up" days for SYM over last 100 days */
add column sym_up_100d
set{sym_dn_100d, count(sym_clop < 0, 100)} /* count number of "down" days for SYM over last 100 days */
add column sym_dn_100d
set{sym_flat_100d, count(sym_clop equals 0, 100)} /* count number of "flat" days for SYM over last 100 days */
add column sym_flat_100d

add column separator

set{both_up_1d, spy_up + sym_up} /* count number of times "SPY" and "SYM" were "up" in the same day over the last 1 day */
set{both_up_100d, count(both_up_1d equals 2, 100)} /* count number of times "SPY" and "SYM" were "up" in the same day over the last 100 days */
add column both_up_100d

set{both_dn_1d, spy_dn + sym_dn} /* count number of times "SPY" and "SYM" were "down" in the same day over the last 1 day */
set{both_dn_100d, count(both_dn_1d equals 2, 100)} /* count number of times "SPY" and "SYM" were "down" in the same day over the last 100 days */
add column both_dn_100d

set{both_flat_1d, spy_flat + sym_flat} /* count number of times "SPY" and "SYM" were "flat" in the same day over the last 1 day */
set{both_flat_100d, count(both_flat_1d equals 2, 100)} /* count number of times "SPY" and "SYM" were "flat" in the same day over the last 100 days */
add column both_flat_100d

add column separator

set{sum_updn_100d, both_up_100d + both_dn_100d} /* count the number of times "SPY" and "SYM" were "up" and "down" over the last 100 days */
add column sum_updn_100d

set{sum_updnflat_100d, sum_updn_100d + both_flat_100d} /* count the number of times "SPY" and "SYM" were "up" and "down" and "flat" over the last 100 days */
add column sum_updnflat_100d

add column separator
]



This got me thinking -- this sounds a lot like correlation studies. Here are some correlation studies (using a lot less code) to investigate:
Fetcher[
set{clop, close - open}
draw clop

add column corr(SPY,100,clop)
draw IND(SPY,clop) on plot clop
draw corr(SPY,100,clop)
compare with SPY
sort column 5 descending

add column corr(^SPX,60,Close)
compare with ^SPX
]



You'll notice that the order of symbols is about the same on both filters ... as expected.

StockFetcher Forums · Filter Exchange · Statistic for up/down comparison with SPY<< >>Post Follow-up

*** Disclaimer *** StockFetcher.com does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. StockFetcher.com does not recommend particular securities. StockFetcher.com, Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.


Copyright 2022 - Vestyl Software L.L.C.Terms of Service | License | Questions or comments? Contact Us
EOD Data sources: DDFPlus & CSI Data Quotes delayed during active market hours. Delay times are at least 15 mins for NASDAQ, 20 mins for NYSE and Amex. Delayed intraday data provided by DDFPlus


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.