Skip to content

Instantly share code, notes, and snippets.

@yunskim
yunskim / tax.ijs
Last active October 13, 2021 02:53
dot =: mp =: +/ .*
thresholds =: 0 0.12 0.46 0.88 1.5 3 5 10
rates =: 0.06 0.15 0.24 0.35 0.38 0.4 0.42 0.45
marginal_rates =: 2 -~/\ 0, rates
tax =: 13 : 'marginal_rates dot 0 >. y - thresholds'
sells =: 10 + i. 10
NB. https://futurecreator.github.io/2018/10/07/functional-programming-filter-map-fold-reduce/
words =: ',' cutopen 'tony,a,steve,captain,b,thor,hulk,c'
filter =: 1 : '(#~ ([: ; u L: 0))'
map =: 1 : 'u L: 0'
capitalize =: 3 : 0
(}. y) ,~ toupper {. y
)
NB. https://www.youtube.com/watch?v=i4VqXRRXi68
NB. https://blogs.mathworks.com/cleve/2017/09/25/how-far-apart-are-two-random-points-in-a-square/
X =: j./ ? 2 1e8 $ 0
Y =: j./ ? 2 1e8 $ 0
dist =: | X - Y
mean dist
NB. 0.521417
min =: |. ;"1 ". each _3 ] \ (TAB, CRLF) cutopen clipread ''
col_min =: |: min
'date time price' =: col_min
is_open =: 905 = time
is_open_plus_30 =: 930 = time
is_close_minus_60 =: 1430 = time
is_close_minus_30 =: 1500 = time
is_close =: 1530 = time
grid =: 0&".;._2 (0 : 0)
5 3 0 0 7 0 0 0 0
6 0 0 1 9 5 0 0 0
0 9 8 0 0 0 0 6 0
8 0 0 0 6 0 0 0 3
4 0 0 8 0 3 0 0 1
7 0 0 0 2 0 0 0 6
0 6 0 0 0 0 2 8 0
0 0 0 4 1 0 0 0 0
0 0 0 0 0 0 0 0 0
require 'stats/distribs'
require 'numeric'
require 'plot'
mu =: 0
sigma =: 0.15
n =: 100
days =: +: 365 NB. 2년
dt =: % 365 NB. sigma는 annualized volatility
correlogram =: 4 : 0
mu =. (+/ % #) x
diff =. x - mu
num =. (+/ .*)/ (y * 1 _1) }."0 _ diff
denum =. (+/ .*)~ diff
num % denum
)
@yunskim
yunskim / tick_script.ijs
Last active July 12, 2018 16:13
simple multi plot for financial data from JD
query =: jd 'read /e time, public_sale, public_purchase, settlement from 069500_TICK order by time'
time =: 'time' jdfrom_jd_ query
ps =: 'public_sale' jdfrom_jd_ query
pp =: 'public_purchase' jdfrom_jd_ query
settlement =: 'settlement' jdfrom_jd_ query
hour =: 9 + (3600 * 1e9) %~ time - efs_jd_ '2018-07-12 09:00:00'
netpp =: +/\ pp - ps
pd 'reset'
@yunskim
yunskim / kNN.ijs
Last active September 12, 2015 06:14
dist =: +/&.:*:@:-"1
NB. group =: 1 1.1 , 1 1 , 0 0 ,:0 0.1
NB. labels =: 'AABB'
kNN =: 4 : 0
'group labels k' =. x
labels ({ ~.)~ (i. >./) #/.~ labels {~ k {. /: group dist y
)
normalize =: (- <./) % (>./ - <./)
@yunskim
yunskim / aa.ijs
Last active August 29, 2015 14:28
simple implementation of associative array in J
NB. Assiciative Array
coclass 'aa'
get =: ".
has =: 0 <: nc@boxopen
set =: 4 :'(x)=:y'
del =: 4!:55@boxopen
NB. following python's convensions
keys =: }.@:nl