Skip to content

Commit

Permalink
calls to using now explicitly list functions
Browse files Browse the repository at this point in the history
  • Loading branch information
PGS62 committed Feb 7, 2024
1 parent d52ed2d commit 55acfd9
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 94 deletions.
1 change: 0 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ version = "3.0.0"
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

Expand Down
1 change: 0 additions & 1 deletion scripts/for_aiden.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using KendallTau
using Statistics

"""
test_corkendall_fromfile()
Expand Down
60 changes: 9 additions & 51 deletions src/corkendall_fromfile.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using CSV: write, File, getnames
import DataFrames
import Tables
import Statistics
using DelimitedFiles
using DataFrames: DataFrame, insertcols!
using Tables: matrix
using Statistics: median

"""
corkendall_fromfile(file1::String, file2::String, outputfile::String,
Expand Down Expand Up @@ -53,10 +52,10 @@ function corkendall_fromfile(file1::String, file2::String, outputfile::String,
res = sin.(π / 2 .* res)
end

datatowrite = DataFrames.DataFrame(res, names2)
datatowrite = DataFrame(res, names2)

if writeheaders
DataFrames.insertcols!(datatowrite, 1, Symbol("") => String.(names1))
insertcols!(datatowrite, 1, Symbol("") => String.(names1))
end

filename = write(outputfile, datatowrite, header=writeheaders)
Expand All @@ -68,10 +67,10 @@ function corkendall_fromfile(file1::String, file2::String, outputfile::String,
if size(res) == (1, 1)
return 1.0
else
return Statistics.median(offdiag(res))
return median(offdiag(res))
end
else
return Statistics.median(res)
return median(res)
end
else
throw("whattoreturn my be either 'filename' or 'median', but got '$whattoreturn'")
Expand All @@ -94,7 +93,7 @@ function csvread(filename::String, ignorefirstrow::Bool, ignorefirstcol::Bool;
strict = true

filedata = File(filename; header, drop, missingstring, types, strict)
data = Tables.matrix(filedata)
data = matrix(filedata)

#Convert to Array{Float64} if there are in fact no missings
if isnothing(findfirst(ismissing, data))
Expand Down Expand Up @@ -163,47 +162,6 @@ function comparecorrelationfiles(file1::String, file2::String)

absdiffs = abs.(data1 .- data2)

return (maximum(absdiffs), Statistics.median(absdiffs))
return (maximum(absdiffs), median(absdiffs))

end

#Use DelimitedFiles for fewer dependencies
function csvread2(filename::String, ignorefirstrow::Bool, ignorefirstcol::Bool;
missingstring::Union{Nothing,String,Vector{String}}="")

contents = DelimitedFiles.readdlm(filename, ',')
contents = ifelse.(contents .== missingstring, missing, contents)
firstrow = ignorefirstrow ? 2 : 1
firstcol = ignorefirstcol ? 2 : 1
if firstrow == firstcol == 1
data = contents
else
data = contents[firstrow:end, firstcol:end]
end
data = identity.(data)
if firstrow == 0
names = "Column" .* string.(1:(size(data, 2)))
else
names = Symbol.(contents[1, firstcol:end])
end
return (data, names)

end

function testcsvread2()
#csvread2("data/y_withheaders.csv",true,true,missingstring="NA")

base_folder = raw"C:\Users\phili\OneDrive\ISDA SIMM\Solum Validation C-VIII 2023\EQ_delta"
#ISDA's calculation of KendallTau
isda_results_file = joinpath(base_folder, raw"9_correlations\eq_delta-kendall_recent_1-10d.csv")

@time res1 = csvread2(isda_results_file, true, true, missingstring="NA")
@time res2 = csvread(isda_results_file, true, true, missingstring="NA")

res1 == res2

end




38 changes: 0 additions & 38 deletions src/notes.jl

This file was deleted.

1 change: 1 addition & 0 deletions test/compare_implementations.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Random: rand, randn
"""
compare_implementations(fn1=corkendall, fn2=corkendall_naive; abstol::Float64=1e-14,
maxcols::Integer, maxrows::Integer, numtests::Integer,
Expand Down
1 change: 0 additions & 1 deletion test/corkendall.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using KendallTau
using Test
using Random

@testset "corkendall_auxiliary_fns" begin

Expand Down
3 changes: 1 addition & 2 deletions test/versus_naive.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using KendallTau
using Test
using Random
using Random: randn,rand,MersenneTwister

#=
Note that corkendall and corkendall_naive share some subroutines, notably handle_pairwise
Expand All @@ -20,5 +20,4 @@ and handle_listwise. If those were bugged then this test would likely give a fal
@test corkendall_naive(smallx, skipmissing=:listwise) == KendallTau.corkendall(smallx, skipmissing=:listwise)
@test isequal(corkendall_naive(smallx, skipmissing=:none) , KendallTau.corkendall(smallx, skipmissing=:none))


end

0 comments on commit 55acfd9

Please sign in to comment.